Code Monkey home page Code Monkey logo

influxdb.net's Introduction

InfluxDB.Net

InfluxDB An open-source distributed time series database with no external dependencies. It is the new home for all of your metrics, events, and analytics.

A Portable .NET library to access the REST API of a InfluxDB database.

Installation

Install-Package InfluxDB.Net-Main

.NET Core Installation

dotnet add package InfluxDB.Net.Core --version 1.1.22-beta

Versions of InfluxDB
The currently supported versions of InfluxDB is 0.9 - 1.1. When creating a connection to the database you can specify the version to use, or the auto configuration that starts by determening the version.

List of supported methods

  • Ping
  • Version
  • CreateDatabase
  • DeleteDatabase
  • DescribeDatabases
  • Write
  • Query
  • CreateClusterAdmin(User user);
  • DeleteClusterAdmin(string name);
  • DescribeClusterAdmins();
  • UpdateClusterAdmin(User user, string name);
  • CreateDatabaseUser(string database, User user);
  • DeleteDatabaseUser(string database, string name);
  • DescribeDatabaseUsers(String database);
  • UpdateDatabaseUser(string database, User user, string name);
  • AuthenticateDatabaseUser(string database, string user, string password);
  • GetContinuousQueries(String database);
  • DeleteContinuousQuery(string database, int id);
  • DeleteSeries(string database, string name);
  • ForceRaftCompaction();
  • Interfaces();
  • Sync();
  • ListServers();
  • RemoveServers(int id);
  • CreateShard(Shard shard);
  • GetShards();
  • DropShard(int id, Shard.Member servers);
  • GetShardSpaces();
  • DropShardSpace(string database, string name);
  • CreateShardSpace(string database, ShardSpace shardSpace);

Ping

var _client = new InfluxDb("http://...:8086", "root", "root");
  Pong pong =await _client.PingAsync();

Version

var _client = new InfluxDb("http://...:8086", "root", "root");
  string version =await  _client.VersionAsync();

Create Database

var _client = new InfluxDb("http://...:8086", "root", "root");
 InfluxDbApiCreateResponse response =await  _client.CreateDatabaseAsync("MyDb");
 //Or
 InfluxDbApiCreateResponse response = await _client.CreateDatabaseAsync(new DatabaseConfiguration
            {
                Name = "MyDb"
            });

Delete Database

var _client = new InfluxDb("http://...:8086", "root", "root");
InfluxDbApiDeleteResponse deleteResponse = await _client.DeleteDatabaseAsync("MyDb");

Describe Databases

var _client = new InfluxDb("http://...:8086", "root", "root");
List<Database> databases = await _client.ShowDatabasesAsync();

Write

var _client = new InfluxDb("http://...:8086", "root", "root");
Serie serie = new Serie.Builder("testSeries")
                .Columns("value1", "value2")
                .Values(DateTime.Now.Millisecond, 5)
                .Build();
InfluxDbApiResponse writeResponse =await _client.WriteAsync("MyDb", TimeUnit.Milliseconds, serie);

Query

var _client = new InfluxDb("http://...:8086", "root", "root");
 List<Serie> series = await _client.QueryAsync("MyDb", "select * from testSeries"), TimeUnit.Milliseconds);

Bugs

If you encounter a bug, performance issue, or malfunction, please add an Issue with steps on how to reproduce the problem.

##PowerShell Cmdlet The PowerShell Cmdlet can be tested using the script TestInfluxDb.ps1.

Installation
import-module [PATH]\InfluxDb -force

Open

$db = Open-InfluxDb -Uri:"http://...:8086" -User:"root" -Password:"root"

Ping

$pong = Ping-InfluxDb -Connection:$db

Add
Adds a new database.

Add-InfluxDb -Connection:$db -Name:"SomeDatabase"

Write
Not yet implemented

Write-InfluxDb

influxdb.net's People

Contributors

aschaible avatar bugthesystem avatar chrisguest75 avatar jamesholcomb avatar jlucansky avatar josephwoodward avatar kirillkovalenko avatar kn4ck3r avatar poxet avatar schmitzt3 avatar tihomir-kit avatar tweir avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

influxdb.net's Issues

Allow connecting to an unauthenticated InfluxDB

Currently the InfluxDbClientConfiguration fails on empty username/password. It's possible to have InfluxDB instances unprotected, so the validation shouldn't be as strict.

I propose removing the validation for the username/password fields.

Create database tip use post

` InfluxVersion influxVersion;
if (!Enum.TryParse(ConfigurationManager.AppSettings.Get("version"), out influxVersion))
influxVersion = InfluxVersion.Auto;
_influx = new InfluxDb("http://localhost:8086", "admin", "admin", influxVersion);

        var createResponse = _influx.CreateDatabaseAsync("zbTestDB").Result;
        Console.WriteLine(createResponse.Body);

`
createResponse.Body:
{"results":[{"statement_id":0,"messages":[{"level":"warning","text":"deprecated use of 'CREATE DATABASE TestDB' in a read only context, please use a POST request instead"}]}]}

