Quick Nginx Status Script

Just to share another script that I hacked together to monitor my sites. Nginx is a great web server software and since I last wrote about it more than 2 years ago, I have since pretty much converted all my sites to Nginx (sorry Lighttpd).

Nginx came with this HTTP stub status module that you can get the current server status in a HTML page. However it’s not pretty comparing to Lighttpd’s and Apache’s. Moreover, the information it provides is a bit cryptic.

For example, when you browse to the stub status page (please refer to the wiki document linked earlier on how to set it up), all you get is 4 lines of text:

$ curl http://myserver/nginx_status
Active connections: 183
server accepts handled requests
914384 914384 2725561
Reading: 3 Writing: 2 Waiting: 178

Not very meaningful. Instead, I wrote a small Python script (download here: nginxstats.py (2.3kb) ) that does something like this:

$ ./nginxstats.py http://myserver/nginx_status
Conn Conn/s Request/s Read Write Wait
-------- ---------- ---------- ----- ----- -----
157 9.57 31.07 0 2 155
140 10.20 36.13 0 1 139
147 9.33 33.60 0 4 143
189 12.60 40.07 1 4 184
164 13.07 41.53 5 2 157

Basically it fetches the data from the stub status page every 30 seconds (configurable in the script) and then do some calculation to find out how many connections have been established within the time frame, and what’s the average connections/second and requests/second. Similar to tools like vmstat , it basically runs continuously (until interrupted).

Very useful when you are getting slashdotted :)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值