提取日志中未落入标准字段的mime,分adx,adtype 统计mime的数量和包含js的数量占比

require 'date'
require 'net/http'
require 'uri'
require 'json' def getmimes ( adx , bodyobj ,totalmimes, statics)
if bodyobj.class != Hash
return
end
mimes = []
bodyobj.keys.each do |key|
val = bodyobj[key]
if val.class == Fixnum || val.class == Float || val.class == Array
if key == "imp"
if val[0]['banner'] != nil && val[0]['banner']['mimes'] != nil
statics['includmime'] +=1
mimes += val[0]['banner']['mimes']
end
if val[0]['video'] != nil && val[0]['video']['mimes'] != nil
statics['includmime'] +=1
mimes += val[0]['video']['mimes']
end
end
end
end if mimes.length >0
mimes.each do |mime|
kk = adx.to_s + "_" + mime.to_s
if mime.include?"javascript"
statics['includejs'] +=1
end
totalmimes[ kk] +=1
end
end
end filepath = "/data/mvdsp/log/request.log.2017-11-30-12"
puts filepath
i = 0
totalmimes = Hash.new(0)
statics = Hash.new(0)
begin
File.open("#{filepath}").each do |line|
statics['total'] +=1
if line.length < 1000
statics['invalidbody'] +=1
next
end
if ! line.valid_encoding?
s = line.encode("UTF-16be", :invalid=>:replace, :replace=>"?").encode('UTF-8')
line = s.gsub(/dr/i,'med')
end fields = line.split("\t")
if fields.length <10
next
end
adx = fields[3]
ext10 = fields[45]
adtype = ""
if ext10.class ==Hash && ext10['reqtype']!= nil
adtype =ext10['reqtype']
end jsonstr = fields[6]
bodyobj = {}
begin
bodyobj = JSON.parse jsonstr rescue JSON::ParserError
i +=1
end
getmimes(adx,bodyobj,totalmimes , statics)
end
rescue SystemCallError
puts "warn:: #{filepath} not exits!!"
end puts "-----------totalmimes---------------------"
print totalmimes
sorted = totalmimes.sort_by {|_key, value| value}
puts sorted puts "-----------statics--------------"
print statics
puts "--------------------------------"

ruby hash sort by value

hsh ={"a" => 1000, "b" => 10, "c" => 200000}
Hash[hsh.sort_by{|k,v| v}]
#or
hsh.sort_by{|k,v| v}.to_h
#or
hsh.sort_by(&:last)

日志分析-mime统计的更多相关文章

  1. 使用Spark进行搜狗日志分析实例——统计每个小时的搜索量

    package sogolog import org.apache.spark.rdd.RDD import org.apache.spark.{SparkConf, SparkContext} /* ...

  2. nginx日志分析及其统计PV、UV、IP

    一.nginx日志结构 nginx中access.log 的日志结构: $remote_addr 客户端地址 211.28.65.253 $remote_user 客户端用户名称 -- $time_l ...

  3. 日志分析_统计每日各时段的的PV,UV

    第一步: 需求分析 需要哪些字段(时间:每一天,各个时段,id,url,guid,tracTime) 需要分区为天/时 PV(统计记录数) UV(guid去重) 第二步: 实施步骤 建Hive表,表列 ...

  4. yhd日志分析(二)

    yhd日志分析(二) 继续yhd日志分析,统计数据 日期 uv pv 登录人数 游客人数 平均访问时长 二跳率 独立ip数 1 分析 登录人数 count(distinct endUserId) 游客 ...

  5. mtools 是由MongoDB 官方工程师实现的一套工具集,可以很快速的日志查询分析、统计功能,此外还支持本地集群部署管理.

    mtools 是由MongoDB 官方工程师实现的一套工具集,可以很快速的日志查询分析.统计功能,此外还支持本地集群部署管理 https://www.cnblogs.com/littleatp/p/9 ...

  6. shell常用命令及正则辅助日志分析统计

    https://www.cnblogs.com/wj033/p/3451618.html 正则日志分析统计 3 grep 'onerror'  v3-0621.log | egrep  -v '(\d ...

  7. shell脚本实现网站日志分析统计

    如何用shell脚本分析与统计每天的访问日志,并发送到电子邮箱,以方便每天了解网站情况.今天脚本小编为大家介绍一款不错的shell脚本,可以实现如上功能. 本脚本统计了:1.总访问量2.总带宽3.独立 ...

  8. elk日志分析平台安装

    ELK安装 前言 什么是ELK? 通俗来讲,ELK是由Elasticsearch.Logstash.Kibana 三个开源软件的组成的一个组合体,这三个软件当中,每个软件用于完成不同的功能,ELK 又 ...

  9. 【转】gc日志分析工具

    性能测试排查定位问题,分析调优过程中,会遇到要分析gc日志,人肉分析gc日志有时比较困难,相关图形化或命令行工具可以有效地帮助辅助分析. Gc日志参数 通过在tomcat启动脚本中添加相关参数生成gc ...

随机推荐

  1. angular4-常用指令

    ngIf 指令(它与 AngularJS 1.x 中的 ng-if 指令的功能是等价) <div *ngIf="condition">...</div> n ...

  2. Linux命令----su(切换用户)以及passwd(修改用户密码)

    一.su命令登录root 用户在使用telnet命令可以远程登录,但不可以登录root,这样就需要使用su命令来登录root用户. telnet登录(不能登录root)--- 1.启动终端 输入 te ...

  3. PLY文件格式

    一.PLY简介 PLY文件格式是Stanford大学开发的一套三维mesh模型数据格式,图形学领域内很多著名的模型数据,比如Stanford的三维扫描数据库(其中包括很多文章中会见到的Happy Bu ...

  4. Cracking The Coding Interview 1.7

    //Write an algorithm such that if an element in an MxN matrix is 0, its entire row and column is set ...

  5. SharePoint online Multilingual support - Development(2)

    博客地址:http://blog.csdn.net/FoxDave 上一节讲了如何通过Code的方式设置Site和List级别的国际化,本节介绍一下如何设置Content type和Site co ...

  6. 软件工程结对作业01 psp表格

  7. day 26面向对象 的封装 接口 抽象

    大纲分析 # 面向对象# 类 :一类具有相同属性和方法的事物 #类的定义:class #类中可以定义的方法种类: #普通方法 self 对象 #类方法 cls @classmethod 类/对象 #静 ...

  8. golang切片类型

    切片slice 其本身并不是数组,它指向底层的数组 作为变长数组的替代方案,可以关联底层数组的局部或全部 为引用类型 可以直接创建或从底层数组获取生成 使用len()获取元素个数,cap()获取容量 ...

  9. python DRF获取参数介绍

    DRF获取参数的方式 例如url url(r'^demo/(?P<word>.*)/$', DemoView.as_view()) 在类视图中获取参数 url:http://127.0.0 ...

  10. anaconda jupyter notebook修改默认文件路径

    使用anaconda附带的jupyter,想要改变默认运行文件路径,直接在cmd中输入jupyter notebook会提示:jupyter不是内部命令! 可能是anaconda代理了他所安装的软件, ...