Giter Club home page Giter Club logo

influxdb-csharp's Introduction

InfluxDB .NET Collector

Build status NuGet Version License GitHub issues GitHub pull requests Slack Status

Note: This library is for use with InfluxDB 1.x. For connecting to InfluxDB 2.x instances, please use the influxdb-client-csharp client.

This is a C# implementation of the InfluxDB ingestion 'Line Protocol'.

You can use it to write time series data to InfluxDB version 0.9.3+ over HTTP or HTTPS. Two packages are provided:

  • A higher-level metrics-oriented API described in Getting Started below
  • A bare-bones HTTP line protocol client, described in the Raw Client API section

Supporting the full/read API of InfluxDB is an explicit non-goal: this package will be kept small so as to have a minimal footprint when used in client applications.

Getting Started

Install the InfluxDB.Collector NuGet package:

Install-Package InfluxDB.Collector

Add using statements where needed:

using InfluxDB.Collector;

Configure a MetricsCollector. These can be used directly, or via the static Metrics class:

Metrics.Collector = new CollectorConfiguration()
    .Tag.With("host", Environment.GetEnvironmentVariable("COMPUTERNAME"))
    .Batch.AtInterval(TimeSpan.FromSeconds(2))
    .WriteTo.InfluxDB("http://192.168.99.100:8086", "data")
    .CreateCollector();

Send points using the methods of MetricsCollector or Metrics:

Metrics.Increment("iterations");

Metrics.Write("cpu_time",
    new Dictionary<string, object>
    {
        { "value", process.TotalProcessorTime.TotalMilliseconds },
        { "user", process.UserProcessorTime.TotalMilliseconds }
    });

Metrics.Measure("working_set", process.WorkingSet64);

View aggregated metrics in a dashboarding interface such as Chronograf or Grafana.

Raw Client API

The raw API is a very thin wrapper on InfluxDB's HTTP API, in the InfluxDB.LineProtocol package.

Install-Package InfluxDB.LineProtocol

To send points, create a LineProtocolPayload containing a batch of LineProtocolPoints. Each point carries the measurement name, at least one value, an optional set of tags and an optional timestamp:

var cpuTime = new LineProtocolPoint(
    "working_set",
    new Dictionary<string, object>
    {
        { "value", process.WorkingSet64 },
    },
    new Dictionary<string, string>
    {
        { "host", Environment.GetEnvironmentVariable("COMPUTERNAME") }
    },
    DateTime.UtcNow);

var payload = new LineProtocolPayload();
payload.Add(cpuTime);
// Add more points...

(If the timestamp is not specified, the InfluxDB server will assign a timestamp to each point on arrival.)

Write the points to InfluxDB, specifying the server's base URL, database name, and an optional username and password:

var client = new LineProtocolClient(new Uri("http://my-server:8086"), "data");
var influxResult = await client.WriteAsync(payload);
if (!influxResult.Success)
    Console.Error.WriteLine(influxResult.ErrorMessage);

Diagnostics

The collector will not throw exceptions when communication errors occur. To be notified of metric collection issues, register an error handler:

CollectorLog.RegisterErrorHandler((message, exception) =>
{
    Console.WriteLine($"{message}: {exception}");
});

Status

This project is still undergoing some change while in development, but the core functionality is stabilizing. See issues tagged enhancement for roadmap items. It's currently targeting .NET 4.5.1 and .NET Core using Visual Studio 2017.

influxdb-csharp's People

Contributors

nblumhardt avatar gambrose avatar trevhunter avatar bednar avatar optical avatar bnayae avatar sidhoda avatar hakanl avatar tukaef avatar alexmg avatar e-dard avatar sidhoda-nortech avatar cypressious avatar stmax82 avatar michael-wolfenden avatar rhajek avatar russorat avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.