/// <summary> /// Add the <see cref="GraphiteReporter" /> allowing metrics to be reported to Graphite. /// </summary> /// <param name="metricReporterProviderBuilder"> /// The <see cref="IMetricsReportingBuilder" /> used to configure metrics reporters. /// </param> /// <param name="url">The base url where metrics are written.</param> /// <param name="flushInterval"> /// The <see cref="T:System.TimeSpan" /> interval used if intended to schedule metrics /// reporting. /// </param> /// <param name="fieldsSetup">The metric fields to report as well as thier names.</param> /// <param name="optionsSetup">The setup action to configure the <see cref="MetricsGraphitePlainTextProtocolOptions"/> to use.</param> /// <returns> /// An <see cref="IMetricsBuilder" /> that can be used to further configure App Metrics. /// </returns> public static IMetricsBuilder ToGraphite( this IMetricsReportingBuilder metricReporterProviderBuilder, string url, TimeSpan flushInterval, Action <MetricFields> fieldsSetup = null, Action <MetricsGraphitePlainTextProtocolOptions> optionsSetup = null) { if (metricReporterProviderBuilder == null) { throw new ArgumentNullException(nameof(metricReporterProviderBuilder)); } if (url == null) { throw new ArgumentNullException(nameof(url)); } if (!Uri.TryCreate(url, UriKind.Absolute, out var uri)) { throw new InvalidOperationException($"{nameof(url)} must be a valid absolute URI"); } var plainTextProtocolOptions = new MetricsGraphitePlainTextProtocolOptions(); optionsSetup?.Invoke(plainTextProtocolOptions); IMetricsOutputFormatter formatter; var defaultFields = new MetricFields(); defaultFields.DefaultGraphiteMetricFieldNames(); if (fieldsSetup == null) { formatter = new MetricsGraphitePlainTextProtocolOutputFormatter(plainTextProtocolOptions, defaultFields); } else { fieldsSetup.Invoke(defaultFields); formatter = new MetricsGraphitePlainTextProtocolOutputFormatter(plainTextProtocolOptions, defaultFields); } var options = new MetricsReportingGraphiteOptions { FlushInterval = flushInterval, Graphite = { BaseUri = uri }, MetricsOutputFormatter = formatter }; var httpClient = CreateClient(options, options.ClientPolicy); var reporter = new GraphiteReporter(options, httpClient); var builder = metricReporterProviderBuilder.Using(reporter); builder.OutputMetrics.AsGraphitePlainTextProtocol(plainTextProtocolOptions, defaultFields); return(builder); }
public void WhenAddCounter_ThenSuccess() { using (var sut = new GraphiteReporter(new IntegrationEncompassConfig())) { sut.AddCounter("my-metric", 10); } }
static void Main(string[] args) { var db1Metrics = new MetricRegistry(); var reporter = ConsoleReporter.ForRegistry(db1Metrics).build(); var meter = db1Metrics.Meter("testMeter"); var randomHist = db1Metrics.Histogram("testHist"); //var machineMetrics = MachineMetrics.Create(MachineMetricsCategory.All); //db1Metrics.Register("MachineMetrics", machineMetrics); //reporter.Start(1, TimeUnit.Seconds); CsvReporter creporter = CsvReporter.forRegistry(db1Metrics).build("c:\\merchlog"); //creporter.Start(1, TimeUnit.Seconds); Graphite sender = new Graphite("ttolley-lap3", 2003); GraphiteReporter greporter = GraphiteReporter.ForRegistry(db1Metrics).Build(sender); greporter.Start(10, TimeUnit.Seconds); //var docsTimedCounterPerSec = db1Metrics.TimedCounter("db1", "docs new indexed/sec", "new Indexed Documents"); int i = 0; db1Metrics.Gauge <int>("testGauge", () => i); Random r = new Random(); var counter = db1Metrics.Counter("testCounter"); for (; i < 10000; i++) { meter.Mark(); counter.Increment(i); randomHist.Update(r.Next(101)); Thread.Sleep(100); } Console.WriteLine("Done counting"); for (i = 0; i < 10; i++) { Thread.Sleep(60000); } //Console.WriteLine(docsTimedCounterPerSec.CurrentValue); /*var RequestsPerSecondHistogram = db1Metrics.Histogram("db1.Request Per Second Histogram"); * for (int i = 0; i < 100; i++) * { * RequestsPerSecondCounter.Mark(); * RequestsPerSecondHistogram.Update((long)RequestsPerSecondCounter.CurrentValue); * Thread.Sleep(10); * } * StringBuilder sb = new StringBuilder(); * double[] res; * var perc = RequestsPerSecondHistogram.Percentiles(0.5, 0.75, 0.95, 0.98, 0.99, 0.999); * res = perc; * RequestsPerSecondHistogram.LogJson(sb,perc); * Console.WriteLine(sb); * Console.WriteLine(RequestsPerSecondHistogram.Percentiles(0.5, 0.75, 0.95, 0.98, 0.99, 0.999)); * // RequestsPerSecondHistogram.Update((long)documentDatabase.WorkContext.MetricsCounters.RequestsPerSecondCounter.CurrentValue); //?? */ }
public override void Init() { // Setup Graphite reporting //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final com.codahale.metrics.graphite.Graphite graphite = new com.codahale.metrics.graphite.Graphite(hostnamePort.getHost(), hostnamePort.getPort()); Graphite graphite = new Graphite(_hostnamePort.Host, _hostnamePort.Port); _graphiteReporter = GraphiteReporter.forRegistry(_registry).prefixedWith(_prefix).convertRatesTo(TimeUnit.SECONDS).convertDurationsTo(TimeUnit.MILLISECONDS).filter(MetricFilter.ALL).build(graphite); }
/// <summary> /// Add the <see cref="GraphiteReporter" /> allowing metrics to be reported to Graphite. /// </summary> /// <param name="metricsReportingBuilder"> /// The <see cref="IMetricsReportingBuilder" /> used to configure metrics reporters. /// </param> /// <param name="options">The Graphite reporting options to use.</param> /// <returns> /// An <see cref="IMetricsBuilder" /> that can be used to further configure App Metrics. /// </returns> public static IMetricsBuilder ToGraphite( this IMetricsReportingBuilder metricsReportingBuilder, MetricsReportingGraphiteOptions options) { if (metricsReportingBuilder == null) { throw new ArgumentNullException(nameof(metricsReportingBuilder)); } var httpClient = CreateClient(options, options.ClientPolicy); var reporter = new GraphiteReporter(options, httpClient); return(metricsReportingBuilder.Using(reporter)); }
/// <summary> /// Add the <see cref="GraphiteReporter" /> allowing metrics to be reported to Graphite. /// </summary> /// <param name="metricReporterProviderBuilder"> /// The <see cref="IMetricsReportingBuilder" /> used to configure metrics reporters. /// </param> /// <param name="setupAction">The Graphite reporting options to use.</param> /// <returns> /// An <see cref="IMetricsBuilder" /> that can be used to further configure App Metrics. /// </returns> public static IMetricsBuilder ToGraphite( this IMetricsReportingBuilder metricReporterProviderBuilder, Action <MetricsReportingGraphiteOptions> setupAction) { if (metricReporterProviderBuilder == null) { throw new ArgumentNullException(nameof(metricReporterProviderBuilder)); } var options = new MetricsReportingGraphiteOptions(); setupAction?.Invoke(options); var httpClient = CreateClient(options, options.ClientPolicy); var reporter = new GraphiteReporter(options, httpClient); return(metricReporterProviderBuilder.Using(reporter)); }
public static void Main(string[] args) { Console.WriteLine(typeof(Exception).IsAssignableFrom(typeof(ArgumentNullException))); Console.WriteLine(typeof(ArgumentNullException).IsAssignableFrom(typeof(Exception))); IKernel kernel = new StandardKernel(); MetricRegistry registry = new MetricRegistry(); kernel.Bind <MetricRegistry>().ToConstant <MetricRegistry>(registry); Tryout t = kernel.Get <Tryout>(); ConsoleReporter reporter = ConsoleReporter.ForRegistry(registry).build(); reporter.Start(1, TimeUnit.Seconds); Graphite sender = new Graphite("ttolley-lap3", 2003); GraphiteReporter greporter = GraphiteReporter.ForRegistry(registry).Build(sender); greporter.Start(10, TimeUnit.Seconds); int i = 0; Random r = new Random(); for (; i < 10000; i++) { try { t.Test(r.Next(101)); } catch { // Do nothing } } Console.WriteLine("Done counting"); for (i = 0; i < 10; i++) { Thread.Sleep(60000); } }
/// <summary> /// Add the <see cref="GraphiteReporter" /> allowing metrics to be reported to Graphite. /// </summary> /// <param name="metricReporterProviderBuilder"> /// The <see cref="IMetricsReportingBuilder" /> used to configure metrics reporters. /// </param> /// <param name="url">The base url where metrics are written.</param> /// <param name="flushInterval"> /// The <see cref="T:System.TimeSpan" /> interval used if intended to schedule metrics /// reporting. /// </param> /// <returns> /// An <see cref="IMetricsBuilder" /> that can be used to further configure App Metrics. /// </returns> public static IMetricsBuilder ToGraphite( this IMetricsReportingBuilder metricReporterProviderBuilder, string url, TimeSpan flushInterval) { if (metricReporterProviderBuilder == null) { throw new ArgumentNullException(nameof(metricReporterProviderBuilder)); } if (url == null) { throw new ArgumentNullException(nameof(url)); } if (!Uri.TryCreate(url, UriKind.Absolute, out var uri)) { throw new InvalidOperationException($"{nameof(url)} must be a valid absolute URI"); } var options = new MetricsReportingGraphiteOptions { FlushInterval = flushInterval, Graphite = { BaseUri = uri } }; var httpClient = CreateClient(options, options.ClientPolicy); var reporter = new GraphiteReporter(options, httpClient); var builder = metricReporterProviderBuilder.Using(reporter); builder.OutputMetrics.AsGraphitePlainTextProtocol(); return(builder); }
static void Main(string[] args) { int count = 0; var config = new JsonEncompassConfig(); config.Init(System.IO.File.ReadAllText("../../SextantConfigTest.json")); //manually set appenders // var console = new ConsoleLogAppender(config); //var loggly = new LogglyLogAppender(config); //var elasticSearch = new ElasticsearchLogAppender(config); //Logger.AddAppender(console); //Logger.AddAppender(loggly); //Logger.AddAppender(elasticSearch); //automatically set appenders Logger.Setup(config); Logger.AddTag("runtime-tag"); Logger.Debug("SextantTestRig", "Test debug message."); Logger.Info("SextantTestRig", "Test info message"); Logger.Warn("SextantTestRig", "Test warn message"); Logger.Error("SextantTestRig", "Test error message"); Logger.Fatal("SextantTestRig", "Test fatal message"); Console.WriteLine("press Q to quit or any other key to log another debug event."); while (Console.ReadKey().Key != ConsoleKey.Q) { var increment = 19; Parallel.For(0, increment, async => { Debug(); }); count = count + increment; } Console.WriteLine($"total queued: {count}"); Console.WriteLine("Shutting down."); Logger.Shutdown(30); return; #region Simple Metrics var datadog = new DatadogReporter(config); var graphite = new GraphiteReporter(config); SimpleMetrics.AddReporter(datadog); SimpleMetrics.AddReporter(graphite); SimpleMetrics.AddGauge("SextantTestRig.Gauge", 10); SimpleMetrics.AddCounter("SextantTestRig.Counter", 10); SimpleMetrics.AddMeter("SextantTestRig.Meter", 10); #endregion #region StatsD Metrics StatsDMetrics.Setup(config); var timer = StatsDMetrics.Timer("sextant-statd-tests-timer", Unit.Calls); Random r = new Random(); timer.StartRecording(); var counter = StatsDMetrics.Counter("sextant-statd-tests-counter", Unit.Events, MetricTags.None); counter.Increment(r.Next(0, 100)); counter.Increment(r.Next(0, 10)); counter.Increment(r.Next(0, 10)); counter.Increment(r.Next(0, 10)); counter.Increment(r.Next(0, 10)); counter.Increment(r.Next(0, 10)); counter.Increment(r.Next(0, 10)); counter.Increment(r.Next(0, 10)); timer.EndRecording(); #endregion Console.WriteLine("press enter to quit."); Console.ReadLine(); }
public override void Shutdown() { _graphiteReporter = null; }