GitXplorerGitXplorer
D

prometheus-net.SystemMetrics

public
34 stars
5 forks
3 issues

Commits

List of commits on branch master.
Unverified
92d7937d56d44de9c5f890734494371d40d12ed0

use correct framework

kkasperk81 committed 4 months ago
Unverified
4f9c254784ea7fb981cc33db5aa1341f8cb07bee

Switch P/Invokes to use LibraryImport in .NET 7.0 and above.

DDaniel15 committed 8 months ago
Unverified
07689dcae892c04eeb648fb45a3781efe8048e9d

Remove Mono.Posix import by calling libc directly.

DDaniel15 committed 8 months ago
Unverified
9a4492924c3e08521899bb8636a5f052c840cb01

Add support for AOT compilation

DDaniel15 committed 8 months ago
Unverified
26ea9bb4e2b803258b2d8c7ea375c4979511af7c

Fix CA1416 warnings by explicitly checking for Windows OS

DDaniel15 committed 8 months ago
Unverified
22bd3bf3871c42361cff2f13c17a9c7a4615a3fb

v3.0.0

DDaniel15 committed 10 months ago

README

The README file for this repository.

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

3.0.0 - 30th November 2023

  • Bumped to .NET 8.0.
  • Bumped prometheus-net dependency to version 8.
  • Wrapped metric collector creation in try-catch so that one collector failing doesn't break the whole app.
  • Updated Windows memory counters so their names more closely match the Linux version. Notably, node_memory_MemFree is now node_memory_MemAvailable_bytes, and node_memory_MemTotal is now node_memory_MemTotal_bytes. Currently, both the old and new counters exist (for backwards compatibility), but the old ones will be removed in the next major version.

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.