Beispiel #1
0
 public StatPoint[] Collect()
 {
     return(_performanceCounter
            .GetValues()
            .Select(value => new StatPoint
     {
         NodeRef = _nodeRefCreator.CreateFromInstanceName(value.InstanceName),
         Time = DateTimeOffset.UtcNow,
         Value = value.Value,
         StatType = _statType
     })
            .ToArray());
 }
Beispiel #2
0
 //possible return null if can't find site with that binds
 public StatPoint ConvertPoint(Message item)
 {
     item.Domain   = item.Domain.ReplaceIfLocalhostOrIp().EraseSlash();
     item.Segment2 = item.Segment2.EraseSlash();
     if (SiteNameSearch(item, out string siteName) && TryFindStatType(item, out string statType))
     {
         return(new StatPoint
         {
             NodeRef = _nodeRefCreator.CreateFromInstanceName(siteName),
             StatType = statType,
             Time = item.DateTime,
             Value = 1,
         });
     }
     else
     {
         return(null);
     }
 }
        public StatPoint[] Collect()
        {
            if (_category == null)
            {
                return(new StatPoint[0]);
            }

            using (var counter = new PerformanceCounter(_category.CategoryName, _counterName))
            {
                return(new StatPoint[]
                {
                    new StatPoint
                    {
                        NodeRef = _nodeRefCreator.CreateFromInstanceName(null),
                        StatType = _statType,
                        Time = DateTimeOffset.UtcNow,
                        Value = counter.NextValue(),
                    }
                });
            }
        }
Beispiel #4
0
 public StatPoint[] Collect()
 {
     if (_category == null)
     {
         return(new StatPoint[0]);
     }
     PerformanceCounter[] counters;
     try
     {
         counters = _category.GetInstanceNames()
                    .Select(instanceName => new PerformanceCounter(_category.CategoryName, _counterName, instanceName))
                    .ToArray();
     }
     catch (InvalidOperationException e)
     {
         throw new MyExceptions.InstanceNotFoundException(_category.CategoryName, _counterName, e);
     }
     try
     {
         return(counters
                .Select(c => new StatPoint
         {
             NodeRef = _nodeRefCreator.CreateFromInstanceName(c.InstanceName),
             StatType = _statType,
             Time = DateTimeOffset.UtcNow,
             Value = c.NextValue(),
         })
                .ToArray());
     }
     finally
     {
         foreach (var counter in counters)
         {
             counter.Dispose();
         }
     }
 }