提取日志中未落入标准字段的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. Linux学习 :移植linux-3.4.83到JZ2440开发板

    一.编译环境搭建: 1.linux源码下载:https://www.kernel.org/ (最新)  https://mirrors.edge.kernel.org/pub/linux/kernel ...

  2. DevExpress WinForms v18.2新版亮点(六)

    行业领先的.NET界面控件2018年第二次重大更新——DevExpress v18.2日前正式发布,本站将以连载的形式为大家介绍各版本新增内容.本文将介绍了DevExpress WinForms v1 ...

  3. Creating and Destroying Objects

    Consider static factpry methods instead of construction 四个优点两个缺点 One advantage of static factory met ...

  4. Unity3D使用OpenFileDialog后崩溃

    http://ask.unitymanual.com/question/24922 找了很久,原来是我的dll文件引错了,名字都一样,应该引用unity安装目录下的System.Window.Form

  5. vue 自定义过滤器 格式化金额(保留两位小数)

    1.js部分 import Vue from 'vue' Vue.filter('money', function(val) { val = val.toString().replace(/\$|\, ...

  6. microsoft office如何在菜单里显示“开发工具”

    VBA开发教程: https://www.yiibai.com/vba/vba_excel_macros.html msdn:https://docs.microsoft.com/zh-cn/offi ...

  7. Python 进程的其他方法

    import time import os from multiprocessing import Process def f1(): print("子进程的pid",os.get ...

  8. golang flag简单用法

    package main import ( "flag" "strings" "os" "fmt" ) var ARGS ...

  9. nginx 之 proxy_pass详解

    在nginx中配置proxy_pass代理转发时,如果在proxy_pass后面的url加/,表示绝对根路径:如果没有/,表示相对路径,把匹配的路径部分也给代理走.     假设下面四种情况分别用 h ...

  10. 小技巧, 批处理修改IP

    相信很多人都有这样的麻烦, 工作单位的IP网段与住的不一致, 自己的笔记本在单位和回家的时候每次都要更改IP, 很麻烦,  菜鸟小罗偷个懒, 做了个批处理来修改IP,方便一点. 还有就是可以把工作的时 ...