forked from stfc/telegraf-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmetrics-influxdb-fts3-http
executable file
·56 lines (46 loc) · 1.22 KB
/
metrics-influxdb-fts3-http
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/usr/bin/python
import sys
import re
import httplib
import socket
from datetime import datetime, timedelta
hostname = socket.gethostname().split('.')[0]
logfile='/var/log/httpd/fts3rest_access_log'
if 'fts-test' in hostname:
instance = 'test'
elif 'lcgfts' in hostname:
instance = 'production'
else:
instance = 'unknown'
timeformat='%d/%b/%Y:%H:%M'
delta=timedelta(minutes=-1)
now=datetime.now()
then=now+delta
timeString=then.strftime(timeformat)
duration=0
count=0
count200=0
count400=0
count500=0
f=open(logfile)
for line in f:
if timeString in line:
pieces = line.split()
rc = int(pieces[8])
dur = int(pieces[10])
if rc >= 200 and rc < 300:
count200 += 1
elif rc >= 400 and rc < 500:
count400 += 1
elif rc >= 500 and rc < 600:
count500 += 1
count += 1
duration += dur
f.close()
data = 'http_response_status,response=2xx value='+str(count200)+'\n'
data += 'http_response_status,response=4xx value='+str(count400)+'\n'
data += 'http_response_status,response=5xx value='+str(count500)+'\n'
if count > 0:
averageDuration = duration/count
data += 'http_response_duration value='+str(averageDuration)+'\n'
print data