【ELK】metricbeat 扩展module

一、下载源码:

            https://github.com/elastic/beats

二、创建module

             1、执行    make create-metricset

             执行命令后过程如下:

            依次输入module和metricset,输入完成后可以在metricbeat/module目录下可以看到新增加一个domain目录,并且domain目录下有个flow目录。

            如果在执行create-metricbeat命令时,提示mage命令找不到,可参考: https://magefile.org/

             2、注册新增加的module

            进入metricbeat/include/list_common.go 添加新注册的module

        _ "github.com/elastic/beats/v7/metricbeat/module/vsphere"
        _ "github.com/elastic/beats/v7/metricbeat/module/vsphere/datastore"
        _ "github.com/elastic/beats/v7/metricbeat/module/vsphere/host"
        _ "github.com/elastic/beats/v7/metricbeat/module/vsphere/virtualmachine"
        _ "github.com/elastic/beats/v7/metricbeat/module/windows"
        _ "github.com/elastic/beats/v7/metricbeat/module/windows/perfmon"
        _ "github.com/elastic/beats/v7/metricbeat/module/windows/service"
        _ "github.com/elastic/beats/v7/metricbeat/module/zookeeper"
        _ "github.com/elastic/beats/v7/metricbeat/module/zookeeper/connection"
        _ "github.com/elastic/beats/v7/metricbeat/module/zookeeper/mntr"
        _ "github.com/elastic/beats/v7/metricbeat/module/zookeeper/server"


        // 按照原有格式注册新添加的module
        _ "github.com/elastic/beats/v7/metricbeat/module/domain"
        _ "github.com/elastic/beats/v7/metricbeat/module/domain/flow"

             3、为新增加的module增加配置文件

              进入metricbeat/modules.d目录,按照已存在的配置文件格式为新增加的metricset增加配置,如示例:

           

# Module: domain
# Docs: https://www.elastic.co/guide/en/beats/metricbeat/master/metricbeat-module-system.html
# 新增加domain.yml文件,配置采集flow相关选项

- module: domain
  period: 10s
  metricsets:
    - flow
  # Configure the mount point of the host’s filesystem for use in monitoring a host from within a container

         

             4、为新增加的metricset编写简单逻辑,进行测试

              修改metricbeat/module/domain/flow/flow.go文件,修改fetch函数

func (m *MetricSet) Fetch(report mb.ReporterV2) error {
        report.Event(mb.Event{
                MetricSetFields: common.MapStr{
                        // 增加value,测试是否创建module成功
                        "VALUE":  "test_create_module",
                        "counter": m.counter,
                },
        })
        m.counter++

        return nil
}

             5、重新编译metricbeat,并运行

go build -o metricbeat

./metricbeat

   三、结果

             查看metricbeat发出的内容,可以看到刚才添加的内容已经成功发出,说明module注册成功。

附:

     官方参考文档:Creating a Metricset | Beats Developer Guide [master] | Elastic

  • 5
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值