Https://www.elastic.co/guide/en/beats/devguide/current/index.html
First, the local correct installation Golang
Yum install-y Golang or Https://golang.org/doc/install
Second, set up a good Gopath
Vim ~/.bash_profile
Export Goroot=/usr/local/go
Export path= $PATH: $GOROOT/bin
Export Gopath=/usr/local/go
Third, access to Metricbeat source code
Clone the Beat, the directory is $goroot/$yourdirectory/src/github.com/elastic/beats
Git clonehttps://github.com/elastic/beats.git
Or:
Go get github.com/elastic/beats/metricbeat
Iv. creation of Metricset
Proceed to $GOROOT/$yourdirectory/src/github.com/elastic/beats/metricbeat/Directory
Make Create-metricset (dependent on Yum install-y python-virtualenv)
Follow the prompts to enter the custom module name & metricset name (module name can be an existing module and add a new Metricset to an existing module)
Module Name:
Metricset Name:
V. Editing Custom Scripts
Go to {metricbeat}/module/{module name}/{metricset name}/Edit Custom Script
{metricset Name}.go # change script template will be generated automatically, generally only need to modify the Func Fetch () custom data acquisition and data output
VI. Compiling metricbeat
To the {metricbeat}/module/{module name}/directory
Perform make collect #将所做的修改录入metricbeat
Execute Make #编译
VII. Debug
After compiling, a metricbeat binary file will appear, in the MODULES.D directory you can remove the configuration file that needs to collect data disabled (by default, only system is not disabled)
Run./METRICBEAT-E-D "*" to debug to see if the compiled metricbeat is working properly, the data collected is normal
Viii. using compiled Metricbeat
Copy the normal working binary file metricbeat to the original metricbeat binary directory, replace it, copy all files under the generated MODULES.D folder to/etc/metricbeat/modules.d/and replace the original file.
Systemctl Stop Metricbeat
CP Metcibeat/usr/bin/metricbeat
CP Metricbeat/usr/share/metricbeat/bin/metricbeat
Cp-r modules.d/*/etc/metricbeat/modules.d/
Nine, start metricbeat service
Modify the configuration file/etc/metricbeat/metricbeat.yml and start the service
Configure parameters such as output
Systemctl Start Metricbeat