Beispiel #1
0
        /// <summary>
        ///     Execute a query agains a database.
        /// </summary>
        /// <param name="database">the name of the database</param>
        /// <param name="query">
        ///     the query to execute, for language specification please see
        ///     <a href="http://influxdb.org/docs/query_language">http://influxdb.org/docs/query_language</a>
        /// </param>
        /// <param name="precision">the precision used for the values.</param>
        /// <returns>A list of Series which matched the query.</returns>
        public async Task <List <Serie> > QueryAsync(string database, string query, TimeUnit precision)
        {
            InfluxDbApiResponse response =
                await _influxDbClient.Query(NoErrorHandlers, database, query, ToTimePrecision(precision));

            return(response.ReadAs <List <Serie> >());
        }
Beispiel #2
0
        /// <summary>
        ///     Create a new Database.
        /// </summary>
        /// <param name="name">The name of the new database</param>
        /// <returns></returns>
        public async Task <InfluxDbApiCreateResponse> CreateDatabaseAsync(string name)
        {
            var db = new Database {
                Name = name
            };

            InfluxDbApiResponse response = await _influxDbClient.CreateDatabase(NoErrorHandlers, db);

            return(new InfluxDbApiCreateResponse(response.StatusCode, response.Body));
        }
Beispiel #3
0
        /// <summary>
        ///     Ping this InfluxDB
        /// </summary>
        /// <returns>The response of the ping execution.</returns>
        public async Task <Pong> PingAsync()
        {
            Stopwatch watch = Stopwatch.StartNew();

            InfluxDbApiResponse response = await _influxDbClient.Ping(NoErrorHandlers);

            watch.Stop();
            var pong = response.ReadAs <Pong>();

            pong.ResponseTime = watch.ElapsedMilliseconds;

            return(pong);
        }
Beispiel #4
0
        /// <summary>
        ///     Return the version of the connected influxDB Server.
        /// </summary>
        /// <returns>The version String, otherwise unknown</returns>
        public async Task <string> VersionAsync()
        {
            InfluxDbApiResponse response = await _influxDbClient.Version(NoErrorHandlers);

            const string version = "unknown";

            if (!string.IsNullOrEmpty(response.Body))
            {
                return(response.Body);
            }

            return(version);
        }
Beispiel #5
0
        /// <summary>Execute a query agains a database.</summary>
        /// <param name="database">The name of the database.</param>
        /// <param name="query">The query to execute. For language specification please see
        /// <a href="https://influxdb.com/docs/v0.9/concepts/reading_and_writing_data.html">InfluxDb documentation</a>.</param>
        /// <returns>A list of Series which matched the query.</returns>
        /// <exception cref="InfluxDbApiException"></exception>
        public async Task <List <Serie> > QueryAsync(string database, string query)
        {
            InfluxDbApiResponse response = await _influxDbClient.Query(NoErrorHandlers, database, query);

            var queryResult = response.ReadAs <QueryResult>();

            Validate.NotNull(queryResult, "queryResult");
            Validate.NotNull(queryResult.Results, "queryResult.Results");

            // Apparently a 200 OK can return an error in the results
            // https://github.com/influxdb/influxdb/pull/1813
            var error = queryResult.Results.Single().Error;

            if (error != null)
            {
                throw new InfluxDbApiException(System.Net.HttpStatusCode.BadRequest, error);
            }

            var result = queryResult.Results.Single().Series;

            return(result != null?result.ToList() : new List <Serie>());
        }
Beispiel #6
0
        /// <summary>Execute queries against a database.</summary>
        /// <param name="database">The name of the database.</param>
        /// <param name="queries">Queries to execute. For language specification please see
        /// <a href="https://influxdb.com/docs/v0.9/concepts/reading_and_writing_data.html">InfluxDb documentation</a>.</param>
        /// <returns>A list of Series which matched the queries.</returns>
        /// <exception cref="InfluxDbApiException"></exception>
        public async Task <List <Serie> > QueryAsync(string database, List <string> queries)
        {
            InfluxDbApiResponse response = await _influxDbClient.Query(NoErrorHandlers, database, queries);

            var queryResult = response.ReadAs <QueryResult>();

            Validate.NotNull(queryResult, "queryResult");
            Validate.NotNull(queryResult.Results, "queryResult.Results");

            // Apparently a 200 OK can return an error in the results
            // https://github.com/influxdb/influxdb/pull/1813
            var errors = queryResult.Results.Where(res => res.Error != null).Select(res => res.Error).ToList();

            if (errors.Any())
            {
                throw new InfluxDbApiException(System.Net.HttpStatusCode.BadRequest, string.Join(", ", errors));
            }

            var result = queryResult.Results.SelectMany(res => res.Series == null ? new List <Serie> {
                new Serie()
            } : res.Series.DefaultIfEmpty(new Serie()));

            return(result.ToList());
        }
