Exemplo n.º 1
0
        public async Task PublishRegisterCounterValuesAsync()
        {
            try
            {
                _timer.Stop();
                var value = _counterPublisher.GetValue();
                _perfCounter.RawValue = value;

                //Console.WriteLine("{0} read {1} and published to {2}", _counterPublisher.CounterName, value, _perfCounter.CounterName);
                Console.WriteLine("{0} read {1}.", _counterPublisher.CounterName, value);

                //var performanceCounterInfo = performanceCounterInfos[i];

                var categoryName = _counterPublisher.CategoryName;
                var counterName  = _counterPublisher.CounterName;
                //var key = performanceCounterInfo.PerformanceCounter.InstanceName;
                //var instanceAlias = performanceCounterInfo.Alias;
                //var tags = GetTags(_tags.Union(performanceCounterInfo.Tags), categoryName, counterName);
                var tags   = GetTags(_tags, categoryName, counterName);
                var fields = new Dictionary <string, object>
                {
                    { "value", value },
                    //{ "readSpan", readSpan }, //Time in ms from the first, to the lats counter read in the group.
                    //{ "timeOffset", (float)(timeOffset * 1000) } //Time difference in ms from reported time, to when read actually started.
                };

                var point = new Point
                {
                    Name      = _counterPublisher.CounterName,
                    Tags      = tags,
                    Fields    = fields,
                    Precision = TimeUnit.Seconds,
                    Timestamp = DateTime.UtcNow,
                };

                //if (!string.IsNullOrEmpty(key))
                //{
                //    point.Tags.Add("instance", key);
                //    if (!string.IsNullOrEmpty(instanceAlias))
                //    {
                //        point.Tags.Add(instanceAlias, key);
                //    }
                //}

                //TODO: Have a setting to evaluate if this is to be sent directly to Graphana. Of just published as a performance counter.
                _sendBusiness.Enqueue(new[] { point });
            }
            catch (Exception exception)
            {
                OnPublishRegisterCounterValuesEvent(new PublishRegisterCounterValuesEventArgs(_counterPublisher.CounterName, exception));
            }
            finally
            {
                _timer.Start();
            }
        }
 protected void Enqueue(Point[] points)
 {
     _sendBusiness.Enqueue(points);
 }