public void can_report_gauges() { var metricsMock = new Mock <IMetrics>(); var gauge = new FunctionGauge(() => 1); var gaugeValueSource = new GaugeValueSource("test gauge", ConstantValue.Provider(gauge.Value), Unit.None, MetricTags.None); var payloadBuilder = new LineProtocolPayloadBuilder(); var reporter = CreateReporter(payloadBuilder); reporter.StartReportRun(metricsMock.Object); reporter.ReportMetric("test", gaugeValueSource); payloadBuilder.PayloadFormatted().Should().Be("test__test_gauge value=1\n"); }
public void can_report_gauges__when_multidimensional() { var metricsMock = new Mock <IMetrics>(); var gauge = new FunctionGauge(() => 1); var gaugeValueSource = new GaugeValueSource( "gauge-group" + MultidimensionalMetricNameSuffix, ConstantValue.Provider(gauge.Value), Unit.None, _tags); var items = CreateReporterAndPayloadBuilder(); items.Item1.StartReportRun(metricsMock.Object); items.Item1.ReportMetric("test", gaugeValueSource); items.Item2.PayloadFormatted().Should().Be("test__gauge-group host=server1 env=staging mtype=gauge unit=none value=1" + Environment.NewLine); }
public void can_report_gauges() { var metricsMock = new Mock <IMetrics>(); var gauge = new FunctionGauge(() => 1); var gaugeValueSource = new GaugeValueSource( "test gauge", ConstantValue.Provider(gauge.Value), Unit.None, MetricTags.Empty); var items = CreateReporterAndPayloadBuilder(); items.Item1.StartReportRun(metricsMock.Object); items.Item1.ReportMetric("test", gaugeValueSource); items.Item2.PayloadFormatted().Should().Be("test__test_gauge mtype=gauge unit=none value=1" + Environment.NewLine); }
public void Can_report_gauges__when_multidimensional() { // Arrange var expected = "test__gauge-group,host=server1,env=staging,mtype=gauge,unit=none value=1 1483232461000000000\n"; var gauge = new FunctionGauge(() => 1); var gaugeValueSource = new GaugeValueSource( "gauge-group" + MultidimensionalMetricNameSuffix, ConstantValue.Provider(gauge.Value), Unit.None, _tags); // Act var valueSource = CreateValueSource("test", gauges: gaugeValueSource); // Assert AssertExpectedLineProtocolString(new MetricsDataValueSource(_timestamp, new[] { valueSource }), expected); }
public void Can_report_gauges() { // Arrange var expected = "test__test_gauge,mtype=gauge,unit=none value=1 1483232461000000000\n"; var gauge = new FunctionGauge(() => 1); var gaugeValueSource = new GaugeValueSource( "test gauge", ConstantValue.Provider(gauge.Value), Unit.None, MetricTags.Empty); // Act var valueSource = CreateValueSource("test", gauges: gaugeValueSource); // Assert AssertExpectedLineProtocolString(new MetricsDataValueSource(_timestamp, new[] { valueSource }), expected); }
public async Task Can_report_gauges__when_multidimensional() { // Arrange var expected = "{\"series\":[{\"metric\":\"test.gauge-group.gauge.value\",\"points\":[[1483232461,1]],\"type\":\"gauge\",\"tags\":[\"host:server1\",\"env:staging\",\"unit:none\"]}]}"; var gauge = new FunctionGauge(() => 1); var gaugeValueSource = new GaugeValueSource( "gauge-group" + MultidimensionalMetricNameSuffix, ConstantValue.Provider(gauge.Value), Unit.None, _tags); // Act var valueSource = CreateValueSource("test", gauges: gaugeValueSource); // Assert await AssertExpectedLineProtocolString(new MetricsDataValueSource(_timestamp, new[] { valueSource }), FlushInterval, expected); }
public async Task Can_report_gauges() { // Arrange var expected = "{\"series\":[{\"metric\":\"test.test_gauge.gauge.value\",\"points\":[[1483232461,1]],\"type\":\"gauge\",\"tags\":[\"unit:none\"]}]}"; var gauge = new FunctionGauge(() => 1); var gaugeValueSource = new GaugeValueSource( "test gauge", ConstantValue.Provider(gauge.Value), Unit.None, MetricTags.Empty); // Act var valueSource = CreateValueSource("test", gauges: gaugeValueSource); // Assert await AssertExpectedLineProtocolString(new MetricsDataValueSource(_timestamp, new[] { valueSource }), FlushInterval, expected); }
public void can_report_gauges__when_multidimensional() { var metricsMock = new Mock <IMetrics>(); var gauge = new FunctionGauge(() => 1); var gaugeValueSource = new GaugeValueSource( "gauge-group" + MultidimensionalMetricNameSuffix, ConstantValue.Provider(gauge.Value), Unit.None, _tags); var payloadBuilder = new LineProtocolPayloadBuilder(); var reporter = CreateReporter(payloadBuilder); reporter.StartReportRun(metricsMock.Object); reporter.ReportMetric("test", gaugeValueSource); payloadBuilder.PayloadFormatted().Should().Be("test__gauge-group,host=server1,env=staging value=1\n"); }
public async Task Can_report_gauges__when_multidimensional() { // Arrange var expected = "env.staging.gauge.test.gauge-group.host.server1.Value 1.00 1483232461\n"; var gauge = new FunctionGauge(() => 1); var gaugeValueSource = new GaugeValueSource( "gauge-group" + MultidimensionalMetricNameSuffix, ConstantValue.Provider(gauge.Value), Unit.None, _tags); // Act var valueSource = CreateValueSource("test", gauges: gaugeValueSource); // Assert await AssertExpectedLineProtocolString(new MetricsDataValueSource(_timestamp, new[] { valueSource }), expected); }
public async Task Can_report_gauges() { // Arrange var expected = "gauge.test.test_gauge.Value 1.00 1483232461\n"; var gauge = new FunctionGauge(() => 1); var gaugeValueSource = new GaugeValueSource( "test gauge", ConstantValue.Provider(gauge.Value), Unit.None, MetricTags.Empty); // Act var valueSource = CreateValueSource("test", gauges: gaugeValueSource); // Assert await AssertExpectedLineProtocolString(new MetricsDataValueSource(_timestamp, new[] { valueSource }), expected); }
public void can_report_gauges__when_multidimensional() { var metricsMock = new Mock <IMetrics>(); var gauge = new FunctionGauge(() => 1); var gaugeValueSource = new GaugeValueSource( "gauge-group" + MultidimensionalMetricNameSuffix, ConstantValue.Provider(gauge.Value), Unit.None, _tags); var payloadBuilder = new GraphitePayloadBuilder(_settings.GraphiteSettings.MetricNameFormatter, _settings.DataKeys, Origin); var reporter = CreateReporter(payloadBuilder); reporter.StartReportRun(metricsMock.Object); reporter.ReportMetric("test", gaugeValueSource); payloadBuilder.PayloadFormatted().Should().Be("env.staging.gauge.test.gauge-group.host.server1.value 1.00 0\n"); }
public void can_report_gauges() { var metricsMock = new Mock <IMetrics>(); var gauge = new FunctionGauge(() => 1); var gaugeValueSource = new GaugeValueSource( "test gauge", ConstantValue.Provider(gauge.Value), Unit.None, MetricTags.Empty); var payloadBuilder = new GraphitePayloadBuilder(_settings.GraphiteSettings.MetricNameFormatter, _settings.DataKeys, Origin); var reporter = CreateReporter(payloadBuilder); reporter.StartReportRun(metricsMock.Object); reporter.ReportMetric("test", gaugeValueSource); payloadBuilder.PayloadFormatted().Should().Be("gauge.test.test_gauge.value 1.00 0\n"); }
static void Main(string[] args) { // 将会自动将 app(程序集名)、server(机器名)和env(运行环境)作为标签 var metrics = AppMetrics.CreateDefaultBuilder() .Report.ToConsole() .Build(); //metrics.Measure.Gauge.SetValue(MyMetrics.ProcessMetrics.SystemNonPagedMemoryGauge, 2); //metrics.Measure.Gauge.SetValue(MyMetrics.ProcessMetrics.ProcessVirtualMemorySizeGauge, 20); //using (metrics.Measure.Timer.Time(MyMetrics.DatabaseMetrics.SearchUsersSqlTimer)) //{ // Thread.Sleep(100); //} var process = Process.GetCurrentProcess(); var derivedGauge = new GaugeOptions { Name = "Derived Gauge", MeasurementUnit = Unit.MegaBytes }; var processPhysicalMemoryGauge = new GaugeOptions { Name = "Process Physical Memory", MeasurementUnit = Unit.Bytes }; var physicalMemoryGauge = new FunctionGauge(() => process.WorkingSet64); metrics.Measure.Gauge.SetValue(derivedGauge, () => new DerivedGauge(physicalMemoryGauge, g => g / 1024 / 1024)); metrics.Measure.Gauge.SetValue(processPhysicalMemoryGauge, () => physicalMemoryGauge); Task.WhenAll(metrics.ReportRunner.RunAllAsync()).Wait(); Console.ReadKey(); }
public IActionResult GetMetrics() { var httpStatusMeter = new MeterOptions { Name = "Http Status", MeasurementUnit = Unit.Calls, }; _metrics.Measure.Meter.Mark(httpStatusMeter, 70, "200"); _metrics.Measure.Meter.Mark(httpStatusMeter, 10, "500"); _metrics.Measure.Meter.Mark(httpStatusMeter, 20, "401"); // Test Counter Sample _metrics.Measure.Counter.Increment(MetricsRegistry.Counters.TestCounter); _metrics.Measure.Counter.Increment(MetricsRegistry.Counters.TestCounter, 4); _metrics.Measure.Counter.Decrement(MetricsRegistry.Counters.TestCounter, 2); var process = Process.GetCurrentProcess(); var physicalMemoryGauge = new FunctionGauge(() => process.WorkingSet64); _metrics.Measure.Gauge.SetValue(MetricsRegistry.Gauges.TestGauge, () => physicalMemoryGauge.Value); _metrics.Measure.Gauge.SetValue( MetricsRegistry.Gauges.DerivedGauge, () => new DerivedGauge(physicalMemoryGauge, g => g / 1024.0 / 1024.0)); var cacheHits = _metrics.Provider.Meter.Instance(MetricsRegistry.Meters.CacheHits); var calls = _metrics.Provider.Timer.Instance(MetricsRegistry.Timers.DatabaseQueryTimer); var cacheHit = Rnd.Next(0, 2) == 0; if (cacheHit) { cacheHits.Mark(); } using (calls.NewContext()) { Thread.Sleep(cacheHit ? 10 : 100); } using (_metrics.Measure.Apdex.Track(MetricsRegistry.ApdexScores.TestApdex)) { Thread.Sleep(cacheHit ? 10 : 100); } _metrics.Measure.Gauge.SetValue(MetricsRegistry.Gauges.CacheHitRatioGauge, () => new HitRatioGauge(cacheHits, calls, m => m.OneMinuteRate)); var histogram = _metrics.Provider.Histogram.Instance(MetricsRegistry.Histograms.TestHAdvancedistogram); histogram.Update(Rnd.Next(1, 20)); _metrics.Measure.Histogram.Update(MetricsRegistry.Histograms.TestHistogram, Rnd.Next(20, 40)); _metrics.Measure.Timer.Time(MetricsRegistry.Timers.TestTimer, () => Thread.Sleep(20), "value1"); _metrics.Measure.Timer.Time(MetricsRegistry.Timers.TestTimer, () => Thread.Sleep(25), "value2"); using (_metrics.Measure.Timer.Time(MetricsRegistry.Timers.TestTimerTwo)) { Thread.Sleep(15); } using (_metrics.Measure.Timer.Time(MetricsRegistry.Timers.TestTimerTwo, "value1")) { Thread.Sleep(20); } using (_metrics.Measure.Timer.Time(MetricsRegistry.Timers.TestTimerTwo, "value2")) { Thread.Sleep(25); } return(Ok()); }
public IEnumerable <string> Get() { var httpStatusMeter = new MeterOptions { Name = "Http Status", MeasurementUnit = Unit.Calls }; _metrics.Mark(httpStatusMeter, 70, "200"); _metrics.Mark(httpStatusMeter, 10, "500"); _metrics.Mark(httpStatusMeter, 20, "401"); _metrics.Increment(MetricsRegistry.Counters.TestCounter); _metrics.Increment(MetricsRegistry.Counters.TestCounter, 4); _metrics.Decrement(MetricsRegistry.Counters.TestCounter, 2); var process = Process.GetCurrentProcess(); var physicalMemoryGauge = new FunctionGauge(() => process.WorkingSet64); _metrics.Gauge(MetricsRegistry.Gauges.TestGauge, () => physicalMemoryGauge.Value); _metrics.Advanced.Gauge(MetricsRegistry.Gauges.DerivedGauge, () => new DerivedGauge(physicalMemoryGauge, g => g / 1024.0 / 1024.0)); var cacheHits = _metrics.Advanced.Meter(MetricsRegistry.Meters.CacheHits); var calls = _metrics.Advanced.Timer(MetricsRegistry.Timers.DatabaseQueryTimer); var cacheHit = Rnd.Next(0, 2) == 0; if (cacheHit) { cacheHits.Mark(); } using (calls.NewContext()) { Thread.Sleep(cacheHit ? 10 : 100); } _metrics.Advanced.Gauge(MetricsRegistry.Gauges.CacheHitRatioGauge, () => new HitRatioGauge(cacheHits, calls, m => m.OneMinuteRate)); var histogram = _metrics.Advanced.Histogram(MetricsRegistry.Histograms.TestHAdvancedistogram); histogram.Update(Rnd.Next(1, 20)); _metrics.Update(MetricsRegistry.Histograms.TestHistogram, Rnd.Next(20, 40)); _metrics.Time(MetricsRegistry.Timers.TestTimer, () => Thread.Sleep(20), "value1"); _metrics.Time(MetricsRegistry.Timers.TestTimer, () => Thread.Sleep(25), "value2"); using (_metrics.Time(MetricsRegistry.Timers.TestTimerTwo)) { Thread.Sleep(15); } using (_metrics.Time(MetricsRegistry.Timers.TestTimerTwo, "value1")) { Thread.Sleep(20); } using (_metrics.Time(MetricsRegistry.Timers.TestTimerTwo, "value2")) { Thread.Sleep(25); } return(new[] { "value1", "value2" }); }