I wanted to know the number of accesses per second for one day, but the seconds that were not accessed with "uniq -c" etc. were missing, so I decided to try Nantoka.
hits.py
#!/usr/bin/env python
import sys
def main():
dict = {}
#init dict
for hour in range(24):
for min in range(60):
for sec in range(60):
hhmmdd = '%02d:%02d:%02d' % (hour, min, sec,)
dict[hhmmdd] = 0
#read stdin
for line in sys.stdin:
text = line.rstrip('\n')
dict[text] = dict[text] + 1
#print hit/s
for hour in range(24):
for min in range(60):
for sec in range(60):
hhmmdd = '%02d:%02d:%02d' % (hour, min, sec,)
print '%s %d' % (hhmmdd, dict[hhmmdd])
if __name__ == '__main__':
main()
Pass the hour, minute, and second portion of the web server log
$ cat /var/log/httpd/access_log | cut -d" " -f4 | cut -d":" -f2- | python hits.py
When I was organizing SSDs, I found a fake script that I made a little while ago, so I put it on Qiita. I wanted to know the number of accesses per second from the Apache log, so I used the "uniq -c" command to add up, but when I thought about it carefully, the seconds without access were missing instead of "0". It's quite natural ... (I started to notice that I'm going to do 86400, even though I counted the number of accesses per second for one day)
So, I made the following script appropriately. It's pretty rough, but I remembered that I was able to do it.
Recommended Posts