• logstash系列使用中的一些点


    指定conf文件启动一个logstash进程,path.data和path.logs只需要指定到文件夹路径即可,host和port可以不指定

    bin/logstash -f  xxx.conf --path.data=xxx --path.logs=xxx --http.host=xxx --http.port=xxx;

    指定一个conf文件夹启动一个logstash进程

    bin/logstash --path.settings=/opt/test/logstash-7.13.0/prod-conf  --path.data=/opt/test/logstash-7.13.0/data/test --path.logs=/opt/test/logstash-7.13.0/logs/test --http.host=1.1.1.1 --http.port=9642

    支持多个input,在input中添加type标记来分流,比如这样子:

    input {
        beats {port => 5045   type=>"aa"}
        beats {port => 5046   type=>"bb"}
    }

    filter中可以先对message用ruby 的 code 插件进行处理

    output中支持if判断后输出,通常是一个output{},里面指定多个类型的输出,多个输出的例子:

    output {
        kafka {
            topic_id => "topic_1"    
    bootstrap_servers => "10.10.10.10:9092,10.10.10.11:9092"
    codec => "json" } elasticsearch { hosts => "10.10.10.10:9200"
    index => "aa" } }

    ruby的demo,将时间值换算成long值的时间戳

    ruby{
        code => "event.set('requestTimestamp',event.get('requestTimestamp').to_i*1000)"
    }
    
    ruby{
        code => "event.set('requestTimestamp',(event.get('requestTimestamp').to_f.round(3)*1000).to_i)"
    }

     如何给日志增加一个唯一id作为日志id

    第一种是uuid:在每个event中增加一个字段,值为uuid,优点是业务简单,缺点是重复的日志也会被标记为不同的uuid,无法达到去重的目的

    uuid {
       target    => "uuid"
       overwrite => true
    }

    第二种是指纹插件:优点是相同的event,生成的指纹值相同,缺点是这个会比较耗费性能,需要指定算法计算

    fingerprint {
            source => ["aa","message"] 
            target => "fingerprint"
            method => "SHA1"
            key => "lcm"
            concatenate_sources => true 
            base64encode => true
    }

    指纹插件的几点说明:

    base64encode          :设置为true时,SHA1, SHA256, SHA384, SHA512 and MD5方法生成的字符串将会使用base64编码而非hex
    concatenate_sources:设置为true时(且不使用UUID和PUNCTUATION),source属性中的字符串将会拼接起来
    concatenate_all_fields:相当于source中的fields包含所有的fields,且使用concatenate_sources
    sources                       :参与生成指纹的字段
    target                          :存指纹值的字段,如果已经有,将会被覆盖
    key                              :可选项,如果提供了key,将会使用HMAC方法参与生成指纹
    method                       :必填,默认SHA1,支持:SHA1, SHA256, SHA384, SHA512, MD5,MURMUR3(非加密的一致性哈希算法),UUID(产生随机值,不是一致性hash的)

  • 相关阅读:
    Linux Shell处理文本最常用的工具大盘点
    Linux GCC常用命令
    IT运维流程 — ITIL
    linux软件安装与卸载
    ifconfig无输出的解决办法
    du 命令秘籍
    linux主机名的修改
    输错密码?这个 sudo 会“嘲讽”你
    VS开发环境美化
    oracle +plsql装完省略号不能点
  • 原文地址:https://www.cnblogs.com/yb38156/p/15847795.html
Copyright © 2020-2023  润新知