the "TestDB" had created,but i can't Write

Missing Newtonsoft.JSON as a dependency?

 System.AggregateException: One or more errors occurred. ---> System.IO.FileNotFoundException: Could not load file or assembly 'Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. The system cannot find the file specified.
   at LibInfluxDB.Net.ObjectExtensions.ReadAs[T](InfluxDbApiResponse response)
   at LibInfluxDB.Net.InfluxDb.<PingAsync>d__0.MoveNext()
   --- End of inner exception stack trace ---

Access to sockets forbidden by its access policy

Hi!

First - thanks for the library, really nice work so far. The library made my life easier. :)

Well, I stumbled upon a problem. We have a .net webapp hosted on Azure (currently Basic B1 tier) and the InfluxDB is running in an Azure Linux VM instance. Recently we started noticing the following error:

» 2 Sep 2015 09:44:01.733 Wed Sep 02 08:44:02.3041 +00:00 2015 <Namespace>.Business.Services.ReadingService : Error, System.Net.Http.HttpRequestException: An error occurred while sending the request. 
---> System.Net.WebException: Unable to connect to the remote server 
---> System.Net.Sockets.SocketException: An attempt was made to access a socket in a way forbidden by its access permissions at System.Net.Sockets.Socket.DoBind(EndPoint endPointSnapshot, SocketAddress socketAddress) at System.Net.Sockets.Socket.InternalBind(EndPoint localEP) at System.Net.Sockets.Socket.BeginConnectEx(EndPoint remoteEP, Boolean flowContext, AsyncCallback callback, Object state) at System.Net.Sockets.Socket.UnsafeBeginConnect(EndPoint remoteEP, AsyncCallback callback, Object state) at System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Exception& exception) 
--- End of inner exception stack trace 
--- at System.Net.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult) at System.Net.Http.HttpClientHandler.GetResponseCallback(IAsyncResult ar) 
--- End of inner exception stack trace 
--- at Microsoft.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at Microsoft.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccess(Task task) at Microsoft.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task) at Microsoft.Runtime.CompilerServices.TaskAwaiter`1.GetResult() at InfluxDB.Net.InfluxDb.<QueryAsync>d__f.MoveNext() 
--- End of stack trace from previous location where exception was thrown 
--- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task) at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult() at <Namespace>.Business.Services.InfluxDbService.<QueryReading>d__20.MoveNext() in c:\BuildAgent\work\1b725b0f890f9b97\<Namespace>.Business\Services\InfluxDbService.cs:line 227 
--- End of stack trace from previous location where exception was thrown 
--- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task) at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult() at <Namespace>.Business.Services.InfluxDbService.<GetLastReadings>d__f.MoveNext() in c:\BuildAgent\work\1b725b0f890f9b97\<Namespace>.Business\Services\InfluxDbService.cs:line 129 
--- End of stack trace from previous location where exception was thrown 
--- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task) at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult() at <Namespace>.Business.Services.InfluxDbService.<GetLastReading>d__a.MoveNext() in c:\BuildAgent\work\1b725b0f890f9b97\<Namespace>.Business\Services\InfluxDbService.cs:line 100 
--- End of stack trace from previous location where exception was thrown 
--- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task) at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult() at <Namespace>.Business.Services.ReadingService.<ResolveSensorReading>d__13.MoveNext() in c:\BuildAgent\work\1b725b0f890f9b97\<Namespace>.Business\Services\ReadingService.cs:line 95 Context

Which boils down to the following message: "An attempt was made to access a socket in a way forbidden by its access permissions at System.Net.Sockets.Socket.DoBind"

I googled it up and at first it seemed that the connections are being refused by the InfluxDB VM, but after I tried to reproduce the thing from my dev machine, I couldn't. I made a lot more requests from my dev machine than from what I needed to do with the production, and I didn't see the same symptoms. That led me to believe that the problem was not in the InfluxDB instance but in some kind of Azure website limitation.

I used these two netstat commands on InfluxDB to monitor connections on the InfluxDB VM..

This one gives connection counts per IP:

watch "netstat -plan|grep :80|awk {'print \$5'} | cut -d: -f 1 | sort | uniq -c | sort -nk 1"

So, something like:

30 one_ip
3138 another_ip

And this one gives counts by tcp connection status:

netstat -tn | awk 'NR>2 {print $6}' | sort | uniq -c | sort -rn

And something like:

285 TIME_WAIT
1802 FIN_WAIT2
82 ESTABLISHED
3 FIN_WAIT1
2 SYN_RECV

In production, after I got at about ~1500 FIN_WAIT2 (which basically means that the server is waiting for the connection to be closed (and the client acknowledged that it know it can close the connection), I would start seeing the access to socket being forbidden message. In essence - lingering connections remain, and it takes them up to 3 minutes to clean themselves up.

On my dev machine FIN_WAIT2 went all the way up to ~10000 and everything still worked fine and I didn't want to wait any more so I stopped the test.

Then I decided to take a look into your code and noticed that you're not disposing the HttpClient after you get the response from the InfluxDB server (at RequestInnerAsync()). I checked on SO whether HttpClient should be disposed after usage and it seems that unless it's being reused for later. In the case of InfluxDB.Net, I guess it should be disposed then. I tried disposing the HttpClient, the request and the response objects and it didn't help. Then I decided to try and set the requestTimeout from RequestAsync (I set it to 5 seconds), but that didn't change anything either (FIN_WAIT2 didn't go away earlier because of that). The last thing I tried was to make a singleton wrapper around HttpClient like this:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Text;

namespace InfluxDB.Net
{
    public class HttpClientSingletonWrapper : HttpClient
    {
        private static readonly Lazy<HttpClientSingletonWrapper> Lazy = new Lazy<HttpClientSingletonWrapper>(() => new HttpClientSingletonWrapper());

        public static HttpClientSingletonWrapper Instance { get { return Lazy.Value; } }

        private HttpClientSingletonWrapper()
        {

        }
    }
}

But this didn't help either. So now I'm kind of out of options and was hoping you might have an idea or suggestion on how to solve this? If you need any additional info, I'll gladly provide it. I would like to get to the bottom of this because someone else might have the same problem in the future, so it would be good if we were able to fix this. :)

Additional links:

Thanks!

Uri Parameter are not escaped

The method InfluxDbClientBase.BuildUri escapes username and password but not the extra parameters.

I ran a select query which contained the character ':'. The server responed with a parsing error. Then I changed the code to HttpUtility.UrlEncode(param.Value) but it didn't work because the ':' was not escaped. Then I changed HttpUtility.UrlEncode to use Uri.EscapeDataString. Now everything was escaped correctly and the server accepted the query.

I haven't created a pull request because I'm not sure if this was the correct way to go.

Inserting string values like "with space" result in "with\ space"

I'm not able to implement the following insert:
INSERT cpu,host=serverA,region=us_west value="with space"
or via REST:
curl -i -XPOST 'http://localhost:8086/write?db=mydb' --data-binary 'cpu,host=server02 value="with space"

Could you verify and post a piece of code to not escape spaces with "\ "?

Need Help: Unable to read data from the transport connection: The connection was closed.

Hi,

We are using the library InfluxDB.Net Release 8.0.1 to read data from Influx DB hosted in the cloud. We have 1-minute interval data stored in the cloud database. We have a requirement to generate .csv report based on user request. The REST call works seamlessly for MultiQueryAsync (190 Queries, each query reading different Data Point) for three weeks worth of data. i.e 190 Columns * 1446 Rows per day * 21 = 5,769,540 data points.

However when we try to read a month worth of Data: the Influx DB call fails with the below exception
InnerException = {"Unable to read data from the transport connection: The connection was closed."}

at System.Net.ConnectStream.EndRead(IAsyncResult asyncResult)
at System.IO.Stream.<>c.b__43_1(Stream stream, IAsyncResult asyncResult)
at System.Threading.Tasks.TaskFactory1.FromAsyncTrimPromise1.Complete(TInstance thisRef, Func`3 endMethod, IAsyncResult asyncResult, Boolean requiresSynchronization)
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Net.Http.HttpClientHandler.WebExceptionWrapperStream.d__4.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Net.Http.StreamToStreamCopy.d__3.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Net.Http.HttpContent.d__49.MoveNext()

