提取日志中未落入标准字段的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-表单

    导入表单模块 import { FormsModule } from '@angular/forms'; // ... @NgModule({ imports: [BrowserModule, For ...

  2. 《Python》常用内置模块

    一.time模块(时间模块) 三种格式: 1.时间戳时间(timestamp):浮点数,秒为单位,从1970年1月1日0时距今的时间 1970.1.1  0:0:0 英国伦敦时间(开始时间) 1970 ...

  3. hMailServer 配置

    本例记录如何通过  [hMailServer] 在私有服务器中搭建邮件服务器 1.下载安装包 版本: hMailServer-5.6.7-B2425.exe (支持使用内置数据库) , 安装时,设置管 ...

  4. 插入排序算法 Java实现

    插入排序算法是算法排序中的一种: 该算法是假设已有序列是有序序列,从首元素(首元素为单个元素,肯定是有序的...)开始分析,对其他元素的位置进行有序的确定: 以算法为例: public class I ...

  5. python+requests+excel 接口自动化框架

    一.项目框架如图: 1.common :这个包都是一些公共的方法,如:手机号加解密,get/post接口请求的方法封装,接口鉴权,发邮件,读写excel文件方法等等 2.result:存放每次运行的l ...

  6. Building Tablet PC Applications ROB JARRETT

    Building Tablet PC Applications ROB JARRETT Tablet PC 开发,有需要PDF的留下邮箱 目录This text was added by using ...

  7. 路径问题 :<c:url >的作用

    最近的项目一直报这样的错 可是本地启动 又没问题,xshell查看日志 没有错误日志,找了好久都没想到错误原因.一位大佬几分钟就找到原因了有点扎心. 首先说一下解决问题的思路.首先报错是4开头,说明是 ...

  8. python基础之socket与socketserver

    ---引入 Socket的英文原义是“孔”或“插座”,在Unix的进程通信机制中又称为‘套接字’.套接字实际上并不复杂,它是由一个ip地址以及一个端口号组成.Socket正如其英文原意那样,像一个多孔 ...

  9. 队列 c实现

    循环队列的数组实现 queue.h #ifndef _QUEUE_H_ #define _QUEUE_H_ #define SIZE 10 typedef int data_t; typedef st ...

  10. Spring 配置文件

    <?xml version="1.0" encoding="UTF-8" ?> <beans> <bean id=...> ...