Smdn.Net.MuninNode.Hosting 3.1.0

Prefix Reserved
dotnet add package Smdn.Net.MuninNode.Hosting --version 3.1.0
                    
NuGet\Install-Package Smdn.Net.MuninNode.Hosting -Version 3.1.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.1.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.1.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.1.0
                    
#r "nuget: Smdn.Net.MuninNode.Hosting, 3.1.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.1.0
                    
Install as a Cake Addin
#tool nuget:?package=Smdn.Net.MuninNode.Hosting&version=3.1.0
                    
Install as a Cake Tool

Smdn.Net.MuninNode.Hosting 3.1.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 PluginGraphAttributesBuilder(title: "Temperature")
                  .WithCategory(WellKnownCategory.Sensor)
                  .WithVerticalLabel("Degree Celsius")
                  .WithGraphLimit(0, 50)
                  .Build()
              )
            );
            // 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.1.0 (net8.0)

// Smdn.Net.MuninNode.Hosting.dll (Smdn.Net.MuninNode.Hosting-3.1.0)
//   Name: Smdn.Net.MuninNode.Hosting
//   AssemblyVersion: 3.1.0.0
//   InformationalVersion: 3.1.0+d9b937573b3b1dd41eaf878498bcf5d285c10471
//   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.5.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.Diagnostics.CodeAnalysis;
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 static IServiceCollection AddHostedMuninNodeService<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] TMuninNodeBackgroundService, TMuninNode, TMuninNodeOptions, TMuninNodeBuilder>(this IServiceCollection services, Action<TMuninNodeOptions> configureNode, Func<IMuninServiceBuilder, string, TMuninNodeBuilder> createNodeBuilder, Action<TMuninNodeBuilder> buildNode) where TMuninNodeBackgroundService : MuninNodeBackgroundService where TMuninNode : class, IMuninNode where TMuninNodeOptions : MuninNodeOptions, new() where TMuninNodeBuilder : MuninNodeBuilder {}
    public static IServiceCollection AddHostedMuninNodeService<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] TMuninNodeBackgroundService, TMuninNodeBuilder>(this IServiceCollection services, Func<IMuninServiceBuilder, TMuninNodeBuilder> buildMunin) where TMuninNodeBackgroundService : MuninNodeBackgroundService where TMuninNodeBuilder : MuninNodeBuilder {}
    public static IServiceCollection AddHostedMuninNodeService<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] TMuninNodeBackgroundService, TMuninNodeService, TMuninNodeImplementation, TMuninNodeOptions, TMuninNodeBuilder>(this IServiceCollection services, Action<TMuninNodeOptions> configureNode, Func<IMuninServiceBuilder, string, TMuninNodeBuilder> createNodeBuilder, Action<TMuninNodeBuilder> buildNode) where TMuninNodeBackgroundService : MuninNodeBackgroundService where TMuninNodeService : class, IMuninNode where TMuninNodeImplementation : class, TMuninNodeService where TMuninNodeOptions : MuninNodeOptions, new() where TMuninNodeBuilder : MuninNodeBuilder {}
  }

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

    public EndPoint EndPoint { get; }
    protected ILogger? Logger { get; }

    public override void Dispose() {}
    protected override async Task ExecuteAsync(CancellationToken stoppingToken) {}
    public override async Task StartAsync(CancellationToken cancellationToken) {}
    public override async Task StopAsync(CancellationToken cancellationToken) {}
  }
}
// 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.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.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 (1)

Showing the top 1 NuGet packages that depend on Smdn.Net.MuninNode.Hosting:

Package Downloads
Smdn.Net.SmartMeter.Extensions.Munin

Provides a mechanism for graphing data collected from **low-voltage smart electric energy meter** via **route-B** using Munin. More specifically, this library provides a `SmartMeterMuninNode` class that functions as a Munin node. This class enables Munin to collect and graph data aggregated from **low-voltage smart electricity meters**. This library also provides a `BackgroundService` implementation that allows the Munin node implementation to run on any host environment. 「Bルート」を介して「低圧スマート電力量メータ」から収集したデータを、Muninによってグラフ化するための手段を提供します。 具体的には、このライブラリではMuninノードとして機能する`SmartMeterMuninNode`クラスを提供します。 このクラスを使用することで、「低圧スマート電力量メータ」から収集したデータをMuninが集計・グラフ化できるようにします。 またこのライブラリでは、同Muninノードの実装を任意のホスト環境で動作させるための`BackgroundService`の実装も提供します。

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
3.1.0 190 6/1/2025
3.0.0 181 5/1/2025