If anyone has experience with resolving this issue please share your inputs. The Client Request is handled by WebAPI2.0, below is the code snippet.
image

Optimize write

Point is a class hosting other classes (i.e Dictionary) which is not exactly the best performer due to GC.
A struct, or even better, a readonly struct might be a better option when it comes to writes.

Can't Write Point with Empty String Tag

Hi!
I can't write a point containing a Tag with an empty string. I wrote the following unit test based on the existing ones:

        private Dictionary<string, object> EmptyStringTag()
        {
            return new Dictionary<string, object>
            {
                {"tag_string", string.Empty}
            };
        }
        [Test]
        public async Task DbWrite_OnPointWithEmptyStringTag_ShouldWritePoint()
        {
            var rnd = new Random();
            var fixture = new Fixture();
            fixture.Customize<Point>(c => c
                .With(p => p.Measurement, CreateRandomMeasurementName())
                .Do(p => p.Tags = EmptyStringTag())
                .Do(p => p.Fields = NewFields(rnd))
                .OmitAutoProperties());
            var points = fixture.CreateMany<Point>(1).ToArray();
            var timestamp = DateTime.UtcNow.AddDays(-5);
            foreach (var point in points)
            {
                timestamp = timestamp.AddMinutes(1);
                point.Timestamp = timestamp;
            }
            var writeResponse = await _influx.WriteAsync(_dbName, points);
            writeResponse.Success.Should().BeTrue();
        }

