国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > Python > 正文

Python實(shí)現(xiàn)獲取nginx服務(wù)器ip及流量統(tǒng)計(jì)信息功能示例

2020-02-23 00:09:25
字體:
供稿:網(wǎng)友

本文實(shí)例講述了Python實(shí)現(xiàn)獲取nginx服務(wù)器ip及流量統(tǒng)計(jì)信息功能。分享給大家供大家參考,具體如下:

#!/usr/bin/python#coding=utf8log_file = "/usr/local/nginx/logs/access.log"with open(log_file) as f:  contexts = f.readlines()# define ip dict###ip = {}   # key為ip信息,value為ip數(shù)量(若重復(fù)則只增加數(shù)量)flow = {}  # key為ip信息,value為流量總和sum = 0for line in contexts:  # count row size of flow  size = line.split()[9]  # print ip  ip_attr = line.split()[0]  # count total size of flow  sum = int(size) + sum  if ip_attr in ip.keys():  # if ip repeated,如果ip重復(fù)就將ip數(shù)量加一,而流量繼續(xù)疊加  # count of ip plus 1    ip[ip_attr] = ip[ip_attr] + 1  # size of flow plus size    flow[ip_attr] = flow[ip_attr] + int(size)  else:  # if ip not repeated  # define initial values of count of ip and size of flow    ip[ip_attr] = 1    flow[ip_attr] = int(size)print(ip)print(flow)print(sum/1024/1024)

現(xiàn)在有nginx的訪問日志:

[root@weblogic ~]# cat access.log 192.168.223.1 - - [18/Jul/2017:10:21:25 +0800] "GET /favicon.ico HTTP/1.1" 192.168.223.136:8080 404 24 "http://192.168.223.136:8080/proxy_path/index.html" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36" "-"192.168.223.136 "192.168.223.1" - - [17/Jul/2017:17:06:44 +0800] "GET /index.html HTTP/1.0" "192.168.223.136" 304 0 "-" "Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; rv:11.0) like Gecko" "192.168.223.1"192.168.223.1 - - [18/Jul/2017:10:30:12 +0800] "GET /proxy_path/index.html HTTP/1.1" 192.168.223.136:8080 304 0 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36" "-"192.168.223.136 "192.168.223.1" - - [18/Jul/2017:10:30:12 +0800] "GET /index.html HTTP/1.0" "192.168.223.137" 304 0 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36" "192.168.223.1"192.168.223.1 - - [18/Jul/2017:10:38:38 +0800] "GET /proxy_path/index.html HTTP/1.1" 192.168.223.136:8080 304 0 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36" "-"192.168.223.136 "192.168.223.1" - - [18/Jul/2017:10:38:38 +0800] "GET /index.html HTTP/1.0" "192.168.223.136:80" 304 0 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36" "192.168.223.1"192.168.223.1 - - [18/Jul/2017:10:45:07 +0800] "GET /proxy_path/index.html HTTP/1.1" 192.168.223.136:8080 304 0 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36" "-"192.168.223.136 "192.168.223.1" - - [18/Jul/2017:10:45:07 +0800] "GET /index.html HTTP/1.0" "192.168.223.136:80" 304 0 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36" "192.168.223.1"192.168.223.1 - - [18/Jul/2017:10:51:25 +0800] "GET /proxy_path/index.html HTTP/1.1" 192.168.223.136:8080 304 0 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36" "-"192.168.223.136 "192.168.223.1" - - [18/Jul/2017:10:51:25 +0800] "GET /index.html HTTP/1.0" "192.168.223.136:80" 304 0 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36" "192.168.223.1"            
發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 信丰县| 垦利县| 麦盖提县| 昆明市| 秀山| 平阴县| 卫辉市| 宁乡县| 太保市| 桃园县| 宣汉县| 西畴县| 廉江市| 阿拉善右旗| 荔浦县| 东明县| 和政县| 综艺| 遂宁市| 永胜县| 赤水市| 商丘市| 柳林县| 龙口市| 右玉县| 太仆寺旗| 昌平区| 张家港市| 衢州市| 九寨沟县| 汝州市| 华亭县| 洪雅县| 牡丹江市| 旬邑县| 文化| 渝北区| 广宁县| 文昌市| 天门市| 汾西县|