Skip to content

Commit

Permalink
Add response code logging
Browse files Browse the repository at this point in the history
  • Loading branch information
adubkov committed Mar 20, 2014
1 parent 1b6f1e0 commit 99aa7a8
Show file tree
Hide file tree
Showing 3 changed files with 488 additions and 11 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ It's accumulate nginx stats and parse the access.log (just pice of log at oce) a
## What's logging:

- Request\sec
- Keepalive connections
- Active connections
- Response codes (200,301,302,403,404,500,503)\min
- Active\Keepalive connections
- Header and body reading
- Accepted, handled connections

Expand Down
13 changes: 13 additions & 0 deletions zbx_nginx_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ def write_seek(file, value):
total_rps = 0
rps = [0]*60
tps = [0]*60
res_code = {}

nf = open(nginx_log_file_path, 'r')

Expand All @@ -156,6 +157,12 @@ def write_seek(file, value):
new_seek = nf.tell()
total_rps += 1
sec = int(re.match('(.*):(\d+):(\d+):(\d+)\s', line).group(4))
code = re.match(r'(.*)"\s(\d*)\s', line).group(2)
if code in res_code:
res_code[code] += 1
else:
res_code[code] = 1

rps[sec] += 1
line = nf.readline()

Expand All @@ -170,14 +177,20 @@ def write_seek(file, value):

data_to_send = []

# Adding the metrics to response
if not metric:
for i in data:
data_to_send.append(Metric(hostname, ('nginx[%s]' % i), data[i]))
else:
print data[metric]

# Adding the request per seconds to response
for t in range(0,60):
data_to_send.append(Metric(hostname, 'nginx[rps]', rps[t], minute+t))

# Adding the response codes stats to respons
for t in res_code:
data_to_send.append(Metric(hostname, ('nginx[%s]' % t), res_code[t]))


send_to_zabbix(data_to_send, zabbix_host, zabbix_port)
Loading

0 comments on commit 99aa7a8

Please sign in to comment.