Skip to content

Commit

Permalink
Scrape HerculesSinkMetrics on dispose
Browse files Browse the repository at this point in the history
  • Loading branch information
HolyPrapor committed Oct 14, 2021
1 parent 32ad860 commit f8737b3
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions Vostok.Hosting/Components/Hercules/HerculesSinkMetrics.cs
Original file line number Diff line number Diff line change
@@ -1,21 +1,18 @@
using System;
using System.Collections.Generic;
using System.Text;
using Vostok.Commons.Time;
using Vostok.Hercules.Client;
using Vostok.Hercules.Client.Abstractions;
using Vostok.Hosting.Abstractions;
using Vostok.Logging.Abstractions;
using Vostok.Metrics;
using Vostok.Metrics.Models;
using Vostok.Metrics.Scraping;
using Vostok.Metrics.Primitives.Gauge;

namespace Vostok.Hosting.Components.Hercules
{
internal class HerculesSinkMetrics : IScrapableMetric
internal class HerculesSinkMetrics
{
private static readonly TimeSpan ScrapePeriod = 1.Minutes();

private readonly ILog log;
private readonly HerculesSink herculesSink;
private readonly MetricTags tags;
Expand All @@ -35,11 +32,13 @@ public static IDisposable Measure(IHerculesSink herculesSink, IVostokApplication
return null;

var builtContext = context.Application.WithTag(WellKnownTagKeys.Component, "HerculesSink");
return builtContext.Register(new HerculesSinkMetrics(sink, builtContext, log), ScrapePeriod);
return builtContext.CreateMultiFuncGaugeFromEvents(new HerculesSinkMetrics(sink, builtContext, log).ProvideMetrics, new FuncGaugeConfig(){ScrapeOnDispose = true}) as IDisposable;
}

public IEnumerable<MetricEvent> Scrape(DateTimeOffset timestamp)
public IEnumerable<MetricEvent> ProvideMetrics()
{
var timestamp = DateTimeOffset.Now;

var statistic = herculesSink.GetStatistics();

var delta = statistic.Total - previous.Total;
Expand Down

0 comments on commit f8737b3

Please sign in to comment.