Want to see new indicators? Teach you to write prober plug-ins easily

Time:2021-9-4

Want to see new indicators? Teach you to write prober plug-ins easily

The prober plug-in collects management data through API. At present, there are plug-ins:

  • elasticsearch
  • github
  • haproxy
  • mongodb
  • mysql
  • nginx
  • prometheus
  • rabbitmq
  • redis
  • tengine
  • zookeeper

The prober plug-in uses telegraf

(https://www.influxdata.com/time-series-platform/telegraf/T))The plug-in interface is encapsulated. You can:

  • Directly encapsulate a telegraf
  • Write a telegraf plug-in, and then package it into a prober plug-in

Next, take Src / modules / monapi / plugins / demo as an example to introduce the development of plug-ins.

Telegraf plug-in development


Safety tips

You need to implement such an interface type:

Want to see new indicators? Teach you to write prober plug-ins easily

Want to see new indicators? Teach you to write prober plug-ins easily

The following is the implementation of the demo plug-in:

Want to see new indicators? Teach you to write prober plug-ins easily

Want to see new indicators? Teach you to write prober plug-ins easily

In this way, there is a telegraf plug-in. Next, it is encapsulated into a prober plug-in.

ACC in the gather method in the plug-in is an interface. The specific instance is provided by the running environment. When running the plug-in in prober, the implementation of ACC is in Src / modules / prober / Manager / calculator.go

Prober


Prober will periodically obtain the collectrule list from the monapi and check and update its own plug-in instances.

  • create rule collector
  • update rule collector
  • delete rule collector

Update rule is implemented by delete old and create new.

The reason why monapi needs to load plug-ins is that it needs to obtain the parameter description of plug-ins, so as to render an appropriate UI interface for user input. This is the parameter description of the demo:

Want to see new indicators? Teach you to write prober plug-ins easily

The information about UI is described in the tag of structfield. The detailed tag is as follows:

Want to see new indicators? Teach you to write prober plug-ins easily

In this way, after getting the structure, the mapapi can know how to render, fill in the parameters in the structure, and then store the data entered by the user in the database and distribute it to each prober for execution.

After the prober obtains the rule, it converts the rule into a telegraf.input instance through the telegrafinput method of the plug-in.

Want to see new indicators? Teach you to write prober plug-ins easily

test


src/modules/monapi/plugins/demo/demo_test.go

Want to see new indicators? Teach you to write prober plug-ins easily

Want to see new indicators? Teach you to write prober plug-ins easily

deploy

Built in compilation

  • Modify Src / modules / monapi / plugins / all / all.go and add demo
  • Recompile monapi & prober

Plug in loading

Compile your plug-in into a dynamic library file (. So) and copy it to plugins under the monapi & prober working directory/

Want to see new indicators? Teach you to write prober plug-ins easily

Want to see new indicators? Teach you to write prober plug-ins easily

Watch Video Explanationwww.bilibili.com/video/BV1MK…

Recommended Today

Swift advanced (XV) extension

The extension in swift is somewhat similar to the category in OC Extension can beenumeration、structural morphology、class、agreementAdd new features□ you can add methods, calculation attributes, subscripts, (convenient) initializers, nested types, protocols, etc What extensions can’t do:□ original functions cannot be overwritten□ you cannot add storage attributes or add attribute observers to existing attributes□ cannot add parent […]