nginx acces.log日志分析
1,统计各访问IP的总数
awk '{if($9>0 && $9==200 && substr($6,2)== "GET") a[$1]++}END{for(i in a)print i,a[i]}' access.log|sort -t ' ' -k2 -rn|head -n 10
2,统计包含xx字符的总数
cat access.log | grep 'GET /adsview/cqgd/img/tan/cq_320.png' | grep '10/Jun/2019:15' -c
3,查看实时包含xx字符的数据
tail -f access.log | grep 'cq_mb.html'
4,使用python获取日志,并保存到MongoDB进行分析
执行命令:
python logPy.py ./access.log
logPy.py
import re
import sys
import argparse
from collections import Counter
import pymongo
parser = argparse.ArgumentParser(description='python for access.log')
parser.add_argument('log_file', metavar='LOG_FILE', type=argparse.FileType('r'),
help='Path to the Apache log file')
# Regex for the common Apache log format.
parts = [
r'(?P<host>\S+)', # host %h
r'\S+', # indent %l (unused)
r'(?P<user>\S+)', # user %u
r'\[(?P<time>.+)\]', # time %t
r'"(?P<request>.*)"', # request "%r"
r'(?P<status>[0-9]+)', # status %>s
r'(?P<size>\S+)', # size %b (careful, can be '-')
r'"(?P<referrer>.*)"', # referrer "%{Referer}i"
r'"(?P<agent>.*)"', # user agent "%{User-agent}i"
]
pattern = re.compile(r'\s+'.join(parts)+r'\s*\Z')
# Initiazlie required variables
args = parser.parse_args()
log_data = [] # Get components from each line of the log file into a structured dict
for line in args.log_file:
if pattern.match(line):
log_data.append(pattern.match(line).groupdict())
client = pymongo.MongoClient('localhost')
db = client['access']
db['cq_ads'].insert_many(log_data) # Using a counter to get stats on the status in log entries
# Refer = http://docs.python.org/2/library/collections.html#collections.Counter
# status_counter = Counter(x['status'] for x in log_data)
# Printing the STATUS count sorted by highest to lowest count
# print ("Most common STATUSes in the Apache log file %s are:" % args.log_file.name)
# for x in status_counter.most_common():
# print ("\t%s Status %d times" % x)
nginx acces.log日志分析的更多相关文章
- Nginx Access Log日志统计分析常用命令
Nginx Access Log日志统计分析常用命令 IP相关统计 统计IP访问量 awk '{print $1}' access.log | sort -n | uniq | wc -l 查看某一时 ...
- 转 Nginx Access Log日志统计分析常用命令
Nginx Access Log日志统计分析常用命令Nginx Access Log日志统计分析常用命令IP相关统计 统计IP访问量 awk '{print $1}' access.log | sor ...
- (转)DB2 db2diag.log 日志分析
DB2 db2diag.log 日志分析 原文:http://blog.csdn.net/lyjiau/article/details/52129997 db2diag.log是用来记录DB2数据库运 ...
- Nginx+Flume+Hadoop日志分析,Ngram+AutoComplete
配置Nginx yum install nginx (在host99和host101) service nginx start开启服务 ps -ef |grep nginx看一下进程 ps -ef | ...
- [日志分析] Access Log 日志分析
0x00.前言: 如何知道自己所在的公司或单位是否被入侵了?是没人来“黑”,还是因自身感知能力不足,暂时还没发现?入侵检测是每个安全运维人员都要面临的严峻挑战.安全无小事,一旦入侵成功,后果不堪设想. ...
- Android log 日志分析
一. Log 日志中 Bug 类型 程序异常强制关闭: Force Close ,Fatal 程序无响应: Application Not Response , ANR(应用无响应).一般是主线程超时 ...
- 分析nginx access log日志的命令
统计访问最多的ip 1. tail -n 10000 xxaccess_log | cut -d " " -f 1 |sort|uniq -c|sort -rn|head -10 ...
- shell分析nginx access log日志
统计访问最多的ip1. tail -n 10000 xxaccess_log | cut -d " " -f 1 |sort|uniq -c|sort -rn|head -10 | ...
- Nginx日志配置及日志分析脚本案例
https://blog.csdn.net/bbwangj/article/details/82186162 nginx的log日志分为access log 和 error log 其中access ...
随机推荐
- ARDUIN人体检测模块
http://henrysbench.capnfatz.com/henrys-bench/arduino-sensors-and-input/arduino-hc-sr501-motion-senso ...
- 2019-2020-1 20199302《Linux内核原理与分析》第九周作业
一.进程调度的时机 硬中断和软中断 中断:程序执行过程中的强制性转移到操作系统内核相应的处理程序,起到切出指令流的作用. 中断处理程序:与进程无关的内核指令流. 进程切换:切换两个进程的内核堆栈. 硬 ...
- 堆内存腐败异常(STATUS_HEAP_CORRUPTION---0xC0000374)
什么是内存腐败 当堆内存位置的内容由于编程行为而被修改,超出了原始程序构造的意图时,计算机程序就会发生内存腐败,也可以叫内存破坏:这被称为违反内存安全.内存腐败的最可能原因是编程错误.当腐败的内存内容 ...
- 分库分表相关 - hash与range结合去分库分表
相关文章1 整体看下来通过hash取模去分库,然后根据range去分到哪个区间的表中. 具体还要实践下来.
- Spark-Streaming DirectKafka count 案例
Spark-Streaming DirectKafka count 统计跟直接 kafka 统计类似,只不过这里使用的是 Direct 的方式,Direct方式使用的 kafka 低级API,不同的地 ...
- C语言函数内局部变量释放的坑
首先把代码贴上来: #include <stdio.h> #include<windows.h> int f(int **iptr){ ; *iptr = &a; ; ...
- Shell脚本实现对文件编辑
常见Linux文件的编辑命令 vi/vim,有时候我们想写一个脚本实现对文件编辑,这个时候,可能就不够用了,下面介绍一些办法 1.echo命令 Shell的echo命令常用于字符串的输出 例如: [r ...
- 使用pwn_deploy_chroot部署国赛pwn比赛题目
目录 使用pwn_deploy_chroot部署国赛pwn比赛题目 一.前言 二.Docker 三.部署镜像 四.pwn_deploy_chroot 五.check && exp 六. ...
- C盘不够用了
mklink /d C:\Users\zhangbaowei\.nuget\packages i:\link\.nuget\packages mklink /d C:\Users\zhangbaow ...
- Mxnet:以全连接层为例子自定义新的操作(层)
https://blog.csdn.net/a350203223/article/details/77449630 在使用深度学习平台时,光会使用其中已定义好的操作有时候是满足不了实际使用的,一般需要 ...