public void Increment(CountMetric countMetric)
 {
     foreach (IMetricLogger currentLogger in loggerList)
     {
         currentLogger.Increment(countMetric);
     }
 }
Example #2
0
 //------------------------------------------------------------------------------
 //
 // Method: LogCountMetricTotal
 //
 //------------------------------------------------------------------------------
 /// <summary>
 /// Logs the total of a count metric to a performance counter.
 /// </summary>
 /// <param name="countMetric">The count metric to log.</param>
 /// <param name="value">The total.</param>
 protected override void LogCountMetricTotal(CountMetric countMetric, long value)
 {
     if (registeredMetricsPerformanceCounters.ContainsKey(countMetric.Name) == true)
     {
         registeredMetricsPerformanceCounters[countMetric.Name].RawValue = value;
     }
 }
 /// <include file='InterfaceDocumentationComments.xml' path='doc/members/member[@name="M:ApplicationMetrics.IMetricLogger.Increment(ApplicationMetrics.CountMetric)"]/*'/>
 public void Increment(CountMetric countMetric)
 {
     lock (countMetricEventQueueLock)
     {
         countMetricEventQueue.Enqueue(new CountMetricEventInstance(countMetric, dateTime.UtcNow));
         bufferProcessingStrategy.NotifyCountMetricEventBuffered();
     }
 }
Example #4
0
 /// <include file='InterfaceDocumentationComments.xml' path='doc/members/member[@name="M:ApplicationMetrics.IMetricAggregateLogger.DefineMetricAggregate(ApplicationMetrics.IntervalMetric,ApplicationMetrics.CountMetric,System.String,System.String)"]/*'/>
 public override void DefineMetricAggregate(IntervalMetric intervalMetric, CountMetric countMetric, string name, string description)
 {
     ValidateMetricAggregateName(name, performanceCounterAggregateInstantaneousPostFix + performanceCounterAggregateBasePostFix);
     base.DefineMetricAggregate(intervalMetric, countMetric, name, description);
     RegisterPerformanceCounter(name);
     RegisterPerformanceCounter(CounterNameAppendInstantaneous(name));
     RegisterPerformanceCounter(CounterNameAppendInstantaneousBase(name));
 }
Example #5
0
 /// <include file='InterfaceDocumentationComments.xml' path='doc/members/member[@name="M:ApplicationMetrics.IMetricAggregateLogger.DefineMetricAggregate(ApplicationMetrics.CountMetric,ApplicationMetrics.TimeUnit,System.String,System.String)"]/*'/>
 public override void DefineMetricAggregate(CountMetric countMetric, TimeUnit timeUnit, string name, string description)
 {
     ValidateMetricAggregateName(name, performanceCounterAggregateInstantaneousPostFix + performanceCounterAggregateBasePostFix);
     base.DefineMetricAggregate(countMetric, timeUnit, name, description);
     RegisterPerformanceCounter(name);
     RegisterPerformanceCounter(CounterNameAppendInstantaneous(name));
     // If the time unit of the aggregate is not second, the instantaneous counter is of type AverageCount64 which requires a base counter...
     if (timeUnit != TimeUnit.Second)
     {
         RegisterPerformanceCounter(CounterNameAppendInstantaneousBase(name));
     }
 }
        private static async Task SendMetricForOverallAppHealth(ILogger log,
                                                                HealthReport healthReport,
                                                                string metricAppPrefix,
                                                                string metricTags,
                                                                long posixTimeStamp)
        {
            var appHealthMetricCount =
                healthReport.Status == HealthStatus.Healthy ? 1 : 2;
            CountMetric countMetric1 = new CountMetric(
                metricName: $"{metricAppPrefix}.app.ishealthy",
                posixTimeStamp: posixTimeStamp,
                count: appHealthMetricCount,
                tags: metricTags);

            await SendMetric(log, countMetric1);
        }
        private static async Task SendMetric(ILogger log, CountMetric countMetric)
        {
            var ddApiKey = Environment.GetEnvironmentVariable("DD_API_KEY");
            var ddAppKey = Environment.GetEnvironmentVariable("DD_APP_KEY");

            var json        = JsonConvert.SerializeObject(countMetric, Formatting.Indented);
            var jsonContent = new StringContent(json,
                                                Encoding.UTF8, "application/json");

            log.LogInformation($"JSON was {json}");

            var ddResponse = await dataDogMetricSubmitter.PostAsync(
                $"/api/v1/series?api_key={ddApiKey}&application_key={ddAppKey}",
                jsonContent);

            ddResponse.EnsureSuccessStatusCode();
            var ddResponseContent = await ddResponse.Content.ReadAsStringAsync();

            log.LogInformation($"DD returned {ddResponseContent}");
        }
        private static async Task SendMetricForComponentHealth(ILogger log,
                                                               string metricAppPrefix,
                                                               string metricTags,
                                                               long posixTimeStamp,
                                                               KeyValuePair <string, HealthReportEntry> item)
        {
            int metricCount = item.Value.Status == HealthStatus.Healthy ? 1 : 2;

            log.LogInformation($"Health test :{item.Key}, " +
                               $"health: {(metricCount == 1 ? "healthy" : "unhealthy")}");

            CountMetric countMetric = new CountMetric(
                metricName: $"{metricAppPrefix}.app." +
                $"{item.Key.ToLower().Replace(" ", "_")}.ishealthy",
                posixTimeStamp: posixTimeStamp,
                count: metricCount,
                tags: metricTags);

            await SendMetric(log, countMetric);
        }
