The following features are specific to agent 2 and its plugins:
single configuration file (all plugin configuration parameters are located in the same file as parameters of the agent itself);
task queue management with respect to schedule and task concurrency;
plugin-level timeouts.
All metrics supported for Zabbix agent 2 are collected by plugins. The following plugins for Zabbix agent 2 are available out-of-the-box:
Common configuration principles and best practices are described in this section.
For specific examples of plugin configuration see also:
All plugins are configured using Plugins.* parameter of the Zabbix agent 2 . Unlike other agent parameters, it is not a key/value type of parameter. It is a separate section where specific parameters of the plugin can be described. Each parameter should have the following structure:
Plugins.<PluginName>.<Parameter>=<Value>
Parameter names should adhere to the following requirements:
the parameter should be capitalized;
nesting isn’t limited by a maximum level;
the number of parameters is not limited.
Named sessions
Named sessions represent an additional level of plugin parameters and can be used to define separate sets of authentication parameters for each of the instances being monitored. Each named session parameter should have the following structure:
Plugins.<PluginName>.<SessionName>.<Parameter>=<Value>
A session name can be used as a connString item key parameter instead of specifying a URI, username, and password separately. In item keys, the first parameter can be either a connString or a Uri. If the first key parameter matches a session name specified in the configuration file, the check will be executed using named session parameters. If the first key parameter doesn’t match any session name, it will be treated as a Uri.
Note, that:
when providing a connString (session name) in key parameters, key parameters for username and password must be empty;
passing embedded URI credentials is not supported, consider using named sessions instead;
in case an authentication parameter is not specified for the named session, a hardcoded default value will be used.
The list of available named session parameters depends on the plugin, see / Zabbix agent 2 (Windows) for details.
Example: Monitoring of two instances “MySQL1” and “MySQL2” can be configured in the following way:
Plugins.Mysql.Sessions.MySQL1.Uri=tcp://127.0.0.1:3306
Plugins.Mysql.Sessions.MySQL1.User=<UsernameForMySQL1>
Plugins.Mysql.Sessions.MySQL2.Uri=tcp://127.0.0.1:3307
Plugins.Mysql.Sessions.MySQL2.User=<UsernameForMySQL2>
Plugins.Mysql.Sessions.MySQL2.Password=<PasswordForMySQL2>
Now, these names may be used as connStrings in keys instead of URIs:
Hardcoded defaults
If a parameter required for authentication is not provided in an item key or in the named session parameters, the plugin will use a hardcoded default value.
Connections
Some plugins support gathering metrics from multiple instances simultaneously. Both local and remote instances can be monitored. TCP and Unix-socket connections are supported.
It is recommended to configure plugins to keep connections to instances in an open state. The benefits are reduced network congestion, latency, and CPU and memory usage due to the lower number of connections. The client library takes care of this.
Time period for which unused connections should remain open can be determined by Plugins.<PluginName>.KeepAlive parameter.
Example: Plugins.Memcached.KeepAlive
A plugin is a Go package that defines the structure and implements one or several plugin interfaces (Exporter, Collector, Runner, Watcher):
- plugin.Exporter
Exporter is the simplest interface that performs a poll and returns a value (values), nothing, error. It accepts a preparsed item key, parameters and context. Exporter interface is the only interface that can be accessed concurrently. All other plugin interface access is exclusive and no method can be called when a plugin is already performing some task. Also, there is a limit of 100 maximum concurrent Export() calls per plugin, which can be reduced as necessary for each plugin.
- plugin.Collector
- plugin.Configurator
Configurator is used to provide plugin its configuration parameters from the agent 2 .
Runner interface provides the means of performing some initialization when a plugin is started (activated) and deinitialization when a plugin is stopped (deactivated). For example, a plugin could start/stop some background goroutine by implementing the Runner interface.
- plugin.Watcher
Watcher allows the plugin to implement its own metric polling, without using the agent’s internal scheduler, for example in trap-based plugins.
Plugins by default are inactive and activated only when a metric provided by the plugin is being monitored.
Plugins are located in the plugin directory tree, grouped by meaning, for example plugins/system/uptime/uptime.go
.
Implementation steps
A plugin must import the zabbix.com/pkg/plugin
package.
import "zabbix.com/pkg/plugin"
A plugin must define the structure and embed the plugin.Base
structure.
A plugin must implement one or several plugin interfaces.
if len(params) > 0 {
p.Debugf("received %d parameters while expected none", len(params))
return nil, errors.New("Too many parameters")
}
return time.Now().Format(time.RFC3339)
}
A plugin must register itself during initialization.
where RegisterMetrics
parameters are:
Pointer to the plugin implementation
Plugin name (upper camel case)
Metric #1 name (item key)
Metric #1 description (starting with an uppercase character and ending with a dot)
Metric #2 name (item key) (optional)
Metric #2 description (starting with an uppercase character and ending with a dot) (optional)
…
If logging is necessary the plugin must use the logging functionality provided by (see the example above). It’s basically a wrapper around standard logging, but it will prefix log messages with [<plugin name>].