prometheus-net.SystemMetrics 2.0.0

.NET Standard 2.0 .NET Framework 4.6.1
Install-Package prometheus-net.SystemMetrics -Version 2.0.0
dotnet add package prometheus-net.SystemMetrics --version 2.0.0
<PackageReference Include="prometheus-net.SystemMetrics" Version="2.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add prometheus-net.SystemMetrics --version 2.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: prometheus-net.SystemMetrics, 2.0.0"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. Copy this into the interactive tool or source code of the script to reference the package.
// Install prometheus-net.SystemMetrics as a Cake Addin
#addin nuget:?package=prometheus-net.SystemMetrics&version=2.0.0

// Install prometheus-net.SystemMetrics as a Cake Tool
#tool nuget:?package=prometheus-net.SystemMetrics&version=2.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

prometheus-net SystemMetrics

NuGet version  Build Status

prometheus-net SystemMetrics allows you to export various system metrics (such as CPU usage, disk usage, etc) from your .NET application to Prometheus. It is designed to be a very lightweight alternative to node_exporter, only containing essential metrics. This is useful on systems with limited RAM or where it is easier to add this library to your app instead of deploying a totally separate service.

Usage

Install the prometheus-net.SystemMetrics library using NuGet.

Add the services to your Startup.cs:

using Prometheus.SystemMetrics;

public void ConfigureServices(IServiceCollection services)
{
    // ...
    services.AddSystemMetrics();
}

If you have not already done so, you will also need to expose the Prometheus metrics endpoint by calling MapMetrics in Configure:

public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
    // ...
    app.UseRouting();
    app.UseEndpoints(endpoints =>
    {
        endpoints.MapMetrics();
        // ...
    });
}

After doing this, going to /metrics should return the new metrics.

Customization

By default, this will add all the collectors. To only add some collectors, you can instead only render the collectors you want to use:

services.AddSystemMetrics(registerDefaultCollectors: false);
services.AddSystemMetricCollector<CpuUsageCollector>();

Metrics

Where possible, metrics have the same name and format as node_exporter.

CPU

The number of seconds the CPU has spent in each mode (system, user, idle, etc). Available on Linux and Windows. Example data:

node_cpu_seconds_total{cpu="0",mode="system"} 172.35
node_cpu_seconds_total{cpu="0",mode="user"} 292.27
node_cpu_seconds_total{cpu="0",mode="idle"} 30760.4

Disk

The amount of free disk space on all mounts. Available on all platforms. Example data:

# Linux
node_filesystem_avail_bytes{mountpoint="/",fstype="ext4"} 57061916672

# Windows
node_filesystem_avail_bytes{mountpoint="C:\\",fstype="NTFS"} 101531594752

Load Average

Available on Linux. Example data:

node_load1 0.06
node_load5 0.03
node_load15 0.26

Memory

Stats such as available RAM, RAM used by caches, etc. Available on Linux and Windows. Example data:

node_memory_MemAvailable_bytes 1527701504
node_memory_Cached_bytes 572964864
node_memory_MemFree_bytes 961966080
node_memory_MemTotal_bytes 2085904384

Network

Total amount of data sent and received over the network. Available on all platforms. Example data:

node_network_transmit_bytes_total{device="eth0"} 3053723
node_network_receive_bytes_total{device="eth0"} 5822231

Changelog

2.0.0 - 8th October 2021

  • Added memory and CPU collectors for Windows (thanks to @masterworgen for the initial implementation in PR #3)
  • Added .NET Framework 4.6.2 builds, since prometheus-net itself supports this framework version.

1.0.1 - 17th May 2020

  • Added memory stats for Linux
  • Added total file size to disk collector
Product Versions
.NET net5.0 net5.0-windows net6.0 net6.0-android net6.0-ios net6.0-maccatalyst net6.0-macos net6.0-tvos net6.0-windows
.NET Core netcoreapp2.0 netcoreapp2.1 netcoreapp2.2 netcoreapp3.0 netcoreapp3.1
.NET Standard netstandard2.0 netstandard2.1
.NET Framework net461 net462 net463 net47 net471 net472 net48
MonoAndroid monoandroid
MonoMac monomac
MonoTouch monotouch
Tizen tizen40 tizen60
Xamarin.iOS xamarinios
Xamarin.Mac xamarinmac
Xamarin.TVOS xamarintvos
Xamarin.WatchOS xamarinwatchos
Compatible target framework(s)
Additional computed target framework(s)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (4)

Showing the top 4 NuGet packages that depend on prometheus-net.SystemMetrics:

Package Downloads
NPitaya

A full implementation of pitaya backend framework for .NET

Convey.Metrics.Prometheus

Convey.Metrics.Prometheus

NetCoreCleanArchitecture.WebHosting

Package Description

Flour.Metrics.Prometheus

Package Description

GitHub repositories (2)

Showing the top 2 popular GitHub repositories that depend on prometheus-net.SystemMetrics:

Repository Stars
microsoft/fhir-server
A service that implements the FHIR standard
snatch-dev/Convey
A simple recipe for .NET Core microservices.
Version Downloads Last updated
2.0.0 204,821 8/9/2021
1.0.1 375,032 5/17/2020
1.0.0 546 5/15/2020