Exemplo n.º 1
0
        private MetricRetriever GetMetricRetriever(string category, string names, string instance)
        {
            string logstr =
                string.Format(
                    "Category:{0} - Instance:{1} - counter:{2}",
                    category, instance, names);

            try
            {
                var metricRetriver = new MetricRetriever();
                metricRetriver.Counters = new List <PerformanceCounter>();
                string[] counterList = names.Split(',');
                foreach (string ctr in counterList)
                {
                    metricRetriver.Counters.Add(new PerformanceCounter(category, ctr.Trim(), instance));
                }
                Logger.Info("Added Performance COUNTER : {0}", logstr);
                return(metricRetriver);
            }
            catch (Exception exp)
            {
                Logger.Error("Got exception : {0}, while adding performance counter: {1}", exp, logstr);
                return(null);
            }
        }
Exemplo n.º 2
0
 public override bool Refresh()
 {
     try
     {
         if (MetricRetrievers == null)
         {
             MetricRetrievers = new List <MetricRetriever>();
         }
         if (CounterInstance != null && CounterInstance == "*")
         {
             var      cat       = new PerformanceCounterCategory(CounterCategory);
             string[] instances = cat.GetInstanceNames();
             foreach (string instance in instances)
             {
                 if (!ExistInstance(instance))
                 {
                     MetricRetriever metricRetriver = GetMetricRetriever(CounterCategory, CounterName, instance);
                     if (metricRetriver == null)
                     {
                         return(false);
                     }
                     // Replace collectd_plugin_instance with the Instance got from counter
                     metricRetriver.Instance = instance;
                     MetricRetrievers.Add(metricRetriver);
                 }
             }
         }
         else if (MetricRetrievers.Count == 0)
         {
             MetricRetriever metricRetriver = GetMetricRetriever(CounterCategory, CounterName, CounterInstance);
             if (metricRetriver == null)
             {
                 return(false);
             }
             MetricRetrievers.Add(metricRetriver);
         }
     }
     catch (Exception exp)
     {
         Logger.Error("Got exception : {0} in Refresh(), CounterCategory: {1}, CounterName: {2}, CounterInstance: {3}", exp, CounterCategory, CounterName, CounterInstance);
         return(false);
     }
     return(true);
 }
 private MetricRetriever GetMetricRetriever(string category, string names, string instance)
 {
     string logstr =
         string.Format(
             "Category:{0} - Instance:{1} - counter:{2}",
             category, instance, names);
     try
     {
         var metricRetriver = new MetricRetriever();
         metricRetriver.Counters = new List<PerformanceCounter>();
         string[] counterList = names.Split(',');
         foreach (string ctr in counterList)
             metricRetriver.Counters.Add(new PerformanceCounter(category, ctr.Trim(), instance));
         Logger.Info("Added Performance COUNTER : {0}", logstr);
         return metricRetriver;
     }
     catch (Exception exp)
     {
         Logger.Error("Got exception : {0}, while adding performance counter: {1}", exp, logstr);
         return null;
     }
 }