shawn-sterling / graphios

A program to send nagios perf data to graphite (carbon) / statsd / librato / influxdb
289 stars 100 forks source link

remove_character function for Graphios #96

Open mjs2012 opened 8 years ago

mjs2012 commented 8 years ago

Hello everybody,

first I will say a fantastic and good project.

I have a question for modifying the output from graphios to graphite. I use some nagios instances to check windows and linux server. The perfdata output is sending by graphios to graphite. For templating of user graphs we use Grafana. The datasource of Grafana is the graphite backend. The setup works great.

After the last nagios core update we found out a problem. The perfdata from nagios has now apostrophes in the metrics, for example (CPU metric before Nagios Core Update) 10m.wsp and example '10m'.wsp (CPU metric after Nagios Core Update).

In my opinion, it is not advisable to use apostrophe in metrics or file names (of wsp files). Do you agree? The second problem based on the apostrophes in the metrics and file names is the query definition in Grafana. In my tests I can't choose metrics with apostrophe in the name. Only if I use asterisk in the Grafana query it works for me but is not user-friendly. My idea or question is now, why don't include in graphios a parameter for removing characters (e.g. apostrophe)? Similar to parameter "replacement_character".

At the moment I use a quick and dirty function to solve the problem with the apostrophe in the source code. Here the modifications in graphios_backends.py (first block modification beginning line 342 and second block modification beginning line 428):

    path = "%s%s%s.%s" % (pre, hostname, post, m.LABEL)
    path = re.sub(r"\.$", '', path)  # fix paths that end in dot
    path = re.sub(r"\.\.", '.', path)  # fix paths with double dots
    path = re.sub('\'', '', path) # Remove ' char
    path = self.fix_string(path)
    return path

…………………………..

    for m in metrics:
        path = '%s.%s.%s.%s' % (m.GRAPHITEPREFIX, m.HOSTNAME,
                                m.GRAPHITEPOSTFIX, m.LABEL)
        path = re.sub(r'\.$', '', path)  # fix paths that end in dot
        path = re.sub(r'\.\.', '.', path)  # fix paths with empty values
        path = re.sub('\'', '', path) # Remove ' char
        mtype = self.set_type(m)  # gauge|counter|timer|set
        value = "%s|%s" % (m.VALUE, mtype)  # emit literally this to statsd
        metric_tuple = "%s:%s" % (path, value)
        out_list.append(metric_tuple)

A better and generic solution would be a parameter to remove "not valid" characters from metric names, default could be the apostrophe. Or simply inluding path = re.sub('\'', '', path)" in the graphios source code?!

I think it should also be helpfully in other monitoring environments using the actual Nagios or ICINGA core.

Thanks and best regards Matthias