Skip to content

Commit

Permalink
Added option DecimalPlaces parameter to windows performance counter p…
Browse files Browse the repository at this point in the history
…lugin to optionally round values. Also replaced ScaleUpFactor(uint) and ScaleDownFactor(uint) with single Multiplier(double) parameter
  • Loading branch information
andrewpaine committed Jul 22, 2015
1 parent 6fb90cc commit 918eea4
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 34 deletions.
18 changes: 9 additions & 9 deletions src/CollectdWinService/MetricsConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -306,19 +306,19 @@ public string CollectdTypeInstance
set { base["CollectdTypeInstance"] = value; }
}

[ConfigurationProperty("ScaleUpFactor", IsRequired = false)]
public uint ScaleUpFactor
[ConfigurationProperty("Multiplier", IsRequired = false, DefaultValue=1.0)]
public double Multiplier
{
get { return (uint) base["ScaleUpFactor"]; }
set { base["ScaleUpFactor"] = value; }
get { return (double)base["Multiplier"]; }
set { base["Multiplier"] = value; }
}

[ConfigurationProperty("ScaleDownFactor", IsRequired = false)]
public uint ScaleDownFactor
[ConfigurationProperty("DecimalPlaces", IsRequired = false, DefaultValue = -1)]
public int DecimalPlaces
{
get { return (uint) base["ScaleDownFactor"]; }
set { base["ScaleDownFactor"] = value; }
}
get { return (int)base["DecimalPlaces"]; }
set { base["DecimalPlaces"] = value; }
}
}

public class CounterConfigCollection : ConfigurationElementCollection
Expand Down
39 changes: 16 additions & 23 deletions src/CollectdWinService/WindowsPerformanceCounterPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ internal struct Metric
public string CounterName;
public IList<PerformanceCounter> Counters;
public string Instance;
public uint ScaleDownFactor;
public uint ScaleUpFactor;
public double Multiplier;
public int DecimalPlaces;
public string[] FriendlyNames;
}

Expand Down Expand Up @@ -49,8 +49,8 @@ public void Configure()
{
// Instance not specified
AddPerformanceCounter(counter.Category, counter.Name,
counter.Instance, counter.ScaleUpFactor,
counter.ScaleDownFactor, counter.CollectdPlugin,
counter.Instance, counter.Multiplier,
counter.DecimalPlaces, counter.CollectdPlugin,
counter.CollectdPluginInstance, counter.CollectdType,
counter.CollectdTypeInstance);
}
Expand Down Expand Up @@ -106,8 +106,8 @@ public void Configure()

// Replace collectd_plugin_instance with the Instance got from counter
AddPerformanceCounter(counter.Category, counter.Name,
instance, counter.ScaleUpFactor,
counter.ScaleDownFactor, counter.CollectdPlugin,
instance, counter.Multiplier,
counter.DecimalPlaces, counter.CollectdPlugin,
instanceAlias, counter.CollectdType,
counter.CollectdTypeInstance);
}
Expand Down Expand Up @@ -137,17 +137,10 @@ public IList<CollectableValue> Read()
foreach (PerformanceCounter ctr in metric.Counters)
{
double val = ctr.NextValue();
if (metric.ScaleUpFactor > 0)
{
val = val * metric.ScaleUpFactor;
}
else
{
if (metric.ScaleDownFactor > 0)
{
val = val / metric.ScaleDownFactor;
}
}
val = val * metric.Multiplier;

if (metric.DecimalPlaces >= 0)
val = Math.Round(val, metric.DecimalPlaces);
vals.Add(val);
}

Expand Down Expand Up @@ -177,15 +170,15 @@ public IList<CollectableValue> Read()
return (metricValueList);
}

private void AddPerformanceCounter(string category, string names, string instance, uint scaleUpFactor,
uint scaleDownFactor, string collectdPlugin, string collectdPluginInstance, string collectdType,
private void AddPerformanceCounter(string category, string names, string instance, double multiplier,
int decimalPlaces, string collectdPlugin, string collectdPluginInstance, string collectdType,
string collectdTypeInstance)
{
string logstr =
string.Format(new FixedLengthFormatter(),
"Category={0} Counter={1} Instance={2} CollectdPlugin={3} CollectdPluginInstance={4} CollectdType={5} CollectdTypeInstance={6} ScaleUpFactor={7} ScaleDownFactor={8}",
"Category={0} Counter={1} Instance={2} CollectdPlugin={3} CollectdPluginInstance={4} CollectdType={5} CollectdTypeInstance={6} Multiplier={7} DecimalPlaces={8}",
category, names, instance, collectdPlugin, collectdPluginInstance,
collectdType, collectdTypeInstance, scaleUpFactor, scaleDownFactor);
collectdType, collectdTypeInstance, multiplier, decimalPlaces);

try
{
Expand All @@ -206,8 +199,8 @@ private void AddPerformanceCounter(string category, string names, string instanc
metric.Category = category;
metric.Instance = instance;
metric.CounterName = names;
metric.ScaleUpFactor = scaleUpFactor;
metric.ScaleDownFactor = scaleDownFactor;
metric.Multiplier = multiplier;
metric.DecimalPlaces = decimalPlaces;
metric.CollectdPlugin = collectdPlugin;
metric.CollectdPluginInstance = collectdPluginInstance;
metric.CollectdType = collectdType;
Expand Down
4 changes: 2 additions & 2 deletions src/CollectdWinService/app.config
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,10 @@
<Counter Category="LogicalDisk" Name="% Free Space" Instance=".*" CollectdPlugin="logical_disk"
CollectdPluginInstance="" CollectdType="percent" CollectdTypeInstance="percent_free" />

<Counter Category="LogicalDisk" Name="Free Megabytes" Instance=".*" ScaleUpFactor="1048576" CollectdPlugin="logical_disk"
<Counter Category="LogicalDisk" Name="Free Megabytes" Instance=".*" Multiplier="1048576" CollectdPlugin="logical_disk"
CollectdPluginInstance="" CollectdType="bytes" CollectdTypeInstance="bytes_free" />

<Counter Category="LogicalDisk" Name="Avg. Disk Queue Length" Instance=".*" ScaleUpFactor="1048576" CollectdPlugin="logical_disk"
<Counter Category="LogicalDisk" Name="Avg. Disk Queue Length" Instance=".*" Multiplier="1048576" CollectdPlugin="logical_disk"
CollectdPluginInstance="" CollectdType="count" CollectdTypeInstance="avg_queue_length" />

<!-- Network Interface -->
Expand Down

0 comments on commit 918eea4

Please sign in to comment.