示例#1
0
 public InfluxDBMeasurementsCollector(InfluxDBLoginInformation loginInformation)
 {
     this.loginInformation = loginInformation;
     influxDBClient        = new InfluxDbClient(loginInformation.DBUri.ToString(),
                                                loginInformation.User,
                                                loginInformation.Password,
                                                InfluxDbVersion.v_1_3);
 }
示例#2
0
 public InfluxDBMeasurementsCollector(InfluxDBLoginInformation loginInformation,
                                      CancellationToken shutdownToken)
 {
     this.loginInformation = loginInformation;
     tokenSource           = CancellationTokenSource.CreateLinkedTokenSource(shutdownToken);
     influxDBClient        = new InfluxDBClient(loginInformation.DBUri.ToString(),
                                                loginInformation.User,
                                                loginInformation.Password);
 }
        public static async Task <object> GetSingleValueForQuery(string query, InfluxDBLoginInformation loginInformation)
        {
            var queryData = (await ExecuteInfluxDBQuery(query, loginInformation).ConfigureAwait(false)).FirstOrDefault();

            if (queryData != null)
            {
                if (queryData.Values.Count > 0)
                {
                    // first row, second column
                    if (queryData.Values[0].Count > 1)
                    {
                        return(queryData.Values[0][1]);
                    }
                }
            }

            return(null);
        }
        public static async Task <IEnumerable <Serie> > ExecuteInfluxDBQuery(string query, InfluxDBLoginInformation loginInformation)
        {
            var influxDbClient = new InfluxDbClient(loginInformation.DBUri.ToString(), loginInformation.User, loginInformation.Password, InfluxDbVersion.v_1_3);

            return(await influxDbClient.Client.QueryAsync(query, loginInformation.DB, TimeUnit.Seconds).ConfigureAwait(false));
        }
        private void HandleSaveDBSettingPostBack(NameValueCollection parts)
        {
            StringBuilder results = new StringBuilder();

            // Validate

            System.Uri dbUri;

            if (!System.Uri.TryCreate(parts[DBUriKey], UriKind.Absolute, out dbUri))
            {
                results.AppendLine("Url is not Valid.<br>");
            }

            string database = parts[DBKey];

            if (string.IsNullOrWhiteSpace(database))
            {
                results.AppendLine("Database is not Valid.<br>");
            }

            string username  = parts[UserKey];
            string password  = parts[PasswordKey];
            string retention = parts[RetentionKey];

            try
            {
                var influxDbClient = new InfluxDbClient(dbUri.ToString(), username, password, InfluxDbVersion.v_1_3);

                var databases = influxDbClient.Database.GetDatabasesAsync().Result;

                var selectedDb = databases.Where((db) => { return(db.Name == database); }).FirstOrDefault();
                if (selectedDb == null)
                {
                    results.AppendLine("Database not found on server.<br>");
                }
                else
                {
                    if (!string.IsNullOrWhiteSpace(retention))
                    {
                        var retentionPolcies = influxDbClient.Retention.GetRetentionPoliciesAsync(selectedDb.Name).Result;
                        if (!retentionPolcies.Any(r => r.Name == retention))
                        {
                            results.AppendLine("Retention policy not found for database.<br>");
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                results.AppendLine(Invariant($"Failed to connect to InfluxDB with {ex.GetFullMessage()}"));
            }

            if (results.Length > 0)
            {
                this.divToUpdate.Add(ErrorDivId, results.ToString());
            }
            else
            {
                this.divToUpdate.Add(ErrorDivId, string.Empty);
                var dbConfig = new InfluxDBLoginInformation(dbUri,
                                                            PluginConfig.CheckEmptyOrWhitespace(username),
                                                            PluginConfig.CheckEmptyOrWhitespace(password),
                                                            PluginConfig.CheckEmptyOrWhitespace(parts[DBKey]),
                                                            PluginConfig.CheckEmptyOrWhitespace(retention));
                this.pluginConfig.DBLoginInformation = dbConfig;
                this.pluginConfig.DebugLogging       = parts[DebugLoggingId] == "checked";
                this.pluginConfig.FireConfigChanged();
            }
        }