which failes with the Error:

InfluxDB.Net.Infrastructure.Influx.InfluxDbApiException : InfluxDb API responded with status code=BadRequest, response={"error":"unable to parse 'FakeMeasurement1517307523440,tag_string= field_bool=true,field_int=1446281079i,field_decimal=0.922650927176071,field_float=0.04777522,field_datetime=1517311123442 1516875583442': missing tag value"}

Compatibility with 0.9.0

Getting this error running the unit tests in both Xamarin 5.9.3 (Mono 4.0.1) and VS2015 RC1 against 0.9.0-rc31

InfluxDB.Net.InfluxDbApiException : InfluxDb API responded with status code=NotFound, response=404 page not found

curl works ok:

~/InfluxDB.Net [master|✚ 5…56] 
10:02 AM $ curl -G "http://localhost:8086/ping" -v
* Hostname was NOT found in DNS cache
*   Trying ::1...
* Connected to localhost (::1) port 8086 (#0)
> GET /ping HTTP/1.1
> User-Agent: curl/7.37.1
> Host: localhost:8086
> Accept: */*
> 
< HTTP/1.1 204 No Content
< Request-Id: f1c7a8db-0b93-11e5-8209-000000000000
< X-Influxdb-Version: 0.9.0-rc31
< Date: Fri, 05 Jun 2015 15:02:54 GMT
< 
* Connection #0 to host localhost left intact

doesnt work in wpf project

Hello:
I established a wpf project and using nuget to import the dll (1.0.46)to the project.but I found that there is no response when I new a instance of InfluxDb,There is not any excption throwed out. Coud u
help me solve this problem?

async support

As InfluxDB works over HTTP REST, it must be easy to make all client methods async by using HttpClient from Microsoft.Net.Http package. I am not using the library but if I needed it, I'd certainly seek for asynchronous call support as non-blocking io matters a lot nowadays.

Found memory leak in InfluxDbClientBase

This change fixed it. (HttpClient was never disposed)

private async Task RequestAsync(
IEnumerable errorHandlers,
HttpMethod method,
string path,
HttpContent content = null,
Dictionary<string, string> extraParams = null,
bool includeAuthToQuery = true,
bool headerIsBody = false,
TimeSpan? requestTimeout = null)
{
using (HttpClient client = GetHttpClient())
{
var response = await RequestInnerAsync(client, requestTimeout,
HttpCompletionOption.ResponseHeadersRead,
CancellationToken.None,
method,
path,
content,
extraParams,
includeAuthToQuery);

            string responseContent = String.Empty;

            if (!headerIsBody)
            {
                responseContent = await response.Content.ReadAsStringAsync();
            }
            else
            {
                IEnumerable<string> values;

                if (response.Headers.TryGetValues("X-Influxdb-Version", out values))
                {
                    responseContent = values.First();
                }
            }

            HandleIfErrorResponse(response.StatusCode, responseContent, errorHandlers);

            Debug.WriteLine("[Response] {0}", response.ToJson());
            Debug.WriteLine("[ResponseData] {0}", responseContent);

            return new InfluxDbApiResponse(response.StatusCode, responseContent);
        }
    }

    private async Task<HttpResponseMessage> RequestInnerAsync(
        HttpClient client,
        TimeSpan? requestTimeout,
        HttpCompletionOption completionOption,
        CancellationToken cancellationToken,
        HttpMethod method,
        string path,
        HttpContent content = null,
        Dictionary<string, string> extraParams = null,
        bool includeAuthToQuery = true)
    {
        if (requestTimeout.HasValue)
        {
            client.Timeout = requestTimeout.Value;
        }

        StringBuilder uri = BuildUri(path, extraParams, includeAuthToQuery);
        HttpRequestMessage request = PrepareRequest(method, content, uri);

        Debug.WriteLine("[Request] {0}", request.ToJson());
        if (content != null)
        {
            Debug.WriteLine("[RequestData] {0}", content.ReadAsStringAsync().Result);
        }

        return await client.SendAsync(request, completionOption, cancellationToken);
    }

Support parameterized queries

It feels really weird to have to use custom query builders instead of being able to generate queries with something like:

_dbClient.QueryAsync("databaseName", "SELECT * FROM temp WHERE cpuId = @CpuId",
   new
   {
       CpuId = cpuId
   });

SSL/TLS support

https is not supported yet.
Can you add this to your lib please ?

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.