public IList<CollectableValue> Read()
{
// Check if it is time to reload the metric config
// We need to periodially reload the config in case new instances or new categories are available (e.g. due to cluster move)
if (Util.GetNow() - _lastUpdated >= _reloadInterval)
{
Configure();
}
var metricValueList = new List<CollectableValue>();
foreach (Metric metric in _metrics)
{
try
{
var vals = new List<double>();
foreach (PerformanceCounter ctr in metric.Counters)
{
double val = ctr.NextValue();
val = val * metric.Multiplier;
if (metric.DecimalPlaces >= 0)
val = Math.Round(val, metric.DecimalPlaces);
vals.Add(val);
}
var metricValue = new MetricValue
{
HostName = _hostName,
PluginName = metric.CollectdPlugin,
PluginInstanceName = metric.CollectdPluginInstance,
TypeName = metric.CollectdType,
TypeInstanceName = metric.CollectdTypeInstance,
Values = vals.ToArray(),
FriendlyNames = metric.FriendlyNames
};
metricValue.Epoch = Util.toEpoch(DateTime.UtcNow);
metricValueList.Add(metricValue);
}
catch (Exception ex)
{
Logger.Warn(string.Format("Failed to collect metric: {0}, {1}, {2}", metric.Category, metric.Instance, metric.CounterName), ex);
}
}
return (metricValueList);
}