Beispiel #7
0
        /// <summary>
        /// List all servers which are member of the cluster.
        /// </summary>
        /// <returns>A list of all influxdb servers.</returns>
        public async Task <List <Server> > ListServersAsync()
        {
            InfluxDbApiResponse response = await _influxDbClient.ListServers(NoErrorHandlers);

            return(response.ReadAs <List <Server> >());
        }
Beispiel #8
0
        /// <summary>
        /// List all interfaces influxDB is listening.
        /// </summary>
        /// <returns>A list of interface names.</returns>
        public async Task <List <string> > InterfacesAsync()
        {
            InfluxDbApiResponse response = await _influxDbClient.Interfaces(NoErrorHandlers);

            return(response.ReadAs <List <string> >());
        }
Beispiel #9
0
        /// <summary>
        /// Sync the database to the filesystem.
        /// </summary>
        /// <returns>true|false if successful.</returns>
        public async Task <bool> SyncAsync()
        {
            InfluxDbApiResponse response = await _influxDbClient.Sync(NoErrorHandlers);

            return(response.ReadAs <bool>());
        }
Beispiel #10
0
        /// <summary>
        /// Describe all existing shardspaces.
        /// </summary>
        /// <returns>A list of all <see cref="ShardSpace"></see>'s.</returns>
        public async Task <List <ShardSpace> > GetShardSpacesAsync()
        {
            InfluxDbApiResponse response = await _influxDbClient.GetShardSpaces(NoErrorHandlers);

            return(response.ReadAs <List <ShardSpace> >());
        }
Beispiel #11
0
        /// <summary>
        /// Describe all database users allowed to acces the given database.
        /// </summary>
        /// <param name="database">The name of the database for which all users should be described.</param>
        /// <returns>A list of all users.</returns>
        public async Task <List <User> > DescribeDatabaseUsersAsync(string database)
        {
            InfluxDbApiResponse response = await _influxDbClient.DescribeDatabaseUsers(NoErrorHandlers, database);

            return(response.ReadAs <List <User> >());
        }
Beispiel #12
0
        /// <summary>
        /// Describe all contious queries in a database.
        /// </summary>
        /// <param name="database">The name of the database for which all continuous queries should be described.</param>
        /// <returns>A list of all contious queries.</returns>
        public async Task <List <ContinuousQuery> > DescribeContinuousQueriesAsync(string database)
        {
            InfluxDbApiResponse response = await _influxDbClient.GetContinuousQueries(NoErrorHandlers, database);

            return(response.ReadAs <List <ContinuousQuery> >());
        }
Beispiel #13
0
        /// <summary>
        /// Describe all cluster admins.
        /// </summary>
        /// <returns>A list of all admins.</returns>
        public async Task <List <User> > DescribeClusterAdminsAsync()
        {
            InfluxDbApiResponse response = await _influxDbClient.DescribeClusterAdmins(NoErrorHandlers);

            return(response.ReadAs <List <User> >());
        }
Beispiel #14
0
        /// <summary>
        ///     Create a new Database from a <see cref="DatabaseConfiguration" />. This is the way to create a db with shards
        ///     specified.
        /// </summary>
        /// <param name="config">The configuration for the database to create..</param>
        /// <returns></returns>
        public async Task <InfluxDbApiCreateResponse> CreateDatabaseAsync(DatabaseConfiguration config)
        {
            InfluxDbApiResponse response = await _influxDbClient.CreateDatabase(NoErrorHandlers, config);

            return(new InfluxDbApiCreateResponse(response.StatusCode, response.Body));
        }
Beispiel #15
0
        public static T ReadAs <T>(this InfluxDbApiResponse response)
        {
            var @object = JsonConvert.DeserializeObject <T>(response.Body);

            return(@object);
        }
Beispiel #16
0
        public async Task <Shards> GetShardsAsync()
        {
            InfluxDbApiResponse response = await _influxDbClient.GetShards(NoErrorHandlers);

            return(response.ReadAs <Shards>());
        }
Beispiel #17
0
        /// <summary>
        ///     Delete a database.
        /// </summary>
        /// <param name="name">The name of the database to delete.</param>
        /// <returns></returns>
        public async Task <InfluxDbApiDeleteResponse> DeleteDatabaseAsync(string name)
        {
            InfluxDbApiResponse response = await _influxDbClient.DeleteDatabase(NoErrorHandlers, name);

            return(new InfluxDbApiDeleteResponse(response.StatusCode, response.Body));
        }
Beispiel #18
0
        /// <summary>
        ///     Describe all available databases.
        /// </summary>
        /// <returns>A list of all Databases</returns>
        public async Task <List <Database> > DescribeDatabasesAsync()
        {
            InfluxDbApiResponse response = await _influxDbClient.DescribeDatabases(NoErrorHandlers);

            return(response.ReadAs <List <Database> >());
        }