public void RunReport(MetricsData metricsData, Func<HealthStatus> healthStatus, CancellationToken token)
 {
     using (log.Timing("Report of metrics data to Google Analytics"))
     {
         tracker.Track(metricsData.AsGoogleAnalytics(), token).Wait(token);
     }
 }
 public static IEnumerable<Google.ICanReportToGoogleAnalytics> Map(MetricsData metricData)
 {
     using (log.Timing("Map Metrics.NET Data to Google Analytics Reports"))
     {
         return Map(metricData, null);
     }
 }
Exemplo n.º 3
0
        public static void VerifyRollBackCount(string queueName, MetricsData data, long messageCount, int rollbackCount, int failedCount)
        {
            var found = false;
            const string name = "RollbackMessage.RollbackCounter";
            const string retryName = "MessageFailedProcessingRetryMeter";
            foreach (var metric in data.Counters.Where(counter => counter.Name.EndsWith(name, StringComparison.InvariantCultureIgnoreCase)))
            {
                Assert.Equal(messageCount * rollbackCount, metric.Value.Count);
                found = true;
                break;
            }
            if (!found)
            {
                throw new DotNetWorkQueueException($"Failed to find metric {name}");
            }

            if (failedCount > 0)
            {
                found = false;
                foreach (
                    var metric in
                        data.Meters.Where(
                            counter => counter.Name.EndsWith(retryName, StringComparison.InvariantCultureIgnoreCase)))
                {
                    Assert.Equal(messageCount*failedCount, metric.Value.Count);
                    found = true;
                    break;
                }
                if (!found)
                {
                    throw new DotNetWorkQueueException($"Failed to find metric {name}");
                }
            }
        }
Exemplo n.º 4
0
        public static string BuildJson(MetricsData data, IEnumerable<EnvironmentEntry> environment, Clock clock, bool indented = DefaultIndented)
        {
            var version = Version.ToString(CultureInfo.InvariantCulture);

            return JsonMetricsContext.FromContext(data, environment, version)
                .ToJsonObject()
                .AsJson(indented);
        }
 private static IEnumerable<Google.ICanReportToGoogleAnalytics> Map(MetricsData metricData, string context)
 {
     return Map(metricData.Counters, context)
         .Concat(Map(metricData.Gauges, context))
         .Concat(Map(metricData.Histograms, context))
         .Concat(Map(metricData.Meters, context))
         .Concat(Map(metricData.Timers, context))
         .Union(metricData.ChildMetrics.SelectMany(m => Map(m, m.Context)));
 }
        public void RunReport(MetricsData metricsData, Func<HealthStatus> healthStatus, CancellationToken token)
        {
            foreach (var timer in metricsData.Timers)
            {
                var timerValue = timer.ValueProvider.GetValue(resetMetric: true);

                Console.WriteLine("{0} : {1} {2} {3}", timer.Name, timerValue.Rate.Count, timerValue.Histogram.Count, timerValue.Histogram.Percentile75);
            }
        }
Exemplo n.º 7
0
        public static string BuildJson(MetricsData data, Clock clock, bool indented = DefaultIndented)
        {
            var flatData = data.OldFormat();

            return new JsonBuilderV1()
                .AddVersion(Version)
                .AddTimestamp(Clock.Default)
                .AddEnvironment()
                .AddObject(flatData.Gauges)
                .AddObject(flatData.Counters)
                .AddObject(flatData.Meters)
                .AddObject(flatData.Histograms)
                .AddObject(flatData.Timers)
                .GetJson(indented);
        }
Exemplo n.º 8
0
 public static JsonMetricsContext FromContext(MetricsData contextData, IEnumerable<EnvironmentEntry> environment, string version)
 {
     return new JsonMetricsContext
     {
         Version = version,
         Timestamp = contextData.Timestamp,
         Environment = contextData.Environment.Union(environment).ToDictionary(e => e.Name, e => e.Value),
         Context = contextData.Context,
         Gauges = contextData.Gauges.Select(JsonGauge.FromGauge).ToArray(),
         Counters = contextData.Counters.Select(JsonCounter.FromCounter).ToArray(),
         Meters = contextData.Meters.Select(JsonMeter.FromMeter).ToArray(),
         Histograms = contextData.Histograms.Select(JsonHistogram.FromHistogram).ToArray(),
         Timers = contextData.Timers.Select(JsonTimer.FromTimer).ToArray(),
         ChildContexts = contextData.ChildMetrics.Select(FromContext).ToArray()
     };
 }
