poxet / Influx-Capacitor

Influx-capacitor collects metrics from windows machines using Performance Counters. Data is sent to influxDB to be viewable by grafana.
http://influx-capacitor.com
MIT License
44 stars 13 forks source link

Add the ability to rename/filter instances #41

Closed tbolon closed 8 years ago

tbolon commented 8 years ago

Before using InfluxDB I was using graphite, and a powershell script to send data to graphite.

One of the useful feature this tool has was the ability to rename and filter counters based on regular expressions.

See an example in StatsToGraphite.xml, in elements <MetricsCleaning> and <Filtering>

I am facing a problem that requires the kind of same functionality on capacitor.

The problem arise when collecting IIS and ASP.NET counters, in categories W3SVC_W3WP and WAS_W3WP: the instance name is composed of the pid and the application pool name (see this doc). So instances names varies when processes are started/recycled. So, it is impossible to filter by instance name, and we can not send this instance name as a tag, because the value will change too often.

Basically two features are needed:

My idea for now is:

Add a new <InstanceFilters> element under <CounterGroup>. Within this element, you can add multiple <Filter> element. Each <Filter> must define a Pattern attribute with a regular expression, and an optional Replacement pattern.

During counter reading, each filter is applied to the instances returned by the performance counter.

If an instance name is null after the filters pass, the counter is ignored. Otherwise, the value is read and the process continue. The new instance name is used when sending the value to the collector.

Configuration example:

<InstanceFilters>
  <!-- this filter will exclude all instance names where ".NET" is not present in the instance name -->
  <Filter Pattern="\.NET" />
  <!-- this filter will remove all pids from instance names for IIS apps. "1879_.NET v4.5" => ".NET v4.5" -->
  <Filter Pattern="^\d+_(.*)$" Replacement="$1" />
  <!-- this filter will replace ".NET v4.5" by "net45" -->
  <Filter Pattern="\.NET v4\.5" Replacement="net45" />
</InstanceFilters>

Possible enhancements:

Do you think this feature could fit the project ? I have some prototype already, but I prefer to be sure that I am not missing anything or that I am going in the right direction.

nathanwebb commented 8 years ago

This feature seems like a good idea, and might be good for cleaning unusual instance names, but I wouldn't use it in the use-case that you identified.

In this specific use-case, what would happen if you have multiple processes in the same apppool? For example, you have multiple instances like:

1879.NET v4.5 1921.NET v4.5 1922_.NET v4.5

When the data is collected, they will all be sent as the same series in Influxdb, so you will get the last-arriving value overwriting the first one. The last value could be any of the three as well. That's definitely not what you want! The correct approach would be to collect all values, and then sum/average them in Influxdb, using a continuous query.

tbolon commented 8 years ago

You are right. Even if duplicates instances is often only a transition state (when app pools are recycled), I prefer not to miss them. Perhaps some code could make instances names unique again after filters have been processed, adding a counter suffix when necessary.

tbolon commented 8 years ago

I am still working on this. Nothing to share yet, but still on tracks :)