用了这个logstash扩展

https://github.com/PeterPaulH/logstash-influxdb/blob/master/src/influxdb.rb

把这个文件放到 logstash-1.4.2/lib/logstash/outputs

看一下午logstash的文档,终于解决了自己的需求

用python描述就是这样的

开发要求统计日志中各种类型的数量

while True:
line = f.readline()
try:
if '"type":"text","receiver_id"' in line:
type = 'directmessage'
elif '"subtype":"unfollow"' in line:
type = 'unfollow'
elif '"subtype":"follow"' in line:
type = 'follow'
elif '"subtype":"status"' in line:
type = 'weibo'
elif '"subtype":"comment"' in line:
type = 'comment'
else:
type = None if type:
data = [
{"name":"pingpong_processor",
"columns" : ["type"],
"points" : [[type]] }
]

logstash配置文件如下

input {
stdin {}
} filter {
if '"type":"text"' in [message] {
mutate {
add_field => { "type" => "directmessage" }
remove_field => [ "message", "search" , "@version" ]
}
} else if '"subtype":"unfollow"' in [message] {
mutate {
add_field => { "type" => "unfollow" }
remove_field => [ "message", "search" , "@version" ]
}
} else if '"subtype":"follow"' in [message] {
mutate {
add_field => { "type" => "follow" }
remove_field => [ "message", "search" , "@version" ]
}
} else if '"subtype":"status"' in [message] {
mutate {
add_field => { "type" => "weibo" }
remove_field => [ "message", "search" , "@version" ]
}
} else if '"subtype":"comment"' in [message] {
mutate {
add_field => { "type" => "comment" }
remove_field => [ "message", "search" , "@version" ]
}
} else {
drop {}
} } output {
influxdb {
host => "10.75.28.180"
port => 4444
name => ["pingpong_processor"]
columns => ["type", "host"]
points => [
"%{type}", "c",
"%{host}", "c"
] } stdout {}
}

别忘记把influxdb的配置也修改下,因为默认upd协议是没有打开的

# Configure the udp api
[input_plugins.udp]
enabled = true
port = 4444
database = "pingpong_processor"

我用的influxdb版本是 influxdb-0.8.2-1.x86_64,用/etc/init.d/influxdb这个启动报错,无奈手动启动的

/usr/bin/influxdb -pidfile /tmp/influxdb.pid -config config.toml

看一下udp端口是否启动了

netstat -anup|grep influxdb
udp 0 0 :::4444 :::* 27512/influxdb

完工

logstash输出到influxdb的更多相关文章

  1. logstash输出到rabbitmq

    场景 将应用日志文件发送到rabbitmq. filebeat 不支持rabbitmq作为输出.因此,需要先将文件由filebeat发送到logstash ,再由logstash 输出到rabbitm ...

  2. logstash输出到elasticsearch多索引

    目标:将json格式的两类日志输出到elasticsearch两类索引 1. 安装logstash. 2. 编写logstash处理配置文件,创建一个test.conf文件,内容如下: input { ...

  3. 第二章 logstash - 输出插件之redis与es

    最常用的两个输出插件: redis es 一.redis 1.用法 output { redis{ batch => false batch_events => 50 batch_time ...

  4. logstash输出至elasticsearch

    续上一篇 上一篇描述了通过logback配置用logstash收集springmvc项目日志,本文是描述如何进一步通过elasticsearch对所收集数据进行的分析. output { elasti ...

  5. logstash 输出到elasticsearch 自动建立index

    由于es 单index 所能承受的数据量有限,之前情况是到400w数据300G左右的时候,整个数据的插入会变得特别慢(索引重建)甚至会导致集群之间的通信断开,于是我们采用每天一个index的方法来缓解 ...

  6. ELK系列五:Logstash输出到Elasticsearch和redis

    1.Logstash与Redis的读写 1.1 Logstash 写入Redis 看完Logstash的输入,想必大家都清楚了Logstash的基本用法,那就是写配置文件. output{ { red ...

  7. ElasticSearch——Logstash输出到Elasticsearch配置

    位置 在Logstash的.conf配置文件中的output中配置ElasticSearch 示例: output { elasticsearch{ action => "index& ...

  8. Windows服务器使用Telegraf采集服务器监控指标输出到influxdb

    1.环境说明 操作系统:Windows Server 2008 R2 IP:192.168.10.135 官方文档地址 :https://docs.influxdata.com/telegraf/v1 ...

  9. SpringBoot日志输出至Logstash

    1.springboot项目pom.xml文件下添加如下配置 2.resources目录下创建logback-spring.xml文件 <?xml version="1.0" ...

随机推荐

  1. 规范和封装jdbc程序代码

    JDBC 部分方法引用工具类 package it.cast.jdbc; import java.sql.Connection; import java.sql.DriverManager; impo ...

  2. 第一个python程序

    一个python程序的两种执行方式: 1.第一种方式是通过python解释器: cmd->python->进入python解释器->编写python代码->回车. 2.第二种方 ...

  3. Ubuntu下的PHP开发环境架设

    Ubuntu下的PHP开发环境架设   今天重新装了ubuntu那么就吧过程记录下. 打开终端,也就是命令提示符. 我们先来最小化组建安装,按照自己的需求一步一步装其他扩展.命令提示符输入如下命令: ...

  4. redis3.2新增属性protected mode

    在安装新版redis时(3.2) , 一直出现问题 , 只能本机连接其他机器访问失败 , 后来发现是新版增加了安全机制 在配置文件里可以发现多出了protected-mode这一项 , 如果为yes ...

  5. 常见的java类

    String System StringBuilder Thread Math ArrayList LinkedList HashMap HashSet Scanner Calendar Date F ...

  6. Ubuntu的安装与配置

    一.Ubuntu的安装与配置 Ubuntu 快速下载地址 1.安装VMwareTools 系统安装后,工具栏"虚拟机"-->"安装VMwareTools" ...

  7. linux系统中如何查看日志(转)

    cat tail -f 日 志 文 件 说    明 /var/log/message 系统启动后的信息和错误日志,是Red Hat Linux中最常用的日志之一 /var/log/secure 与安 ...

  8. Nginx+uwsgi安装配置

    一.安装基础开发包 yum groupinstall "Development tools" yum install zlib-devel bzip2-devel pcre-dev ...

  9. Mssql迁移至Oracle 查询优化

    针对Oracle的查询优化 a.避免使用nclob类型字段,可以通过排除此类型的字段,优化查询b.避免对字段进行NULL值判断,如:SELECT * FROM  TABLE WHERE COL IS ...

  10. cocos2dx 3.x (单选,多选,复选checkBox按钮的实现) RadioButton

    // //  LandLordsMakeNewRoom.hpp //  MalaGame39 // //  Created by work on 2016/12/19. // //   #ifndef ...