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. qtcreator cannot find catkin packages

    adding /opt/ros/kinetic to CMAKE_PREFIX_PATH in Project -> build environment only /opt/ros/kineti ...

  2. [Javascript] Window.matchMedia()

    window.matchMedia() allow to listen to browser window size changes and trigger the callback for diff ...

  3. ThinkCMF框架任意内容包含

    更多内容,欢迎关注微信公众号:信Yang安全,期待与您相遇. ThinkCMF是一款基于PHP+MYSQL开发的中文内容管理框架,底层采用ThinkPHP3.2.3构建.ThinkCMF提出灵活的应用 ...

  4. am335x system upgrade kernel ethernet(四)

    1      Scope of Document This document describes ethernet hardware design and porting KZS8081 to ubo ...

  5. requestLayout() improperly called by xxxxxxxxxxxxxxxxxxx ScrollViewContainer 问题

    当scrollview内的内容更改大小时,Scrollview不会自行调整大小.效果是,当内容变小时,内容将留在原来的位置,当内容变大时,无法看到.仅当ScrollView位于作为MasterDeta ...

  6. javascript之反柯里化uncurrying

    使用方法: // 使用 var push=Array.prototype.push.uncurrying(); var obj={ "length": 1, "0&quo ...

  7. shell脚本编程基础之函数

    函数 作用:代码重用 定义函数: 方法1: function FUNCTION_NAME { #函数名和定义变量名一样,只能包含数字字母下划线,并且不能以数字开头 command } 方法2: FUN ...

  8. 【18NOIP普及组】对称二叉树(信息学奥赛一本通 1981)(洛谷 5018)

    [题目描述] 一棵有点权的有根树如果满足以下条件,则被轩轩称为对称二叉树: 1.二叉树: 2.将这棵树所有节点的左右子树交换,新树和原树对应位置的结构相同且点权相等. 下图中节点内的数字为权值,节点外 ...

  9. Net core学习系列(一)——Net Core介绍

    一.什么是Net Core .NET Core是适用于 windows.linux 和 macos 操作系统的免费.开源托管的计算机软件框架,是微软开发的第一个官方版本,具有跨平台 (Windows. ...

  10. C# 获取文件扩展信息-应用名称/作者等

    方案一:使用微乳封装的Shell包 添加nuget包:Microsoft.WindowsAPICodePack.Shell using Microsoft.WindowsAPICodePack.She ...