public void RegisterMetrics(ICollectorRegistry registry) { MetricFactory metricFactory = Prometheus.Metrics.WithCustomRegistry(registry); var counter = metricFactory.CreateCounter("gc_collect_count", "GC collection count", _lableNames.Union(new[] { "generation" }).ToArray()); for (var number = 0; number <= GC.MaxGeneration; number++) { _collectionCounts.Add(counter.Labels(_labelValues.Union(new[] { number.ToString() }).ToArray())); } _startTime = metricFactory .CreateGauge("start_time", "Start time of the process since unix epoch in seconds", _lableNames) .Labels(_labelValues); _cpuTotal = metricFactory.CreateCounter("cpu_seconds_total", "Total user and system CPU time spent in seconds", _lableNames).Labels(_labelValues); _virtualMemorySize = metricFactory.CreateGauge("virtual_bytes", "Process virtual memory size", _lableNames).Labels(_labelValues); _workingSet = metricFactory.CreateGauge("working_set", "Process working set", _lableNames).Labels(_labelValues); _privateMemorySize = metricFactory.CreateGauge("private_bytes", "Process private memory size", _lableNames).Labels(_labelValues); _openHandles = metricFactory.CreateGauge("open_handles", "Number of open handles", _lableNames).Labels(_labelValues); _numThreads = metricFactory.CreateGauge("num_threads", "Total number of threads", _lableNames).Labels(_labelValues); _pid = metricFactory.CreateGauge("processid", "Process ID", _lableNames).Labels(_labelValues); _totalMemory = metricFactory.CreateGauge("totalmemory", "Total known allocated memory", _lableNames).Labels(_labelValues); _startTime.Set((_process.StartTime.ToUniversalTime() - new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)) .TotalSeconds); _pid.Set(_process.Id); }
public static GaugeVisitor Collect(this IGauge gauge) { var visitor = new GaugeVisitor(); gauge.Visit(visitor); return(visitor); }
protected NodeBase(ICluster owner, IPEndPoint endpoint, IFailurePolicy failurePolicy, ISocket socket) { this.owner = owner; this.endpoint = endpoint; this.socket = socket; this.failurePolicy = failurePolicy; this.name = endpoint.ToString(); failLock = new Object(); writeQueue = new ConcurrentQueue <Data>(); readQueue = new Queue <Data>(); mustReconnect = true; IsAlive = true; counterEnqueuePerSec = Metrics.Meter("node write enqueue/sec", endpoint.ToString(), Interval.Seconds); counterDequeuePerSec = Metrics.Meter("node write dequeue/sec", endpoint.ToString(), Interval.Seconds); counterOpReadPerSec = Metrics.Meter("node op read/sec", endpoint.ToString(), Interval.Seconds); counterWriteQueue = Metrics.Counter("write queue length", endpoint.ToString()); counterReadQueue = Metrics.Counter("read queue length", endpoint.ToString()); counterWritePerSec = Metrics.Meter("node write/sec", endpoint.ToString(), Interval.Seconds); counterErrorPerSec = Metrics.Meter("node in error/sec", endpoint.ToString(), Interval.Seconds); counterItemCount = Metrics.Counter("commands", endpoint.ToString()); gaugeSendSpeed = Metrics.Gauge("send speed", endpoint.ToString()); }
public void Setup() { _gauge = OurMetricFactory.CreateGauge("testgauge", HelpText); _gaugeInt64 = OurMetricFactory.CreateGaugeInt64("testgaugeInt64", HelpText); _theirGauge = TheirMetricFactory.CreateGauge("testgauge", HelpText); }
public ResourceMiddleware( RequestDelegate next, ILogger <ResourceMiddleware> logger, IOptions <ResourceMetricsOptions> ResourceMetricsOptionsAccessor, IMetrics metrics) { _logger = logger; _next = next; _metrics = metrics; // Setup the metrics. _maxWorkingSet = _metrics.Provider.Gauge.Instance(ResourceMetricsRegistry.MaxWorkingSetGauge); _pagedMemorySize64 = _metrics.Provider.Gauge.Instance(ResourceMetricsRegistry.PagedMemorySize64Gauge); _nonpagedSystemMemorySize64 = _metrics.Provider.Gauge.Instance(ResourceMetricsRegistry.NonpagedSystemMemorySize64Gauge); _peakPagedMemorySize64 = _metrics.Provider.Gauge.Instance(ResourceMetricsRegistry.PeakPagedMemorySize64Gauge); _peakWorkingSet64 = _metrics.Provider.Gauge.Instance(ResourceMetricsRegistry.PeakWorkingSet64Gauge); _totalProcessorTime = _metrics.Provider.Gauge.Instance(ResourceMetricsRegistry.TotalProcessorTimeGauge); _userProcessorTime = _metrics.Provider.Gauge.Instance(ResourceMetricsRegistry.UserProcessorTimeGauge); _virtualMemorySize64 = _metrics.Provider.Gauge.Instance(ResourceMetricsRegistry.VirtualMemorySize64Gauge); _workingSet64 = _metrics.Provider.Gauge.Instance(ResourceMetricsRegistry.WorkingSet64Gauge); _threadsCount = _metrics.Provider.Gauge.Instance(ResourceMetricsRegistry.ThreadsCountGauge); _gcCollectionCount = _metrics.Provider.Gauge.Instance(ResourceMetricsRegistry.GCCollectionCountGauge); _gcTotalMemory = _metrics.Provider.Gauge.Instance(ResourceMetricsRegistry.GCTotalMemoryGauge); _lastGCTime = _metrics.Provider.Gauge.Instance(ResourceMetricsRegistry.LastGCTimeGauge); }
/// <summary> /// Sets the value of the gauge to the current Unix timestamp in seconds. /// </summary> public static void SetToCurrentTime(this IGauge gauge) { var unixTicks = DateTime.UtcNow.Ticks - new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).Ticks; // Convert to double first to ensure that we can report fractional seconds. gauge.Set((double)unixTicks / TimeSpan.TicksPerSecond); }
protected NodeBase(ICluster owner, IPEndPoint endpoint, IFailurePolicy failurePolicy, ISocket socket) { this.owner = owner; this.endpoint = endpoint; this.socket = socket; this.failurePolicy = failurePolicy; this.name = endpoint.ToString(); failLock = new Object(); writeQueue = new ConcurrentQueue<Data>(); readQueue = new Queue<Data>(); mustReconnect = true; IsAlive = true; counterEnqueuePerSec = Metrics.Meter("node write enqueue/sec", endpoint.ToString(), Interval.Seconds); counterDequeuePerSec = Metrics.Meter("node write dequeue/sec", endpoint.ToString(), Interval.Seconds); counterOpReadPerSec = Metrics.Meter("node op read/sec", endpoint.ToString(), Interval.Seconds); counterWriteQueue = Metrics.Counter("write queue length", endpoint.ToString()); counterReadQueue = Metrics.Counter("read queue length", endpoint.ToString()); counterWritePerSec = Metrics.Meter("node write/sec", endpoint.ToString(), Interval.Seconds); counterErrorPerSec = Metrics.Meter("node in error/sec", endpoint.ToString(), Interval.Seconds); counterItemCount = Metrics.Counter("commands", endpoint.ToString()); gaugeSendSpeed = Metrics.Gauge("send speed", endpoint.ToString()); }
public AppMetricsGauge(IMetrics metrics, IGauge gauge, string bucket, string name) { _metrics = metrics; _gauge = gauge; Context = bucket; Name = name; }
private const long UnixEpochSeconds = UnixEpochTicks / TimeSpan.TicksPerSecond; // 62,135,596,800 /// <summary> /// Sets the value of the gauge to the current UTC time as a Unix timestamp in seconds. /// Value does not include any elapsed leap seconds because Unix timestamps do not include leap seconds. /// </summary> public static void SetToCurrentTimeUtc(this IGauge gauge) { // This gets us sub-millisecond precision, which is better than ToUnixTimeMilliseconds(). var ticksSinceUnixEpoch = DateTimeOffset.UtcNow.Ticks - UnixEpochSeconds * TimeSpan.TicksPerSecond; var secondsSinceUnixEpoch = ticksSinceUnixEpoch / (double)TimeSpan.TicksPerSecond; gauge.Set(secondsSinceUnixEpoch); }
public static T TrackInProgress <T>(this IGauge gauge, Func <T> fun) { gauge.Increment(); var ret = fun.Invoke(); gauge.Decrement(); return(ret); }
// Start is called before the first frame update void Start() { image.color = color; RectTransform rect = GetComponent <RectTransform>(); rect.pivot = pivot; rect.sizeDelta = new Vector2(volume, 10); gauge = new Gauge("HP", 100, 0, 200); GetComponent <Slider>().value = gauge.NormalizedValue; }
/// <inheritdoc /> public IGauge CreateGauge(string name, string help, bool delayPublish, string[] labels) { var gauges = new IGauge[_providers.Count]; for (var index = 0; index < gauges.Length; index++) { gauges[index] = _providers.ElementAt(index).Value.CreateGauge(name, help, delayPublish, labels); } return(gauges.Length == 1 ? gauges[0] : new Gauge(gauges, name, help, labels)); }
public void GaugeValueIsIncreased() { var tags = new Dictionary <string, string> { { "foo", "bar" } }; NoopMetricsFactory metricsFactory = NoopMetricsFactory.Instance; IGauge gauge = metricsFactory.CreateGauge("thegauge", tags); gauge.Update(1); }
/// <summary> /// Tracks the number of in-progress operations taking place. /// /// Calling this increments the gauge. Disposing of the returned instance decrements it again. /// </summary> /// <remarks> /// It is safe to track the sum of multiple concurrent in-progress operations with the same gauge. /// </remarks> public static IDisposable TrackInProgress(this IGauge gauge) { if (gauge == null) { throw new ArgumentNullException(nameof(gauge)); } gauge.Inc(); return(new InProgressTracker(gauge)); }
public GaugeTests() { noLabel = new DefaultGauge("noLabel", new GaugeOptions { Help = "help noLabels", }); labeled = new DefaultGauge("labeled", new GaugeOptions { Help = "help labeled", LabelNames = Labeled.SingleLabels }); }
public void Configure(IMetricsRoot metrics) { Chunks = metrics.Provider.Gauge.Instance(new GaugeOptions() { Context = Context, Name = "Chunks", MeasurementUnit = Unit.None }); RenderedChunks = metrics.Provider.Gauge.Instance(new GaugeOptions() { Context = Context, Name = "Rendered Chunks", MeasurementUnit = Unit.None }); ChunkUpdatesQueued = metrics.Provider.Gauge.Instance(new GaugeOptions() { Context = Context, Name = "Chunk Updates (Queued)", MeasurementUnit = Unit.None }); ChunkUpdateActive = metrics.Provider.Gauge.Instance(new GaugeOptions() { Context = Context, Name = "Chunk Updates (Active)", MeasurementUnit = Unit.None }); Entities = metrics.Provider.Gauge.Instance(new GaugeOptions() { Context = Context, Name = "Entities", MeasurementUnit = Unit.None }); RenderedEntities = metrics.Provider.Gauge.Instance(new GaugeOptions() { Context = Context, Name = "Rendered Entities", MeasurementUnit = Unit.None }); RenderedVertices = metrics.Provider.Gauge.Instance(new GaugeOptions() { Context = Context, Name = "Rendered Vertices", MeasurementUnit = Unit.None }); }
private void AddOverallScoreLabel(IGauge gauge, int score) { var scoreLabel = ((CircularGauge)gauge).AddLabel(); scoreLabel.AppearanceText.TextBrush = new SolidBrushObject { Color = System.Drawing.Color.White }; scoreLabel.Text = score >= 0 ? $"{score.ToString()}%" : "N/A"; scoreLabel.AppearanceText.Font = new Font("Open Sans", 34, FontStyle.Bold); scoreLabel.Size = new SizeF(300F, 300F); }
public void GaugeValueIsIncreased() { var tags = new Dictionary <string, string> { { "foo", "bar" } }; InMemoryMetricsFactory inMemoryMetricsFactory = new InMemoryMetricsFactory(); IGauge gauge = inMemoryMetricsFactory.CreateGauge("thegauge", tags); Assert.Equal(0, inMemoryMetricsFactory.GetGauge("thegauge", tags)); gauge.Update(1); Assert.Equal(1, inMemoryMetricsFactory.GetGauge("thegauge", tags)); }
private void AddCategoryScoreLabels(IGauge gauge, int score, bool isWeekly) { var scoreLabel = ((CircularGauge)gauge).AddLabel(); scoreLabel.Text = score >= 0 ? $"{score.ToString()}%" : "N/A"; scoreLabel.AppearanceText.Font = new Font("Open Sans", 32, FontStyle.Bold); scoreLabel.Size = new SizeF(300F, 300F); var infoLabel = ((CircularGauge)gauge).AddLabel(); infoLabel.Text = isWeekly ? "\n\nWeekly" : "\n\nQuarterly"; infoLabel.AppearanceText.Font = new Font("Open Sans", 17, FontStyle.Bold); infoLabel.Size = new SizeF(300F, 300F); }
/// <summary> /// Initializes a new instance of the <see cref="FixedLimit" /> class. /// </summary> /// <param name="limit">The limit.</param> /// <param name="metricsRegistry">The metrics registry.</param> public FixedLimit(int limit, IMetricsRegistry metricsRegistry) { this.limit = limit; var maxOperations = metricsRegistry.CreateGauge( Metrics.MaxOperations.Name, Metrics.MaxOperations.Description, new[] { Metrics.Labels.LimitTypeName }); maxOperations.WithLabels(new[] { Metrics.Labels.LimitTypeValue }).Set(limit); this.currentOperations = metricsRegistry.CreateGauge( Metrics.CurrentOperations.Name, Metrics.CurrentOperations.Description, new[] { Metrics.Labels.LimitTypeName }) .WithLabels(new[] { Metrics.Labels.LimitTypeValue }); }
public void Configure(IMetricsRoot metrics) { ResourceCounter = metrics.Provider.Gauge.Instance(new GaugeOptions() { Context = Context, Name = "Resources", MeasurementUnit = Unit.Items, // Tags = new MetricTags() }); Memory = metrics.Provider.Gauge.Instance(new GaugeOptions() { Context = Context, Name = "Memory Usage", MeasurementUnit = Unit.Bytes, // Tags = new MetricTags() }); }
public void Configure(IMetricsRoot metrics) { ProcessPhysicalMemoryGauge = metrics.Provider.Gauge.Instance(new GaugeOptions() { Context = ContextName, Name = "Environment Working Set", MeasurementUnit = Unit.Bytes }); ProcessTotalProcessorTime = metrics.Provider.Gauge.Instance(new GaugeOptions() { Context = ContextName, Name = "CPU Time (total)", MeasurementUnit = Unit.None }); ProcessUserProcessorTime = metrics.Provider.Gauge.Instance(new GaugeOptions() { Context = ContextName, Name = "CPU Time (user)", MeasurementUnit = Unit.None }); CpuUsage = metrics.Provider.Gauge.Instance(new GaugeOptions() { Context = ContextName, Name = "CPU Usage", MeasurementUnit = Unit.Percent }); Threads = metrics.Provider.Gauge.Instance(new GaugeOptions() { Context = ContextName, Name = "Threads", MeasurementUnit = Unit.Threads }); CompletionPorts = metrics.Provider.Gauge.Instance(new GaugeOptions() { Context = ContextName, Name = "Completion Ports", MeasurementUnit = Unit.None }); }
/// <summary> /// Initializes a new instance of the type /// </summary> /// <param name="dependencyService">A service that can be used to retrieve dependencies that were injected</param> /// <param name="loggerFactory">A factory that can be used to create loggers</param> /// <param name="metricFactory">A factory that can be used to create metrics</param> /// <param name="webSocketConfiguration">The configuration of the web socket</param> /// <param name="bufferPool">The buffer pool used to retreive arrays</param> public WebSocketHandler(IDependencyService dependencyService, IWebSocketConfiguration webSocketConfiguration, IMetricFactory metricFactory, ILoggerFactory loggerFactory, IBufferPool bufferPool) { Guard.NotNull(nameof(metricFactory), metricFactory); Guard.NotNull(nameof(loggerFactory), loggerFactory); Guard.NotNull(nameof(bufferPool), bufferPool); Guard.NotNull(nameof(webSocketConfiguration), webSocketConfiguration); WebSocketConfiguration = webSocketConfiguration; BufferPool = bufferPool; SessionId = Guid.NewGuid(); MetricFactory = metricFactory; Logger = loggerFactory.CreateLogger($"Session Handler: {SessionId:N}"); DependencyService = dependencyService; _errorCounter = metricFactory.CreateCounter("WebSocket error counter", "Tracks the number of errors that have occurred since the start of the service", false, new string[0]); _serviceSessionGauge = metricFactory.CreateGauge("WebSocket sessions in progress", "Tracks the number of sessions underway", false, new string[0]); _sessionTimes = metricFactory.CreateSummary("WebSocket session iteration times", "Tracks the time taken to execute an iteration in the session", 10, false, new string[0]); _receiveTimes = metricFactory.CreateSummary("WebSocket message receive time", "Tracks the time taken to receive a message", 10, false, new string[0]); }
public ModuleLicensingService(ILogger <ModuleLicensingService> logger, ILicenseValidator licenseValidator, IModuleMetrics moduleMetrics) { this.logger = logger; this.licenseValidator = licenseValidator; moduleInstanceName = Environment.GetEnvironmentVariable("IOTEDGE_MODULEID"); if (string.IsNullOrWhiteSpace(moduleInstanceName)) { throw new InvalidOperationException($"IOTEDGE_MODULEID environment variable is null or blank."); } hostName = Environment.GetEnvironmentVariable("IOTEDGE_DEVICEID"); if (string.IsNullOrWhiteSpace(hostName)) { throw new InvalidOperationException($"IOTEDGE_DEVICEID environment variable is null or blank."); } hubName = Environment.GetEnvironmentVariable("IOTEDGE_IOTHUBHOSTNAME"); if (string.IsNullOrWhiteSpace(hubName)) { throw new InvalidOperationException($"IOTEDGE_IOTHUBHOSTNAME environment variable is null or blank."); } logger.LogInformation("Beginning periodic license validation for module {Module} on host {Host} for IoT Hub {Hub}", moduleInstanceName, hostName, hubName); licenseKey = Environment.GetEnvironmentVariable("MODULE_LICENSE_KEY"); if (string.IsNullOrWhiteSpace(licenseKey)) { throw new InvalidOperationException($"MODULE_LICENSE_KEY environment variable is null or blank."); } logger.LogInformation("License key '{LicenseKey}' loaded from environment variable", licenseKey); licenseCheckInterval = TimeSpan.FromHours(1); maxConsecutiveCheckFailures = 36; serviceStopping = new CancellationTokenSource(); consecutiveLicenseCheckFailures = moduleMetrics.CreateGauge( "edgelicensing_consecutive_failures", "Consecutive edge licensing check failures"); remainingConsecutiveLicenseCheckFailures = moduleMetrics.CreateGauge( "edgelicensing_remaining_consecutive_failures", "Remaining consecutive edge licensing check failures"); }
/// <summary> /// Enables you to easily report elapsed seconds in the value of a gauge. /// You need to manually call .ApplyDuration() on the returned instance to update the value of the gauge. /// </summary> public static Gauge.Timer StartTimer(this IGauge gauge) { return(new Gauge.Timer(gauge)); }
public BackgroundTaskQueue(IGauge queuedItemsGauge) { _queuedItemsGauge = queuedItemsGauge ?? throw new ArgumentNullException(nameof(queuedItemsGauge)); }
public IGauge Gauge(IGauge parent, string instance) { return(new DefaultGauge(parent, instance)); }
protected override void Visit(IGauge gauge) { sb.AppendFormat("{0} ({1}/{2})", gauge.Value, gauge.Min, gauge.Max); }
protected abstract void Visit(IGauge gauge);
public InProgressTracker(IGauge gauge) { _gauge = gauge; }
public IGauge Gauge(IGauge parent, string instance) { return new DefaultGauge(parent, instance); }
public Timer(IGauge gauge) { _gauge = gauge; _stopwatch = System.Diagnostics.Stopwatch.StartNew(); }