目录

Logstash 使用记录

Filters

Ruby

redis

安装依赖
1
2
cd /opt/logstash
env GEM_HOME=vendor/bundle/jruby/1.9 GEM_PATH="" java -jar vendor/jruby-complete-1.7.11.jar -S gem install redis
示例
1
2
3
4
5
6
7
filter {
   ...
   ruby {
      init => 'require "redis"; $rc = Redis.new(path: "/var/run/redis/redis.sock", db: 0)'
      code => 'event.set("enriched_field", $rc.get(event.get("key_field")))'
   }
}
1
2
3
4
5
6
7
filter {
   ...
   ruby {
      init => 'require "redis"; $redis = Redis.new(host: "127.0.0.1", port: 6379, db: 5)'
      code => 'event.set("enriched_field", $redis.get(event.get("key_field")))'
   }
}
1
2
3
4
5
6
7
filter {
   ...
   ruby {
      init => 'require "redis"; $redis = Redis.new(host: "127.0.0.1", port: 6379, db: 5)'
      code => 'event.set("enriched_field", $redis.get(event.get("key_field")))'
   }
}

Curls

查看 event 情况

1
curl -s "localhost:9600/_node/stats/events?pretty=true"

查看堆内存使用情况

1
curl -s localhost:9600/_node/stats/jvm?pretty=true

查看 pipeline 详细信息

1
curl -s localhost:9600/_node/stats/pipeline?pretty=true

Commands

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
    bin/logstash -e 'input { stdin { } } output { stdout {} }' --path.data=/opt/data/logstash/

    bin/logstash --path.data=/opt/data/logstash/ --config.test_and_exit -f /opt/data/configs/logstash-first-pipeline.conf

    bin/logstash --path.data=/opt/data/logstash/ --config.reload.automatic -f /opt/data/configs/logstash-first-pipeline.conf
    
    bin/logstash -e "filter { ruby { path => '/usr/local/etc/logstash/pipelines/filters.rb' script_params => { 'proc' => 'check_player' } } }" -t
    
    bin/logstash -e "filter { ruby { path => '/usr/local/etc/logstash/pipelines/filters.rb' script_params => { 'proc' => 'check_player' 'x' => 'add_time' 'y' => 'role_reg_time' 'z' => 'role_reg_days' } } }" -t
    
    bin/logstash -e 'filter { ruby { path => "/usr/local/etc/logstash/scripts/filters.rb" } }' -t