Giter VIP home page Giter VIP logo

influxclient's Introduction

InfluxClient Build status NuGet

A .NET InfluxDB client that supports asynchronous IO, the v0.9 API and greater, the line protocol for efficient logging, and InfluxDB authentication

Quick Start

Install the NuGet package from the package manager console:

Install-Package InfluxClient

Be sure your project has a reference to System.Net.Http (for the HttpResponseMessage class)

Logging a measurement

In your application, call:

// Create the InfluxManager, passing the InfluxDB endpoint and target database:
InfluxManager mgr = new InfluxManager("http://YOURSERVER:8086/", "YOUR_DATABASE");

// Create a measurement (with a name and at least one field name and value)
Measurement m = new Measurement("unittest").AddField("count", 42);

// Write the measurement (notice that this is awaitable):
var retval = await mgr.Write(m);

Exceptions

Logging and telemetry is usually a secondary function in an application -- so by default, InfluxClient tries to be as quiet as possible when handling error conditions. InfluxClient won't throw exceptions for anything unless you indicate it's OK to do so.

You can control this behavior in the constructor:

// Create the influx client and indicate we want to have exceptions bubble up:
InfluxManager mgr = new InfluxManager(_influxEndpoint, _influxDatabase, true);
// Just add a parameter to your constructor                             ^^^^

The client will always try to signal with Trace output when something goes wrong -- so you should be able to trap this in your application logging toolkit (or see it in your debugging output) without too much effort -- even if you have exceptions turned off.

Reading measurements

Based on your provided InfuxQL query, InfluxDB passes data back in JSON format. You can either get the raw string back or use the helper methods to get a native object back.

To get the JSON back:

// Create the InfluxManager, passing the InfluxDB endpoint and target database:
InfluxManager mgr = new InfluxManager("http://YOURSERVER:8086/", "YOUR_DATABASE");

// Pass in your InfluxQL query (notice that this is awaitable)
HttpResponseMessage retval = await mgr.QueryJSON("select * from unittest");

// Get the raw JSON data passed back:
data = await retval.Content.ReadAsStringAsync();

To get a QueryResponse object back:

// Create the InfluxManager, passing the InfluxDB endpoint and target database:
InfluxManager mgr = new InfluxManager("http://YOURSERVER:8086/", "YOUR_DATABASE");

// Pass in your InfluxQL query (notice that this is awaitable)
var retval = await mgr.Query("select * from unittest");

// You now have your data back:
string seriesTitle = retval.Results[0].Series[0].Name;

Using authentication

Using authentication is as simple as passing in your username and password as part of the InfluxManager constructor:

// To authenticate, create the InfluxManager with additional parameters:
InfluxManager mgr = new InfluxManager("http://YOURSERVER:8086/", "YOUR_DATABASE", "user", "password");

// Continue normally ... create a measurement (with a name and at least one field name and value)
Measurement m = new Measurement("unittest").AddField("count", 42);

// Write the measurement (notice that this is awaitable):
var retval = await mgr.Write(m);

influxclient's People

Contributors

andymac4182 avatar danesparza avatar marcinsikora avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

influxclient's Issues

How to read?

Is there no method available to run a query???

Ability to specify Action for logging errors

What do you think of the idea of being able to supply an Action that will log the errors to the logging framework the end developer is using without throwing the error. This would be ideal for the apps I work on so I can see the errors without having an error from InfluxClient bubbling up to my app.

The Action would take 2 parameters exception and message. This idea came from how https://github.com/uglybugger/NotDeadYet/blob/63eebdf883020896efcefee9c4209ae22b4850c9/src/NotDeadYet/Configuration/HealthCheckerConfiguration.cs#L9 handles logging.

I would be happy to look at implementing this if you liked the idea.

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.