public async Task TestDropContinuousQueryAsync_NotSaved()
        {
            var client = new InfluxDBClient(influxUrl, dbUName, dbpwd);
            var p      = new InfluxContinuousQuery()
            {
                Name = "TestCQ2", DBName = dbName
            };

            var r = await AssertEx.ThrowsAsync <ArgumentException>(() => client.DropContinuousQueryAsync(p));
        }
        public async Task TestCreateContinuousQueryAsync_MissingGroupBy()
        {
            var client = new InfluxDBClient(influxUrl, dbUName, dbpwd);
            var query  = $"select mean(Doublefield) as Doublefield into cqMeasurement from {measurementName} group by *";
            var p      = new InfluxContinuousQuery()
            {
                Name = "TestCQ2", DBName = dbName, Query = query
            };

            var r = await AssertEx.ThrowsAsync <InfluxDBException>(() => client.CreateContinuousQueryAsync(p));
        }
        public async Task TestCreateContinuousQueryAsync_WithResample()
        {
            var client = new InfluxDBClient(influxUrl, dbUName, dbpwd);
            var query  = $"select mean(Intfield) as Intfield into cqMeasurement from {measurementName} group by time(1h),*";
            var p      = new InfluxContinuousQuery()
            {
                Name = "TestCQ1", DBName = dbName, Query = query, ResampleDuration = TimeSpan.FromHours(2), ResampleFrequency = TimeSpan.FromHours(0.5)
            };
            var r = await client.CreateContinuousQueryAsync(p);

            Assert.IsTrue(p.Saved, "CreateContinuousQueryAsync failed");
        }
        public async Task TestCreateContinuousQueryAsync()
        {
            var client = new InfluxDBClient(influxUrl, dbUName, dbpwd);
            var query  = $"select mean(Doublefield) as Doublefield into cqMeasurement from {measurementName} group by time(1h),*";
            var p      = new InfluxContinuousQuery()
            {
                Name = "TestCQ", DBName = dbName, Query = query
            };

            var r = await client.CreateContinuousQueryAsync(p);

            Assert.IsTrue(r && p.Saved, "CreateContinuousQueryAsync failed");
        }
Exemplo n.º 5
0
        public bool EnsureContinuousQuery(string databaseName, InfluxDbContinuousQueryDefinition definition)
        {
            var cqs = _influxDbClient.GetContinuousQueriesAsync()
                      .Result
                      .FirstOrDefault(x => x.Name.Equals(definition.Name, StringComparison.InvariantCulture));

            if (cqs != null)
            {
                if (cqs.Query.Equals(definition.Query, StringComparison.InvariantCulture) &&
                    cqs.DBName.Equals(databaseName, StringComparison.InvariantCulture) &&
                    cqs.ResampleDuration.Equals(definition.ResampleDuration) &&
                    cqs.ResampleFrequency.Equals(definition.ResampleFrequency))
                {
                    _logger.Debug("Continuous query {0} already exists. Nothing to do.", definition.Name);
                    return(false);
                }
                else
                {
                    _logger.Info("Continuous query {0} already exists, but with different configuration. Current CQ will be deleted and new created.",
                                 definition.Name);
                    _influxDbClient.DropContinuousQueryAsync(cqs);
                }
            }
            else
            {
                _logger.Info("Continuous query {0} does not exists. CQ will be created.",
                             definition.Name);
            }

            var p = new InfluxContinuousQuery()
            {
                Name              = definition.Name,
                DBName            = databaseName,
                Query             = definition.Query,
                ResampleDuration  = definition.ResampleDuration,
                ResampleFrequency = definition.ResampleFrequency
            };

            return(_influxDbClient.CreateContinuousQueryAsync(p).Result);
        }