예제 #1
0
            protected override async Task <double> CountInDb()
            {
                Console.WriteLine("Querying InfluxDB ...");

                var query = "from(bucket:\"" + databaseName + "\")\n"
                            + "  |> range(start: 0, stop: now())\n"
                            + "  |> filter(fn: (r) => r._measurement == \"" + MeasurementName + "\")\n"
                            + "  |> pivot(rowKey:[\"_time\"], columnKey: [\"_field\"], valueColumn: \"_value\")\n"
                            + "  |> drop(columns: [\"id\", \"host\"])\n"
                            + "  |> count(column: \"temperature\")";

                var options = InfluxDBClientOptions.Builder.CreateNew()
                              .Url(url)
                              .AuthenticateToken(InfluxDb2Token.ToCharArray())
                              .TimeOut(TimeSpan.FromSeconds(180))
                              .Build();

                var client = InfluxDBClientFactory.Create(options);

                try
                {
                    var results = await client.GetQueryApi().QueryAsync(query, InfluxDb2Org);

                    var count = (long)results[0].Records[0].GetValueByKey("temperature");

                    return(count);
                }
                catch (Exception e)
                {
                    throw new SystemException(e.Message);
                }
            }
예제 #2
0
            public ClientV2(List <CommandOption> options, WriteOptions writeOptions) : base(options, InfluxDb2Bucket, InfluxDb2Url, InfluxDb2Token)
            {
                if (writeOptions == null)
                {
                    var batchSize     = int.Parse(Benchmark.GetOptionValue(GetOption(options, "batchSize"), "50000"));
                    var flushInterval = int.Parse(Benchmark.GetOptionValue(GetOption(options, "flushInterval"), "10000"));
                    writeOptions = WriteOptions.CreateNew().BatchSize(batchSize).FlushInterval(flushInterval).Build();
                }
                InfluxDBClientOptions opts = InfluxDBClientOptions.Builder.CreateNew()
                                             .Url(InfluxDb2Url)
                                             .AuthenticateToken(InfluxDb2Token.ToCharArray())
                                             .LogLevel(LogLevel.Headers).Build();

                _client   = InfluxDBClientFactory.Create(opts);
                _writeApi = _client.GetWriteApi(writeOptions);
            }