Exemplo n.º 9
0
 public static long GetExpiredMessageCount(MetricsData data)
 {
     var names = new List<string>(2) { ".ClearMessages.ResetCounter", ".Handle.Expired" };
     long count = 0;
     foreach (var name in names)
     {
         foreach (
             var metric in
                 data.Counters.Where(
                     counter => counter.Name.EndsWith(name, StringComparison.InvariantCultureIgnoreCase)))
         {
             count = count + metric.Value.Count;
             break;
         }
     }
     return count;
 }
Exemplo n.º 10
0
 public static long GetPoisonMessageCount(MetricsData data)
 {
     var names = new List<string>(1) { "PoisonHandleMeter" };
     long count = 0;
     foreach (var name in names)
     {
         foreach (
             var metric in
                 data.Meters.Where(
                     counter => counter.Name.EndsWith(name, StringComparison.InvariantCultureIgnoreCase)))
         {
             count = count + metric.Value.Count;
             break;
         }
     }
     return count;
 }
        private async Task UpdateMetrics(Uri remoteUri, Func<string, JsonMetricsContext> deserializer, CancellationToken token)
        {
            try
            {
                var remoteContext = await HttpRemoteMetrics.FetchRemoteMetrics(remoteUri, deserializer, token).ConfigureAwait(false);
                remoteContext.Environment.Add("RemoteUri", remoteUri.ToString());
                remoteContext.Environment.Add("RemoteVersion", remoteContext.Version);
                remoteContext.Environment.Add("RemoteTimestamp", Clock.FormatTimestamp(remoteContext.Timestamp));

                this.currentData = remoteContext.ToMetricsData();
            }
            catch (Exception x)
            {
                MetricsErrorHandler.Handle(x, "Error updating metrics data from " + remoteUri);
                this.currentData = MetricsData.Empty;
            }
        }
Exemplo n.º 12
0
 public static void VerifyProducedAsyncCount(string queueName, MetricsData data, long messageCount)
 {
     var found = false;
     var name = "SendMessagesMeter";
     foreach (var meter in data.Meters.Where(timer => timer.Name.EndsWith(name, StringComparison.InvariantCultureIgnoreCase)))
     {
         Assert.Equal(messageCount, meter.Value.Count);
         found = true;
         break;
     }
     if (!found)
     {
         throw new DotNetWorkQueueException($"Failed to find timer {name}");
     }
 }
Exemplo n.º 13
0
 public static string RenderMetrics(MetricsData metricsData, Func<HealthStatus> healthStatus)
 {
     var report = new StringReport();
     report.RunReport(metricsData, healthStatus, CancellationToken.None);
     return report.Result;
 }
Exemplo n.º 14
0
 public static JsonMetricsContext FromContext(MetricsData contextData)
 {
     return FromContext(contextData, null);
 }
Exemplo n.º 15
0
 public static JsonMetricsContext FromContext(MetricsData contextData, string version)
 {
     return FromContext(contextData, Enumerable.Empty<EnvironmentEntry>(), version);
 }
Exemplo n.º 16
0
 public static void VerifyProcessedCount(string queueName, MetricsData data, long messageCount)
 {
     var found = false;
     const string name = "CommitMessage.CommitCounter";
     foreach (var counter in data.Counters.Where(counter => counter.Name.EndsWith(name, StringComparison.InvariantCultureIgnoreCase)))
     {
         Assert.Equal(messageCount, counter.Value.Count);
         found = true;
         break;
     }
     if (!found)
     {
         throw new DotNetWorkQueueException($"Failed to find timer {name}");
     }
 }
Exemplo n.º 17
0
 public static void VerifyExpiredMessageCount(string queueName, MetricsData data, long messageCount)
 {
     var count = GetExpiredMessageCount(data);
     Assert.Equal(messageCount, count);
 }
Exemplo n.º 18
0
 public MetricsData(string context, IEnumerable <EnvironmentEntry> environment, MetricsData data, IEnumerable <MetricsData> childMetrics)
     : this(context, environment, data.Gauges, data.Counters, data.Meters, data.Histograms, data.Timers, childMetrics)
 {
 }
Exemplo n.º 19
0
 public static string BuildJson(MetricsData data) { return BuildJson(data, Clock.Default, indented: DefaultIndented); }
Exemplo n.º 20
0
 public static string BuildJson(MetricsData data)
 {
     return BuildJson(data, AppEnvironment.Current, Clock.Default, indented: DefaultIndented);
 }