collectd: gather application-specific data

With collectd, system data like load or memory-usage can be easily monitored in distributed systems. Using the network plugin this data is sent to a central server where it can be processed.

Sometimes it is necessary to gather application-specific data. In CurrySearch for example the current number of tenants or the number of search requests per tenant are important metrics.

To gather this data, collectd supports the possibility to push values to a socket. For that, the socket-plugin has to be configured:

LoadPlugin unixsock

<Plugin unixsock>
	SocketFile "/var/lib/currysearch/stats.sock"
	SocketGroup "curryadm"
	SocketPerms "0770"
	DeleteSocket false

Now we can push our current data to the socket in regular intervals. You can find the documentation of the communication protocol here.

In rust, this could look like this:

fn update_stats(&self) -> Result<()> {
    use std::os::unix::net::UnixStream;

    // Connect to the socket
    let mut stream = UnixStream::connect("/var/lib/currysearch/stats.sock").unwrap();

    // Push values (N stands for Now, count is a predefined value type)
    writeln!(&mut stream, "PUTVAL currysearch/active_tenants/count N:{}", self.tenant_count).unwrap();

    // Read the response
    let mut response = String::new();
    let mut reader = BufReader::new(stream);
    reader.read_line(&mut response).unwrap();

    // And check for success
    assert!(response.starts_with("0 Success"));


Call this code in a loop … done.

Predefined value-typed can be found in the types.db. If you want to define custom types be aware, that they have to be identical for any collectd-client and server configuration.