public static async Task Time(Func <Task> action, EventGauge gauge) { Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); await action.Invoke(); stopwatch.Stop(); gauge.Record(stopwatch.Elapsed.TotalMilliseconds, DateTime.Now); }
static void Main(string[] args) { _collector = new MetricsCollector(new BosunOptions(ex => Handle(ex)) { MetricsNamePrefix = "TestApp.", BosunUrl = new System.Uri("http://192.168.1.5:8070"), PropertyToTagName = NameTransformers.CamelToLowerSnakeCase, ThrowOnPostFail = true, DefaultTags = new Dictionary <string, string> { { "host", NameTransformers.Sanitize(Environment.MachineName.ToLower()) }, { "client", "home" }, } }); _timer = _collector.CreateMetric <EventGauge>("GetWeather", "time taken", "measures time taken to get weather from api"); var dispatcherTimer = new Timer(); dispatcherTimer.Interval = 5000; dispatcherTimer.Start(); dispatcherTimer.Elapsed += new ElapsedEventHandler(timer_Elapsed); Console.ReadLine(); }
protected override void UpdateMetric(EventGauge metric) => metric.Record(42.123d);