首页 > 代码库 > tomcat status html内容处理 awk

tomcat status html内容处理 awk


[root@localhost handle_tomcat_status]# cat handle.sh 
#!/bin/sh

awk ‘/Free memory:/{print "Free memory: " $4}‘ a.txt 
awk ‘/Total memory:/{print "Total memory: " $8}‘ a.txt
awk ‘/Max memory:/{print "Max memory: " $12}‘ a.txt 

for n in ‘Eden Space‘  ‘Survivor Space‘ ‘Tenured Gen‘ ‘Code Cache‘ ‘Compressed Class Space‘ ‘Metaspace‘
do
 awk -F"($n)+"  ‘/Eden Space/{ print $2}‘ a.txt |awk -v name="$n" -F‘[(<td>)]+‘ ‘{print name ": "  $5 "  "$7 "  "$9 "  "$11}‘
done



html内容:

curl http://tomcat:s3cret@192.168.10.12:8080/manager/status?JSON=true
<html>
<head>
<style>
H1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} H2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} H3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} BODY {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} B {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} P {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;}A {color : black;}A.name {color : black;}HR {color : #525D76;}
  table {
    width: 100%;
  }
  td.page-title {
    text-align: center;
    vertical-align: top;
    font-family:sans-serif,Tahoma,Arial;
    font-weight: bold;
    background: white;
    color: black;
  }
  td.title {
    text-align: left;
    vertical-align: top;
    font-family:sans-serif,Tahoma,Arial;
    font-style:italic;
    font-weight: bold;
    background: #D2A41C;
  }
  td.header-left {
    text-align: left;
    vertical-align: top;
    font-family:sans-serif,Tahoma,Arial;
    font-weight: bold;
    background: #FFDC75;
  }
  td.header-center {
    text-align: center;
    vertical-align: top;
    font-family:sans-serif,Tahoma,Arial;
    font-weight: bold;
    background: #FFDC75;
  }
  td.row-left {
    text-align: left;
    vertical-align: middle;
    font-family:sans-serif,Tahoma,Arial;
    color: black;
  }
  td.row-center {
    text-align: center;
    vertical-align: middle;
    font-family:sans-serif,Tahoma,Arial;
    color: black;
  }
  td.row-right {
    text-align: right;
    vertical-align: middle;
    font-family:sans-serif,Tahoma,Arial;
    color: black;
  }
  TH {
    text-align: center;
    vertical-align: top;
    font-family:sans-serif,Tahoma,Arial;
    font-weight: bold;
    background: #FFDC75;
  }
  TD {
    text-align: center;
    vertical-align: middle;
    font-family:sans-serif,Tahoma,Arial;
    color: black;
  }
  form {
    margin: 1;
  }
  form.inline {
    display: inline;
  }
</style>
<title>/manager</title>
</head>

<body bgcolor="#FFFFFF">

<table cellspacing="4" border="0">
 <tr>
  <td colspan="2">
   <a href="http://www.apache.org/">
    <img border="0" alt="The Apache Software Foundation" align="left"
         src="http://www.mamicode.com/manager/images/asf-logo.gif">
   </a>
   <a href="http://tomcat.apache.org/">
    <img border="0" alt="The Tomcat Servlet/JSP Container"
         align="right" src="http://www.mamicode.com/manager/images/tomcat.gif">
   </a>
  </td>
 </tr>
</table>
<hr size="1" noshade="noshade">
<table cellspacing="4" border="0">
 <tr>
  <td class="page-title" bordercolor="#000000" align="left" nowrap>
   <font size="+2">Server Status</font>
  </td>
 </tr>
</table>
<br>

<table border="1" cellspacing="0" cellpadding="3">
<tr>
 <td colspan="4" class="title">Manager</td>
</tr>
 <tr>
  <td class="row-left"><a href="http://www.mamicode.com/manager/html/list">List Applications</a></td>
  <td class="row-center"><a href="http://www.mamicode.com/docs/html-manager-howto.html">HTML Manager Help</a></td>
  <td class="row-center"><a href="http://www.mamicode.com/docs/manager-howto.html">Manager Help</a></td>
  <td class="row-right"><a href="http://www.mamicode.com/manager/status/all">Complete Server Status</a></td>
 </tr>
</table>
<br>

<table border="1" cellspacing="0" cellpadding="3">
<tr>
 <td colspan="8" class="title">Server Information</td>
</tr>
<tr>
 <td class="header-center"><small>Tomcat Version</small></td>
 <td class="header-center"><small>JVM Version</small></td>
 <td class="header-center"><small>JVM Vendor</small></td>
 <td class="header-center"><small>OS Name</small></td>
 <td class="header-center"><small>OS Version</small></td>
 <td class="header-center"><small>OS Architecture</small></td>
 <td class="header-center"><small>Hostname</small></td>
 <td class="header-center"><small>IP Address</small></td>
</tr>
<tr>
 <td class="row-center"><small>Apache Tomcat/7.0.53</small></td>
 <td class="row-center"><small>1.8.0_91-b14</small></td>
 <td class="row-center"><small>Oracle Corporation</small></td>
 <td class="row-center"><small>Linux</small></td>
 <td class="row-center"><small>2.6.32-431.el6.x86_64</small></td>
 <td class="row-center"><small>amd64</small></td>
 <td class="row-center"><small>localhost</small></td>
 <td class="row-center"><small>127.0.0.1</small></td>
</tr>
</table>
<br>

<h1>JVM</h1><p> Free memory: 27.21 MB Total memory: 58.00 MB Max memory: 928.00 MB</p><table border="0"><thead><tr><th>Memory Pool</th><th>Type</th><th>Initial</th><th>Total</th><th>Maximum</th><th>Used</th></tr></thead><tbody><tr><td>Eden Space</td><td>Heap memory</td><td>16.00 MB</td><td>16.00 MB</td><td>256.00 MB</td><td>10.50 MB (4%)</td></tr><tr><td>Survivor Space</td><td>Heap memory</td><td>2.00 MB</td><td>2.00 MB</td><td>32.00 MB</td><td>0.82 MB (2%)</td></tr><tr><td>Tenured Gen</td><td>Heap memory</td><td>40.00 MB</td><td>40.00 MB</td><td>640.00 MB</td><td>19.45 MB (3%)</td></tr><tr><td>Code Cache</td><td>Non-heap memory</td><td>2.43 MB</td><td>6.62 MB</td><td>240.00 MB</td><td>6.49 MB (2%)</td></tr><tr><td>Compressed Class Space</td><td>Non-heap memory</td><td>0.00 MB</td><td>2.12 MB</td><td>1024.00 MB</td><td>1.95 MB (0%)</td></tr><tr><td>Metaspace</td><td>Non-heap memory</td><td>0.00 MB</td><td>18.37 MB</td><td>-0.00 MB</td><td>17.73 MB</td></tr></tbody></table><h1>"ajp-bio-8009"</h1><p> Max threads: 200 Current thread count: 0 Current thread busy: 0<br> Max processing time: 0 ms Processing time: 0.0 s Request count: 0 Error count: 0 Bytes received: 0.00 MB Bytes sent: 0.00 MB</p><table border="0"><tr><th>Stage</th><th>Time</th><th>B Sent</th><th>B Recv</th><th>Client (Forwarded)</th><th>Client (Actual)</th><th>VHost</th><th>Request</th></tr></table><p>P: Parse and prepare request S: Service F: Finishing R: Ready K: Keepalive</p><h1>"http-bio-8080"</h1><p> Max threads: 200 Current thread count: 10 Current thread busy: 1<br> Max processing time: 166 ms Processing time: 0.552 s Request count: 47 Error count: 6 Bytes received: 0.00 MB Bytes sent: 0.27 MB</p><table border="0"><tr><th>Stage</th><th>Time</th><th>B Sent</th><th>B Recv</th><th>Client (Forwarded)</th><th>Client (Actual)</th><th>VHost</th><th>Request</th></tr><tr><td><strong>S</strong></td><td>1 ms</td><td>0 KB</td><td>0 KB</td><td>192.168.10.12</td><td>192.168.10.12</td><td nowrap>192.168.10.12</td><td nowrap class="row-left">GET /manager/status?JSON=true HTTP/1.1</td></tr><tr><td><strong>R</strong></td><td>?</td><td>?</td><td>?</td><td>?</td><td>?</td><td>?</td></tr><tr><td><strong>R</strong></td><td>?</td><td>?</td><td>?</td><td>?</td><td>?</td><td>?</td></tr><tr><td><strong>R</strong></td><td>?</td><td>?</td><td>?</td><td>?</td><td>?</td><td>?</td></tr></table><p>P: Parse and prepare request S: Service F: Finishing R: Ready K: Keepalive</p><hr size="1" noshade="noshade">
<center><font size="-1" color="#525D76">
 <em>Copyright &copy; 1999-2014, Apache Software Foundation</em></font></center>

</body>
</html>


本文出自 “奋斗吧” 博客,请务必保留此出处http://lvnian.blog.51cto.com/7155281/1859894

tomcat status html内容处理 awk