From charlesreid1

Write Mongo Plugin

Link: https://collectd.org/wiki/index.php/Plugin:Write_MongoDB

Setup

Revisiting Collectd, you should have collectd installed via your package manager, or installed from source.

The collectd service runs as a daemon, and it reads from a config file when it starts up, so you control collectd by editing the config file.

Config file

The config file is located in one of these locations:

  • /etc/collectd.conf
  • /etc/collectd/collectd.conf
  • /opt/collectd/etc/collectd.conf

The file is extremely detailed and extensively documented (sometimes this can be worse than no documentation - I mean, who the hell's going to read through a 1,000 line configuration file???). The section we're interested in is the section <Plugin>.


<Plugin "write_mongodb">
  <Node "default">
    Host "localhost"
    Port     "27017"
    Timeout    2000
    StoreRates true
  </Node>
</Plugin>

This registers a new writer called write_mongodb/localhost

Logging

To turn on logging (to see what's going on if the plugin is not working),


<Plugin logfile>
	LogLevel "info"
	File "/var/log/collectd.log"
	Timestamp true
	PrintSeverity false
</Plugin>

Error

If you see this error in the log:

plugin_load: Could not find plugin "write_mongodb" in /usr/lib/collectd

it means you have to compile collectd from SOURCE to include the plugin.

Data Format

Here is the data format that is used by collectd to store its data in MongoDB:


 /* Collection "collectd.${plugin}" = */
 {
   "time": 1330940612.932, /* BSON date (UTC milliseconds) */
   "host": "localhost",    /* string */
   "plugin_instance": "",  /* string */
   "type": "load",         /* string */
   "type_instance": "",    /* string */
   "values": [             /* array of numbers */
     0.42, 0.37, 0.11
   ],
   "dstypes": [            /* array of strings */
     "gauge", "gauge", "gauge"
   ],
   "dsnames": [            /* array of strings */
     "shortterm", "midterm", "longterm"
   ]
 }

Code

Repository for collectd-related config files here: https://git.charlesreid1.com/data/collectd-config


Flags

[[Category:2018]