mtail使用

获取mtail,在https://github.com/google/mtail 下载二进制文件

json.Decoder缓存整个JSON数据到内存,然后才解析成GO值。因此在从io.Reader流读取数据时,或者是从多个流数据解析值时,建议使用json.Decoder.在内存中已经存在json数据时,使用json.Unmarshal.因此在http请求时,使用json.Decoder,因为明显是在读取流数据(stream)

示例:

values := map[string]string{"name": "John Doe", "occupation": "gardener"}

json_data, err := json.Marshal(values)

if err != nil {

log.Fatal(err)

}

resp, err := http.Post("https://httpbin.org/post", "application/json",

bytes.NewBuffer(json_data))

if err != nil {

log.Fatal(err)

}

var res map[string]interface{}

json.NewDecoder(resp.Body).Decode(&res)

fmt.Println(res["json"])

获取mtail采集数据,有两种方式

pull基础采集 localhost:3903/json

push基础采集:

mtail --progs /etc/mtail --logs /var/log/syslog,/var/log/rsyncd.log --collectd_socketpath=/var/run/collectd-unixsock

mtail --progs /etc/mtail --logs /var/log/syslog,/var/log/rsyncd.log --graphite_host_port=localhost:9999

配置采集规则:

/etc/mtail/secure.mtail

counter fip_total by sip

counter ip_access by tip

counter test_ip

/Failed password .* (?P<sip>\d+(\.\d+){3}) port / {

fip_total[$sip]++

}

/Accepted publickey .* (?P<tip>\d+(\.\d+){3}) port / {

ip_access[$tip]++

}

/Received disconnect from 122.224.140.154 port/ {

test_ip++

}

配置mtail service:

/etc/systemd/system/mtail.service

[Unit]

Description="mtail:安全日志采集"

After=network.target

[Service]

Type=simple

ExecStart=/usr/bin/mtail --progs /etc/mtail --logs /var/log/secure --override_timezone=Local

ExecReload=/bin/killall -HUP mtail

ExecStop=/bin/kill -s TERM $MAINPID

Restart=on-failure

[Install]

WantedBy=multi-user.target

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值