Esempio n. 1
0
        public async Task <int> CollectAssync(IPerformanceCounterGroup counterGroup, bool metadata)
        {
            var engine = GetCollectorEngine(counterGroup, counterGroup.CollectorEngineType, metadata);

            engine.CollectRegisterCounterValuesEvent += CollectRegisterCounterValuesEvent;
            return(await engine.CollectRegisterCounterValuesAsync());
        }
Esempio n. 2
0
 public async void RunAsync(IPerformanceCounterGroup[] counterGroups)
 {
     foreach (var counterGroup in counterGroups)
     {
         var engine = new CollectorEngine(counterGroup, _sendBusiness, _tagLoader);
         await engine.StartAsync();
         engine.CollectRegisterCounterValuesEvent += CollectRegisterCounterValuesEvent;
     }
 }
Esempio n. 3
0
 private ICollectorEngine GetCollectorEngine(IPerformanceCounterGroup counterGroup, CollectorEngineType collectorEngineType, bool metadata)
 {
     switch (collectorEngineType)
     {
         case CollectorEngineType.Exact:
             return new ExactCollectorEngine(counterGroup, _sendBusiness, _tagLoader, metadata);
         case CollectorEngineType.Safe:
             return new SafeCollectorEngine(counterGroup, _sendBusiness, _tagLoader, metadata);
         default:
             throw new ArgumentOutOfRangeException(string.Format("Unknown collector engine type {0}.", collectorEngineType));
     }            
 }
Esempio n. 4
0
 public CollectorEngine(IPerformanceCounterGroup performanceCounterGroup, ISendBusiness sendBusiness, ITagLoader tagLoader)
 {
     _performanceCounterGroup = performanceCounterGroup;
     _sendBusiness = sendBusiness;
     _tags = tagLoader.GetGlobalTags().Union(_performanceCounterGroup.Tags).ToArray();
     if (performanceCounterGroup.SecondsInterval > 0)
     {
         _timer = new Timer(1000 * performanceCounterGroup.SecondsInterval);
         _timer.Elapsed += Elapsed;
     }
     _name = _performanceCounterGroup.Name;
 }
Esempio n. 5
0
        private ICollectorEngine GetCollectorEngine(IPerformanceCounterGroup counterGroup, CollectorEngineType collectorEngineType, bool metadata)
        {
            switch (collectorEngineType)
            {
            case CollectorEngineType.Exact:
                return(new ExactCollectorEngine(counterGroup, _sendBusiness, _tagLoader, metadata));

            case CollectorEngineType.Safe:
                return(new SafeCollectorEngine(counterGroup, _sendBusiness, _tagLoader, metadata));

            default:
                throw new ArgumentOutOfRangeException(string.Format("Unknown collector engine type {0}.", collectorEngineType));
            }
        }
        protected CollectorEngineBase(IPerformanceCounterGroup performanceCounterGroup, ISendBusiness sendBusiness, ITagLoader tagLoader, bool metadata)
        {
            _engineName = GetType().Name;
            _performanceCounterGroup = performanceCounterGroup;
            _name         = _performanceCounterGroup.Name;
            _sendBusiness = sendBusiness;
            _tags         = tagLoader.GetGlobalTags().Union(_performanceCounterGroup.Tags).ToArray();

            if (performanceCounterGroup.SecondsInterval > 0)
            {
                _timer          = new Timer(1000 * performanceCounterGroup.SecondsInterval);
                _timer.Elapsed += Elapsed;
            }

            _metadata = metadata;
        }
        protected CollectorEngineBase(IPerformanceCounterGroup performanceCounterGroup, ISendBusiness sendBusiness, ITagLoader tagLoader, bool metadata)
        {
            _engineName = GetType().Name;
            _performanceCounterGroup = performanceCounterGroup;
            _name = _performanceCounterGroup.Name;
            _sendBusiness = sendBusiness;
            _tags = tagLoader.GetGlobalTags().Union(_performanceCounterGroup.Tags).ToArray();

            if (performanceCounterGroup.SecondsInterval > 0)
            {
                _timer = new Timer(1000 * performanceCounterGroup.SecondsInterval);
                _timer.Elapsed += Elapsed;
            }

            _metadata = metadata;
        }
 protected void ReadCounterGroup(IPerformanceCounterGroup counterGroup)
 {
     var count = 0;
     foreach (var counter in counterGroup.PerformanceCounterInfos)
     {
         if (counter.PerformanceCounter != null)
         {
             var nextValue = counter.PerformanceCounter.NextValue();
             OutputInformation("{0}.{1}.{2} {3}:\t{4}", counter.PerformanceCounter.CategoryName, counter.PerformanceCounter.CounterName, counter.PerformanceCounter.InstanceName, counter.Name, nextValue);
             count++;
         }
         else
         {
             OutputWarning("Cannot read counter {0}.", counter.Name);
         }
     }
     OutputInformation("{0} counters read.", count);
 }
