Zabbix 监控apache server-status CentOS 6

2016年6月27日

首先打开apache的server-status (一般此功能是关闭的):

这里是yum 安装的,编译安装的在自定义目录中找到 httpd.conf

  1. vim /etc/httpd/conf/httpd.conf
  2. #<location /server-status>
  3. #   SetHandler server-status
  4. #    Order Allow,Deny
  5. #   Allow from all
  6. #</location>

打开注释  启用此功能 ,  同时注意 这信息我不想让任何人都可以看到 就不能使用  allow from all   下面是一个示例:

  1. <location /server-status>
  2. SetHandler server-status
  3. Order Allow,Deny
  4. Deny  from all
  5. Allow from 127.0.0.1
  6. Allow from 192.168.11.110
  7. Allow from  192.168.11.111
  8. Allow from  192.168.11.112
  9. </location>

保存 修改,重启apache

service  httpd restart

[root@localhost shell]# curl 127.0.0.1/server-status
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<html><head>
<title>Apache Status</title>
</head><body>
<h1>Apache Server Status for 127.0.0.1</h1>
 
<dl><dt>Server Version: Apache/2.2.15 (Unix) DAV/2 PHP/5.4.45 SVN/1.6.11</dt>
<dt>Server Built: Jul 18 2016 15:21:39
</dt></dl><hr /><dl>
<dt>Current Time: Wednesday, 26-Apr-2017 10:57:21 CST</dt>
<dt>Restart Time: Tuesday, 25-Apr-2017 04:02:02 CST</dt>
<dt>Parent Server Generation: 3</dt>
<dt>Server uptime: 1 day 6 hours 55 minutes 19 seconds</dt>
<dt>1 requests currently being processed, 9 idle workers</dt>
</dl><pre>__._W__.____....................................................
................................................................
</pre>
<p>Scoreboard Key:<br />
"<b><code>_</code></b>" Waiting for Connection,
"<b><code>S</code></b>" Starting up,
"<b><code>R</code></b>" Reading Request,<br />
"<b><code>W</code></b>" Sending Reply,
"<b><code>K</code></b>" Keepalive (read),
"<b><code>D</code></b>" DNS Lookup,<br />
"<b><code>C</code></b>" Closing connection,
"<b><code>L</code></b>" Logging,
"<b><code>G</code></b>" Gracefully finishing,<br />
"<b><code>I</code></b>" Idle cleanup of worker,
"<b><code>.</code></b>" Open slot with no current process</p>
<p />
PID Key: <br />
<pre>
15018 in state: _ , 17680 in state: _ , 3068 in state: _
10415 in state: W , 26388 in state: _ , 8383 in state: _
32732 in state: _ , 27381 in state: _ , 11944 in state: _
435 in state: _ ,
</pre>
<hr />To obtain a full report with current status information you need to use the <code>ExtendedStatus On</code> directive.
</body></html>

To obtain a full report with current status information you need to use the <code>ExtendedStatus On directive.</code>

看到这样的提示表示  需要开启ExtendedStatus On

vim /etc/httpd/conf/httpd.conf
ExtendedStatus On

重启apache