Example #9
0
 //------------------------------------------------------------------------------
 //
 // Method: LogCountMetricTotal
 //
 //------------------------------------------------------------------------------
 /// <summary>
 /// Logs the total of a count metric to the console.
 /// </summary>
 /// <param name="countMetric">The count metric to log.</param>
 /// <param name="value">The total.</param>
 protected override void LogCountMetricTotal(CountMetric countMetric, long value)
 {
     console.WriteLine(countMetric.Name + separatorString + value.ToString());
 }
Example #10
0
 //------------------------------------------------------------------------------
 //
 // Method: CountMetricTotalContainer (constructor)
 //
 //------------------------------------------------------------------------------
 /// <summary>
 /// Initialises a new instance of the ApplicationMetrics.CountMetricTotalContainer class.
 /// </summary>
 /// <param name="countMetric">The count metric for which the total number of instances is stored.</param>
 public CountMetricTotalContainer(CountMetric countMetric)
 {
     this.countMetric = countMetric;
     totalCount       = 0;
 }
 public void Increment(CountMetric countMetric)
 {
     metricLogger.Increment(countMetric);
 }
Example #12
0
 /// <include file='InterfaceDocumentationComments.xml' path='doc/members/member[@name="M:ApplicationMetrics.IMetricAggregateLogger.DefineMetricAggregate(ApplicationMetrics.AmountMetric,ApplicationMetrics.CountMetric,System.String,System.String)"]/*'/>
 public void DefineMetricAggregate(AmountMetric amountMetric, CountMetric countMetric, string name, string description)
 {
     loggerImplementation.DefineMetricAggregate(amountMetric, countMetric, name, description);
 }
Example #13
0
 /// <include file='InterfaceDocumentationComments.xml' path='doc/members/member[@name="M:ApplicationMetrics.IMetricAggregateLogger.DefineMetricAggregate(ApplicationMetrics.IntervalMetric,ApplicationMetrics.CountMetric,System.String,System.String)"]/*'/>
 public void DefineMetricAggregate(IntervalMetric intervalMetric, CountMetric countMetric, string name, string description)
 {
     loggerImplementation.DefineMetricAggregate(intervalMetric, countMetric, name, description);
 }
Example #14
0
 /// <include file='InterfaceDocumentationComments.xml' path='doc/members/member[@name="M:ApplicationMetrics.IMetricLogger.Increment(ApplicationMetrics.CountMetric)"]/*'/>
 public void Increment(CountMetric countMetric)
 {
     loggerImplementation.Increment(countMetric);
 }
Example #15
0
 /// <include file='InterfaceDocumentationComments.xml' path='doc/members/member[@name="M:ApplicationMetrics.IMetricAggregateLogger.DefineMetricAggregate(ApplicationMetrics.CountMetric,ApplicationMetrics.TimeUnit,System.String,System.String)"]/*'/>
 public void DefineMetricAggregate(CountMetric countMetric, TimeUnit timeUnit, string name, string description)
 {
     loggerImplementation.DefineMetricAggregate(countMetric, timeUnit, name, description);
 }
Example #16
0
 /// <include file='InterfaceDocumentationComments.xml' path='doc/members/member[@name="M:ApplicationMetrics.IMetricLogger.Increment(ApplicationMetrics.CountMetric)"]/*'/>
 public void Increment(CountMetric countMetric)
 {
 }
 //------------------------------------------------------------------------------
 //
 // Method: LogCountMetricTotal
 //
 //------------------------------------------------------------------------------
 /// <summary>
 /// Logs the total number of occurrences of a count metric.
 /// </summary>
 /// <param name="countMetric">The count metric.</param>
 /// <param name="value">The total number of occurrences.</param>
 protected abstract void LogCountMetricTotal(CountMetric countMetric, long value);
 /// <include file='InterfaceDocumentationComments.xml' path='doc/members/member[@name="M:ApplicationMetrics.IMetricAggregateLogger.DefineMetricAggregate(ApplicationMetrics.CountMetric,ApplicationMetrics.TimeUnit,System.String,System.String)"]/*'/>
 public virtual void DefineMetricAggregate(CountMetric countMetric, TimeUnit timeUnit, string name, string description)
 {
     CheckDuplicateAggregateName(name);
     countOverTimeUnitAggregateDefinitions.Add(new MetricAggregateContainer <CountMetric>(countMetric, timeUnit, name, description));
 }
 /// <include file='InterfaceDocumentationComments.xml' path='doc/members/member[@name="M:ApplicationMetrics.IMetricAggregateLogger.DefineMetricAggregate(ApplicationMetrics.AmountMetric,ApplicationMetrics.CountMetric,System.String,System.String)"]/*'/>
 public virtual void DefineMetricAggregate(AmountMetric amountMetric, CountMetric countMetric, string name, string description)
 {
     CheckDuplicateAggregateName(name);
     amountOverCountAggregateDefinitions.Add(new MetricAggregateContainer <AmountMetric, CountMetric>(amountMetric, countMetric, name, description));
 }
 /// <include file='InterfaceDocumentationComments.xml' path='doc/members/member[@name="M:ApplicationMetrics.IMetricAggregateLogger.DefineMetricAggregate(ApplicationMetrics.IntervalMetric,ApplicationMetrics.CountMetric,System.String,System.String)"]/*'/>
 public virtual void DefineMetricAggregate(IntervalMetric intervalMetric, CountMetric countMetric, string name, string description)
 {
     CheckDuplicateAggregateName(name);
     intervalOverAmountAggregateDefinitions.Add(new MetricAggregateContainer <IntervalMetric, CountMetric>(intervalMetric, countMetric, name, description));
 }