Esempio n. 9
0
        protected void ReadCounterGroup(IPerformanceCounterGroup counterGroup)
        {
            var count = 0;

            foreach (var counter in counterGroup.GetFreshCounters())
            {
                if (counter.HasPerformanceCounter)
                {
                    var nextValue = counter.NextValue();
                    OutputInformation("{0}.{1}.{2} {3}:\t{4}", counter.CategoryName, counter.CounterName, counter.InstanceName, counter.Name, nextValue);
                    count++;
                }
                else
                {
                    OutputWarning("Cannot read counter {0}.", counter.Name);
                }
            }

            OutputInformation("{0} counters read.", count);
        }
Esempio n. 10
0
        public async Task RunAsync(IPerformanceCounterGroup[] counterGroups, ICounterPublisher[] counterPublishers, bool metadata)
        {
            if (counterGroups != null)
            {
                foreach (var counterGroup in counterGroups)
                {
                    var engine = GetCollectorEngine(counterGroup, counterGroup.CollectorEngineType, metadata);
                    engine.CollectRegisterCounterValuesEvent += CollectRegisterCounterValuesEvent;
                    await engine.StartAsync();
                }
            }

            if (counterPublishers != null)
            {
                foreach (var counterPublisher in counterPublishers)
                {
                    var engine = GetPublisherEngine(counterPublisher);
                    engine.PublishRegisterCounterValuesEvent += PublishRegisterCounterValuesEvent;
                    await engine.StartAsync();
                }
            }
        }
Esempio n. 11
0
 public SafeCollectorEngine(IPerformanceCounterGroup performanceCounterGroup, ISendBusiness sendBusiness, ITagLoader tagLoader, bool metadata)
     : base(performanceCounterGroup, sendBusiness, tagLoader, metadata)
 {
 }
 public SafeCollectorEngine(IPerformanceCounterGroup performanceCounterGroup, ISendBusiness sendBusiness, ITagLoader tagLoader, bool metadata)
     : base(performanceCounterGroup, sendBusiness, tagLoader, metadata)
 {
 }
Esempio n. 13
0
 public async Task<int> CollectAssync(IPerformanceCounterGroup counterGroup, bool metadata)
 {
     var engine = GetCollectorEngine(counterGroup, counterGroup.CollectorEngineType, metadata);
     engine.CollectRegisterCounterValuesEvent += CollectRegisterCounterValuesEvent;
     return await engine.CollectRegisterCounterValuesAsync();
 }
Esempio n. 14
0
 public async Task<int> CollectAssync(IPerformanceCounterGroup counterGroup)
 {
     var engine = new CollectorEngine(counterGroup, _sendBusiness, _tagLoader);
     engine.CollectRegisterCounterValuesEvent += CollectRegisterCounterValuesEvent;
     return await engine.CollectRegisterCounterValuesAsync();
 }
Esempio n. 15
0
 public ExactCollectorEngine(IPerformanceCounterGroup performanceCounterGroup, ISendBusiness sendBusiness, ITagLoader tagLoader, bool metadata)
     : base(performanceCounterGroup, sendBusiness, tagLoader, metadata)
 {
     _metaDataBusiness = new MetaDataBusiness();
 }