Smdn.Net.MuninNode.Hosting 3.0.0

Prefix Reserved
dotnet add package Smdn.Net.MuninNode.Hosting --version 3.0.0
                    
NuGet\Install-Package Smdn.Net.MuninNode.Hosting -Version 3.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Smdn.Net.MuninNode.Hosting" Version="3.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Smdn.Net.MuninNode.Hosting" Version="3.0.0" />
                    
Directory.Packages.props
<PackageReference Include="Smdn.Net.MuninNode.Hosting" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Smdn.Net.MuninNode.Hosting --version 3.0.0
                    
#r "nuget: Smdn.Net.MuninNode.Hosting, 3.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#addin nuget:?package=Smdn.Net.MuninNode.Hosting&version=3.0.0
                    
Install Smdn.Net.MuninNode.Hosting as a Cake Addin
#tool nuget:?package=Smdn.Net.MuninNode.Hosting&version=3.0.0
                    
Install Smdn.Net.MuninNode.Hosting as a Cake Tool

Smdn.Net.MuninNode.Hosting 3.0.0

A .NET implementation of Munin-Node for .NET Generic Host.

This library provides APIs to run Munin-Node as a background service running on a .NET Generic Host.

This library mainly provides a MuninNodeBackgroundService class derived from BackgroundService, and extension methods to register the Munin-Node service to the ServiceCollection.

This library uses Smdn.Net.MuninNode and the API is provided as an extension to Smdn.Net.MuninNode.

Getting started

First, add the Smdn.Net.MuninNode.Hosting package and any other packages you need to the project file.

dotnet add package Smdn.Net.MuninNode.Hosting
dotnet add package Microsoft.Extensions.Hosting
dotnet add package Microsoft.Extensions.Logging.Console

Using the API of the Smdn.Net.MuninNode.DependencyInjection and Smdn.Net.MuninNode.Hosting namespaces, and the HostApplicationBuilder, WebApplicationBuilder and so on, you can configure and run a Munin-Node as a hosted service in the following way.

using System;
using System.Threading;
using System.Threading.Tasks;

using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;

using Smdn.Net.MuninNode;
using Smdn.Net.MuninNode.DependencyInjection;
using Smdn.Net.MuninNode.Hosting;
using Smdn.Net.MuninPlugin;

// A interface/class that gets the measurements from some kind of sensor.
interface ITemperatureSensor {
  double GetMeasurementValue();
}

class TemperatureSensor : ITemperatureSensor {
  public double GetMeasurementValue() => Random.Shared.Next(20, 30); // 20~30 degree Celsius
}

class Program {
  static async Task Main(string[] args)
  {
    var builder = Host.CreateApplicationBuilder(args);

    builder
      .Services
        // Add sensor devices.
        .AddKeyedSingleton<ITemperatureSensor>("sensor1", new TemperatureSensor())
        .AddKeyedSingleton<ITemperatureSensor>("sensor2", new TemperatureSensor())
        // Add a Munin-Node background service.
        .AddHostedMuninNodeService(
          // Configure the Munin-Node options.
          options => {
            options.HostName = "munin-node.localhost";
            options.UseAnyAddress(port: 14949);
            options.AllowFromLoopbackOnly();
          },
          // Build the Munin-Node.
          nodeBuilder => {
            // Create and add a Munin-Plugin to report measurements via the Munin-Node.
            nodeBuilder.AddPlugin(
              serviceProvider => PluginFactory.CreatePlugin(
                name: "temperature",
                // Configure the 'fields' that identify the data source.
                // See: https://guide.munin-monitoring.org/en/latest/reference/plugin.html#data-source-attributes
                fields: [
                  PluginFactory.CreateField(
                    label: "sensor1",
                    fetchValue: () => serviceProvider
                      .GetRequiredKeyedService<ITemperatureSensor>("sensor1")
                      .GetMeasurementValue()
                  ),
                  PluginFactory.CreateField(
                    label: "sensor2",
                    fetchValue: () => serviceProvider
                      .GetRequiredKeyedService<ITemperatureSensor>("sensor2")
                      .GetMeasurementValue()
                  ),
                ],
                // Configures the 'attributes' of the graph when drawn data as a graph.
                // See: https://guide.munin-monitoring.org/en/latest/reference/plugin.html#global-attributes
                graphAttributes: new PluginGraphAttributes(
                  category: "sensors",
                  title: "Temperature",
                  verticalLabel: "Degree Celsius",
                  scale: false,
                  arguments: "--base 1000 --lower-limit 0 --upper-limit 50"
                )
              )
            );
            // One or more plug-ins can be added.
            // nodeBuilder.AddPlugin(...);
            // nodeBuilder.AddPlugin(...);
          }
        )
        // Add other services.
        .AddLogging(builder => builder
          .AddSimpleConsole(static options => {
            options.SingleLine = true;
            options.IncludeScopes = true;
          })
          .AddFilter(static level => LogLevel.Trace <= level)
        );

    // Build and run app.
    using var app = builder.Build();

    await app.RunAsync();
  }
}

Contributing

This project welcomes contributions, feedbacks and suggestions. You can contribute to this project by submitting Issues or Pull Requests on the GitHub repository.

API List

List of APIs exposed by assembly Smdn.Net.MuninNode.Hosting-3.0.0 (net8.0)

// Smdn.Net.MuninNode.Hosting.dll (Smdn.Net.MuninNode.Hosting-3.0.0)
//   Name: Smdn.Net.MuninNode.Hosting
//   AssemblyVersion: 3.0.0.0
//   InformationalVersion: 3.0.0+0830d2fdea4a5b05d99958b5116ff7b474590f2f
//   TargetFramework: .NETCoreApp,Version=v8.0
//   Configuration: Release
//   Referenced assemblies:
//     Microsoft.Extensions.DependencyInjection.Abstractions, Version=8.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60
//     Microsoft.Extensions.Hosting.Abstractions, Version=8.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60
//     Microsoft.Extensions.Logging.Abstractions, Version=8.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60
//     Smdn.Net.MuninNode, Version=2.2.0.0, Culture=neutral
//     System.Net.Primitives, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
//     System.Runtime, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
#nullable enable annotations

using System;
using System.Net;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Smdn.Net.MuninNode;
using Smdn.Net.MuninNode.DependencyInjection;
using Smdn.Net.MuninNode.Hosting;

namespace Smdn.Net.MuninNode.Hosting {
  public static class IServiceCollectionExtensions {
    public static IServiceCollection AddHostedMuninNodeService(this IServiceCollection services, Action<MuninNodeOptions> configureNode, Action<IMuninNodeBuilder> buildNode) {}
  }

  public class MuninNodeBackgroundService : BackgroundService {
    public MuninNodeBackgroundService(IMuninNode node) {}
    public MuninNodeBackgroundService(IMuninNode node, ILogger<MuninNodeBackgroundService>? logger) {}

    public EndPoint EndPoint { get; }

    public override void Dispose() {}
    protected override async Task ExecuteAsync(CancellationToken stoppingToken) {}
  }
}
// API list generated by Smdn.Reflection.ReverseGenerating.ListApi.MSBuild.Tasks v1.5.0.0.
// Smdn.Reflection.ReverseGenerating.ListApi.Core v1.3.1.0 (https://github.com/smdn/Smdn.Reflection.ReverseGenerating)
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed. 
.NET Core netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
3.0.0 125 5/1/2025