Plugin:Exec

From collectd Wiki

Jump to: navigation, search
Exec plugin
Type: other
Callbacks: config, init, notification, read, shutdown
Status: supported
First version: 4.0
Copyright: 2007–2009 Florian octo Forster
2007–2009 Sebastian Harl
2008 Peter Holik
License: GPLv2
Manpage: collectd.conf(5)
collectd-exec(5)
List of Plugins

Contents

[edit] Description

The Exec plugin executes scripts / applications and reads values back that are printed to STDOUT by that program. This allows you to extend the daemon in an easy and flexible way.

The downside is that executing external programs is very inefficient and always a potential security concern. collectd tries to counter these problems with the following options / mechanism:

It is ensured, that only one instance of the program is executed by collectd at any time. Because executed programs can submit as many values as they want, it is common to let the custom program run in a loop, so that they don't have to be started frequently. Especially with scripts this is a big performance gain, because the interpreter doesn't need to be started over and over again and the script is parsed only once. The required memory for the interpreter to stay in memory is the trade-off though.

Scripts that are implemented like that usually have the following form:

 while sleep $INTERVAL; do
   VALUE=do_magic()
   echo "PUTVAL \"leeloo/exec-magic/gauge-magic_level\" interval=$INTERVAL N:$VALUE"
 done

The security concerns are addressed by forcing the plugin to check that custom programs are never executed with superuser privileges. If the daemon runs as root, you have to configure another user ID with which the new process is created.

This plugin is a generic plugin, i.e. it cannot work without configuration, because there is no reasonable default behavior. Please read the Plugin exec section of the collectd.conf(5) manual page for an in-depth description of the plugin's configuration. Information about the syntax the custom extension scripts must write to STDOUT can be found in the collectd-exec(5) manual page and on the Plain text protocol wiki page.

[edit] Environment

Starting with version 4.9 the Exec plugin sets the COLLECTD_INTERVAL and COLLECTD_HOSTNAME environment variables. The former is set to the global interval setting, the latter to the global hostname.

[edit] Synopsis

<Plugin exec>
  Exec "myuser:mygroup" "myprog"
  Exec "otheruser" "/path/to/another/binary" "arg0" "arg1"
  NotificationExec "user" "/usr/lib/collectd/exec/handle_notification"
</Plugin>

[edit] Example graph

Image:Plugin-exec-temperature-3ware.png

(Data for this graph was collected using the contrib/exec-smartctl script which can be found in contrib/.)

[edit] Example scripts

While the syntax required by the Exec plugin is documented in detail on the Plain text protocol page, example scripts are usually much easier to understand. The following scripts might be of interest for you:

[edit] Dependencies

  • none

[edit] See also