curl 127.0.0.1/server-status

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<html><head>
<title>Apache Status</title>
</head><body>
<h1>Apache Server Status for 127.0.0.1</h1><dl><dt>Server Version: Apache/2.2.15 (Unix) DAV/2 PHP/5.4.45 SVN/1.6.11</dt>
<dt>Server Built: Jul 18 2016 15:21:39
</dt></dl><hr /><dl>
<dt>Current Time: Wednesday, 26-Apr-2017 11:05:38 CST</dt>
<dt>Restart Time: Wednesday, 26-Apr-2017 11:05:27 CST</dt>
<dt>Parent Server Generation: 0</dt>
<dt>Server uptime: 10 seconds</dt>
<dt>Total accesses: 3 - Total Traffic: 40 kB</dt>
<dt>CPU Usage: u.43 s.05 cu0 cs0 - 4.8% CPU load</dt>
<dt>.3 requests/sec - 4096 B/second - 13.3 kB/request</dt>
<dt>2 requests currently being processed, 6 idle workers</dt>
</dl><pre>____W_R_........................................................
................................................................
</pre>
<p>Scoreboard Key:<br />
"<b><code>_</code></b>" Waiting for Connection,
"<b><code>S</code></b>" Starting up,
"<b><code>R</code></b>" Reading Request,<br />
"<b><code>W</code></b>" Sending Reply,
"<b><code>K</code></b>" Keepalive (read),
"<b><code>D</code></b>" DNS Lookup,<br />
"<b><code>C</code></b>" Closing connection,
"<b><code>L</code></b>" Logging,
"<b><code>G</code></b>" Gracefully finishing,<br />
"<b><code>I</code></b>" Idle cleanup of worker,
"<b><code>.</code></b>" Open slot with no current process</p>
<p />
<table border="0"><tr><th>Srv</th><th>PID</th><th>Acc</th><th>M</th><th>CPU
</th><th>SS</th><th>Req</th><th>Conn</th><th>Child</th><th>Slot</th><th>Client</th><th>VHost</th><th>Request</th></tr><tr><td><b>0-0</b></td><td>5963</td><td>0/1/1</td><td>_
</td><td>0.25</td><td>7</td><td>287</td><td>0.0</td><td>0.00</td><td>0.00
</td><td>74.207.253.220</td><td nowrap>blog.megamotormadness.com</td><td nowrap>GET /wp-login.php HTTP/1.0</td></tr><tr><td><b>1-0</b></td><td>5964</td><td>0/1/1</td><td>_
</td><td>0.23</td><td>6</td><td>257</td><td>0.0</td><td>0.00</td><td>0.00
</td><td>74.207.253.220</td><td nowrap>blog.megamotormadness.com</td><td nowrap>POST /wp-login.php HTTP/1.0</td></tr>
 
<tr><td><b>4-0</b></td><td>5967</td><td>0/0/0</td><td><b>W</b>
</td><td>0.00</td><td>0</td><td>1472680755</td><td>0.0</td><td>0.00</td><td>0.00
</td><td>127.0.0.1</td><td nowrap>localhost.localdomain</td><td nowrap>GET /server-status HTTP/1.1</td></tr>
 
<tr><td><b>5-0</b></td><td>5968</td><td>0/1/1</td><td>_
</td><td>0.00</td><td>3</td><td>1379</td><td>0.0</td><td>0.03</td><td>0.03
</td><td>189.83.74.83</td><td nowrap>edm.choies.com</td><td nowrap>GET /blogger/wanted_1.jpg HTTP/1.1</td></tr>
 
<tr><td><b>6-0</b></td><td>5969</td><td>0/0/0</td><td><b>R</b>
</td><td>0.00</td><td>4</td><td>0</td><td>0.0</td><td>0.00</td><td>0.00
</td><td>?</td><td nowrap>?</td><td nowrap>..reading.. </td></tr>
 
</table>
<hr /> <table>
<tr><th>Srv</th><td>Child Server number - generation</td></tr>
<tr><th>PID</th><td>OS process ID</td></tr>
<tr><th>Acc</th><td>Number of accesses this connection / this child / this slot</td></tr>
<tr><th>M</th><td>Mode of operation</td></tr>
<tr><th>CPU</th><td>CPU usage, number of seconds</td></tr>
<tr><th>SS</th><td>Seconds since beginning of most recent request</td></tr>
<tr><th>Req</th><td>Milliseconds required to process most recent request</td></tr>
<tr><th>Conn</th><td>Kilobytes transferred this connection</td></tr>
<tr><th>Child</th><td>Megabytes transferred this child</td></tr>
<tr><th>Slot</th><td>Total megabytes transferred this slot</td></tr>
</table>
</body></html>

看到这样的信息表示成功

然后 添加 Zabbix 的监控和执行脚本

  1. vim /etc/zabbix/shell/apache_status.sh
  2. #!/bin/bash
  3. if [[ "$1" = "Workers" ]]; then
  4. wget --quiet -O - http://127.0.0.1/server-status?auto | grep Score | grep -o "\." | wc -l
  5. else
  6. wget --quiet -O - http://127.0.0.1/server-status?auto | head -n 9 | grep $1 | awk -F ":" '{print $2}'
  7. fi

 

  1. vim  /etc/zabbix/zabbix_agentd.d/apache.conf
  2. UserParameter=apache[*],/etc/zabbix/shell/apache_status.sh $1

重启 zabbix-agent 测试

[root@localhost ~]# zabbix_get -s 127.0.0.1 -k apache[Uptime]
17

最后在 Zabbix Server 端导入模板并关联

模板 Apache_Status

没有评论

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注