private void PublishMetrics(IEnumerable <ICounter> statsCounters) { // Note: some ICounter's hold non-numeric values and cannot be processed. We can easily identify MOST of // them by filtering on counters that can be written to a table. foreach (var metric in statsCounters.Where(a => a.Storage == CounterStorage.LogAndTable)) { var value = metric.IsValueDelta ? metric.GetDeltaString() : metric.GetValueString(); if (double.TryParse(value, out double newVal)) { if (latestMetricValues.TryGetValue(metric.Name, out double _)) { if (metric.IsValueDelta) { latestMetricValues.AddOrUpdate(metric.Name, key => newVal, (k, v) => v + newVal); } else { latestMetricValues[metric.Name] = newVal; } } else // new counter discovered { latestMetricValues[metric.Name] = newVal; context.Gauge(metric.Name, () => latestMetricValues[metric.Name], Unit.None); } } } context.Gauge("Request queue length", () => latestRequestQueueLength, Unit.Items); }
public void Consume(JsonMetricsContext metricsData) { var sendSideLinkStateByKey = metricsData.Gauges.Where(g => g.Tags.Contains("type:sent")).GroupBy(g => g.Name); foreach (var keyState in sendSideLinkStateByKey) { var sequenceKey = keyState.Key; sendLinkState.Gauge(sequenceKey, () => GetHighestSequenceNumber(sequenceKey, receivedMetricContext, "type:sent"), sequenceUnit); } var queues = new HashSet <string>(); var receiveSideLinkStateByKey = metricsData.Gauges.Where(g => g.Tags.Contains("type:received")).GroupBy(g => g.Name); foreach (var keyState in receiveSideLinkStateByKey) { var sequenceKey = keyState.Key; var queue = QueueTag(keyState.First().Tags); queues.Add(queue); receiveLinkState.Gauge(sequenceKey, () => GetHighestSequenceNumber(sequenceKey, receivedMetricContext, "type:received"), sequenceUnit, new MetricTags($"queue:{queue}")); linkState.Gauge(sequenceKey, () => GetNumberOfInFlightMessages(sequenceKey, receiveLinkState, sendLinkState), messagesUnit, new MetricTags($"queue:{queue}")); } foreach (var queue in queues) { queueState.Gauge(queue, () => GetQueueState(queue, linkState), messagesUnit); } }
internal static void RegisterThreadPoolGauges(MetricsContext context) { context.Gauge("Thread Pool Available Threads", () => { int threads, ports; ThreadPool.GetAvailableThreads(out threads, out ports); return threads; }, Unit.Threads, tags: "threads"); context.Gauge("Thread Pool Available Completion Ports", () => { int threads, ports; ThreadPool.GetAvailableThreads(out threads, out ports); return ports; }, Unit.Custom("Ports"), tags: "threads"); context.Gauge("Thread Pool Min Threads", () => { int threads, ports; ThreadPool.GetMinThreads(out threads, out ports); return threads; }, Unit.Threads, tags: "threads"); context.Gauge("Thread Pool Min Completion Ports", () => { int threads, ports; ThreadPool.GetMinThreads(out threads, out ports); return ports; }, Unit.Custom("Ports"), tags: "threads"); context.Gauge("Thread Pool Max Threads", () => { int threads, ports; ThreadPool.GetMaxThreads(out threads, out ports); return threads; }, Unit.Threads, tags: "threads"); context.Gauge("Thread Pool Max Completion Ports", () => { int threads, ports; ThreadPool.GetMaxThreads(out threads, out ports); return ports; }, Unit.Custom("Ports"), tags: "threads"); var currentProcess = Process.GetCurrentProcess(); Func<TimeSpan> uptime = () => (DateTime.UtcNow - Process.GetCurrentProcess().StartTime.ToUniversalTime()); context.Gauge(currentProcess.ProcessName + " Uptime Seconds", () => uptime().TotalSeconds, Unit.Custom("Seconds")); context.Gauge(currentProcess.ProcessName + " Uptime Hours", () => uptime().TotalHours, Unit.Custom("Hours")); context.Gauge(currentProcess.ProcessName + " Threads", () => Process.GetCurrentProcess().Threads.Count, Unit.Threads, tags: "threads"); }
public void MetricsContext_DowsNotThrowOnMetricsOfDifferentTypeWithSameName() { ((Action)(() => { var name = "Test"; context.Gauge(name, () => 0.0, Unit.Calls); context.Counter(name, Unit.Calls); context.Meter(name, Unit.Calls, TimeUnit.Seconds); context.Histogram(name, Unit.Calls, SamplingType.FavourRecent); context.Timer(name, Unit.Calls, SamplingType.FavourRecent, TimeUnit.Seconds, TimeUnit.Milliseconds); })).ShouldNotThrow(); }
public void MetricsContext_DowsNotThrowOnMetricsOfDifferentTypeWithSameName() { ((Action)(() => { var name = "Test"; context.Gauge(name, () => 0.0, Unit.Calls); context.Counter(name, Unit.Calls); context.Meter(name, Unit.Calls); context.Histogram(name, Unit.Calls); context.Timer(name, Unit.Calls); })).ShouldNotThrow(); }
internal static void RegisterThreadPoolGauges(MetricsContext context) { context.Gauge("Thread Pool Available Threads", () => { int threads, ports; ThreadPool.GetAvailableThreads(out threads, out ports); return(threads); }, Unit.Threads, tags: "threads"); context.Gauge("Thread Pool Available Completion Ports", () => { int threads, ports; ThreadPool.GetAvailableThreads(out threads, out ports); return(ports); }, Unit.Custom("Ports"), tags: "threads"); context.Gauge("Thread Pool Min Threads", () => { int threads, ports; ThreadPool.GetMinThreads(out threads, out ports); return(threads); }, Unit.Threads, tags: "threads"); context.Gauge("Thread Pool Min Completion Ports", () => { int threads, ports; ThreadPool.GetMinThreads(out threads, out ports); return(ports); }, Unit.Custom("Ports"), tags: "threads"); context.Gauge("Thread Pool Max Threads", () => { int threads, ports; ThreadPool.GetMaxThreads(out threads, out ports); return(threads); }, Unit.Threads, tags: "threads"); context.Gauge("Thread Pool Max Completion Ports", () => { int threads, ports; ThreadPool.GetMaxThreads(out threads, out ports); return(ports); }, Unit.Custom("Ports"), tags: "threads"); var currentProcess = Process.GetCurrentProcess(); Func <TimeSpan> uptime = () => (DateTime.UtcNow - Process.GetCurrentProcess().StartTime.ToUniversalTime()); context.Gauge(currentProcess.ProcessName + " Uptime Seconds", () => uptime().TotalSeconds, Unit.Custom("Seconds")); context.Gauge(currentProcess.ProcessName + " Uptime Hours", () => uptime().TotalHours, Unit.Custom("Hours")); context.Gauge(currentProcess.ProcessName + " Threads", () => Process.GetCurrentProcess().Threads.Count, Unit.Threads, tags: "threads"); }
private void UpdateGauge(string name, double firstTimeValue, Func <string, double, double> updateValueFactory, Unit unit) { bool exists = true; _latestMetricValues.AddOrUpdate(name, key => { exists = false; return(firstTimeValue); }, updateValueFactory); // New counter discovered if (!exists) { _context.Gauge(name, () => _latestMetricValues[name], unit); } }