Collectd/Mongo: Difference between revisions
From charlesreid1
No edit summary |
(→Setup) |
||
| Line 8: | Line 8: | ||
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. | 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 <code>/etc/collectd.conf</code> | |||
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 <code><Plugin></code>. | |||
<pre> | |||
<Plugin "write_mongodb"> | |||
<Node "default"> | |||
Host "localhost" | |||
Port "27017" | |||
Timeout 2000 | |||
StoreRates true | |||
</Node> | |||
</Plugin> | |||
This registers a new writer called <code>write_mongodb/localhost</code> | |||
===Logging=== | |||
To turn on logging (to see what's going on if the plugin is not working), | |||
<pre> | |||
<Plugin logfile> | |||
LogLevel "info" | |||
File "/var/log/collectd.log" | |||
Timestamp true | |||
PrintSeverity false | |||
</Plugin> | |||
</pre> | |||
===Error=== | |||
If you see this error in the log: | |||
<pre> | |||
plugin_load: Could not find plugin "write_mongodb" in /usr/lib/collectd | |||
</pre> | |||
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: | |||
<pre> | |||
/* 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" | |||
] | |||
} | |||
</pre> | |||
==Code== | ==Code== | ||
Revision as of 09:52, 3 February 2018
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 /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 <code>write_mongodb/localhost</code>
===Logging===
To turn on logging (to see what's going on if the plugin is not working),
<pre>
<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://charlesreid1.com:3000/data/collectd-config
Flags
[[Category:2018]