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日志分析的更多相关文章

  1. Nginx Access Log日志统计分析常用命令

    Nginx Access Log日志统计分析常用命令 IP相关统计 统计IP访问量 awk '{print $1}' access.log | sort -n | uniq | wc -l 查看某一时 ...

  2. 转 Nginx Access Log日志统计分析常用命令

    Nginx Access Log日志统计分析常用命令Nginx Access Log日志统计分析常用命令IP相关统计 统计IP访问量 awk '{print $1}' access.log | sor ...

  3. (转)DB2 db2diag.log 日志分析

    DB2 db2diag.log 日志分析 原文:http://blog.csdn.net/lyjiau/article/details/52129997 db2diag.log是用来记录DB2数据库运 ...

  4. Nginx+Flume+Hadoop日志分析,Ngram+AutoComplete

    配置Nginx yum install nginx (在host99和host101) service nginx start开启服务 ps -ef |grep nginx看一下进程 ps -ef | ...

  5. [日志分析] Access Log 日志分析

    0x00.前言: 如何知道自己所在的公司或单位是否被入侵了?是没人来“黑”,还是因自身感知能力不足,暂时还没发现?入侵检测是每个安全运维人员都要面临的严峻挑战.安全无小事,一旦入侵成功,后果不堪设想. ...

  6. Android log 日志分析

    一. Log 日志中 Bug 类型 程序异常强制关闭: Force Close ,Fatal 程序无响应: Application Not Response , ANR(应用无响应).一般是主线程超时 ...

  7. 分析nginx access log日志的命令

    统计访问最多的ip 1. tail -n 10000 xxaccess_log | cut -d " " -f 1 |sort|uniq -c|sort -rn|head -10 ...

  8. shell分析nginx access log日志

    统计访问最多的ip1. tail -n 10000 xxaccess_log | cut -d " " -f 1 |sort|uniq -c|sort -rn|head -10 | ...

  9. Nginx日志配置及日志分析脚本案例

    https://blog.csdn.net/bbwangj/article/details/82186162 nginx的log日志分为access log 和 error log 其中access ...

随机推荐

  1. Tensorflow细节-P309-监控指标可视化

    注意下面一个点就ok了 with tf.name_scope('input_reshape'): # 注意看这里,图片的生成 image_shaped_input = tf.reshape(x, [- ...

  2. S1_搭建分布式OpenStack集群_10 cinder 存储节点配置

    一.安装配置lvm2安装LVM包:# yum install -y lvm2 启动LVM元数据服务,并将其配置为在系统启动时启动:# systemctl enable lvm2-lvmetad.ser ...

  3. WinDbg常用命令系列---反汇编u*

    u, ub, uu (Unassemble) u*命令显示内存中指定程序代码的汇编转换.不要将此命令与~u(解冻线程)命令混淆. u[u|b] Range u[u|b] Address u[u|b] ...

  4. isntall

    #! /bin/bash # zabbix server address zabbix='10.10.238.110' # repo address REPO='10.10.238.114:4507' ...

  5. ShardingSphere初探1 -- 概览

    知道这个框架是通过一期QQ课堂 https://shardingsphere.apache.org 官网 https://github.com/apache/incubator-shardingsph ...

  6. 了解Python-白 驹 过 隙 , 忽 然 而 已

    白 驹 过 隙 , 忽 然 而 已 人 生 苦 短,我 用 Python -- Life is short , you need Python 代码量少,同一样问题 ,用不同的语言解决时,一般情况下P ...

  7. struct udphdr

    udphdr结构包含在/usr/src/linux/include/linux/udp.h struct udphdr { __u16 source; __u16 dest; __u16 len; _ ...

  8. 【POJ2251】Dungeon Master

    本题传送门 本题知识点:宽度优先搜索 题意简单.在一个L层高的楼里,去走迷宫,就是问从S走到E的最短路径.每走一格每上或者下一层都算1步. 一开始以为这个"立体迷宫"有点吓到我(题 ...

  9. Dubbo+Zookeeper的简单入门案例

    1.1  Dubbo简介 Apache Dubbo是一款高性能的Java RPC框架.其前身是阿里巴巴公司开源的一个高性能.轻量级的开源Java RPC框架,可以和Spring框架无缝集成. 什么是R ...

  10. js中isNaN和Number.isNaN的区别

    isNaN 当我们向isNaN传递一个参数,它的本意是通过Number()方法尝试将这参数转换成Number类型,如果成功返回false,如果失败返回true. 所以isNaN只是判断传入的参数是否能 ...