Skip to content
This repository has been archived by the owner. It is now read-only.

Fix collectd metric processing #3

Merged
merged 3 commits into from Aug 26, 2011
Merged
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

Prev

Improve on @donjohnson's ideas

First, we look at the system installed types.db (works on centos
package, should probably be generalized).

Later, we split up the metric name into is parts according to the
collectd data spec. The instance are split out and handled somewhat
better.

This fixes an issue where type instances will break the lookup in
the types.db file.

This also fixes an issue where metrics will be poorly named when
they appear in graphite.

CAVEAT: This makes changes that are not compatible with existing
proxy users. The graphs will be given different names.

tl:dr This breaks backwards compatability
  • Loading branch information
Corry Haines
Corry Haines committed Aug 26, 2011
commit e64ccd18381de6e822a9225928cdbd3cc9a94d70
@@ -20,7 +20,7 @@ var net = require("net");
var assert = require("assert");
var fs = require('fs');

var types = fs.readFileSync('./types.db', encoding='utf8').split("\n");
var types = fs.readFileSync('/usr/share/collectd/types.db', encoding='utf8').split("\n");

var typesObj = new Object;

@@ -44,7 +44,6 @@ for (var i in types) {
}



try {
var graphite_connection = net.createConnection(2003, host=process.argv[2]);
} catch (error) {
@@ -78,10 +77,52 @@ var request_handler = function(request, response) {
continue;
}

name = "agents." + name.replace(/\./g, "_").replace(/\//g, ".");
// Replace some chars for graphite, split into parts
var name_parts = name.replace(/\./g, "_").replace(/\//g, ".").split(".");

// Start to construct the new name
var rebuild = ["agents"]

var host = name_parts[0].split(/_/)[0]
rebuild = rebuild.concat(host)

// Pluigin names can contain an "instance" which is set apart by a dash
var plugin = name_parts[1].split("-")
rebuild = rebuild.concat(plugin[0])
if (plugin.length > 1) {
var plugin_instance = plugin.slice(1).join("-")
rebuild = rebuild.concat(plugin_instance)
}
plugin = plugin[0]

// Type names can also contain an "instance"
var type = name_parts[2].split("-")
if (type[0] != plugin) {
// If type and plugin are equal, delete one to clean up a bit
rebuild = rebuild.concat(type[0])
}
if (type.length > 1) {
var type_instance = type.slice(1).join("-")
rebuild = rebuild.concat(type_instance)
}
type = type[0]

// Put the name back together
name = rebuild.join(".")

if ( values.length > 2 ) {
var metric = name.split(".")[3];
name = name + "_" + typesObj[metric][v - 1];
var metric = name_parts[2];

// If the metric contains a '-' (after removing the instance name)
// then we want to remove it before looking up in the types.db
index = metric.search(/-/)
if (index > -1) {
metric = /^([\w]+)-(.*)$/.exec(metric);
} else {
// Kinda a hack
metric = [ "", metric]
}
name = name + "." + typesObj[metric[1]][v - 1];
}
message = [name, values[v], time].join(" ");
graphite_connection.write(message + "\n");
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.