Beispiel #1
0
        public override void Configure(IFunctionsHostBuilder builder)
        {
            IConfiguration configuration = new ConfigurationBuilder()
                                           .SetBasePath(Environment.CurrentDirectory)
                                           .AddJsonFile("local.settings.json", optional: true, reloadOnChange: true)
                                           .AddEnvironmentVariables()
                                           .Build();

            IConfigurationSection influxDBConfigurationSection = configuration.GetSection("InfluxDB");
            IConfigurationSection featuresConfigurationSection = configuration.GetSection("Features");

            IInfluxDBConfiguration influxDBConfiguration = new InfluxDBConfiguration();
            IFeaturesConfiguration featuresConfiguration = new FeaturesConfiguration();

            influxDBConfigurationSection.Bind(influxDBConfiguration);
            featuresConfigurationSection.Bind(featuresConfiguration);

            InfluxDBClientOptions influxDBClientOptions = InfluxDBClientOptions.Builder
                                                          .CreateNew()
                                                          .Url(influxDBConfiguration.Url)
                                                          .AuthenticateToken(influxDBConfiguration.Token.ToCharArray())
                                                          .Org(influxDBConfiguration.Organisation)
                                                          .Bucket(influxDBConfiguration.Bucket)
                                                          .Build();

            InfluxDBClient    influxDBClient   = InfluxDBClientFactory.Create(influxDBClientOptions);
            ISensorRepository sensorRepository = new SensorRepository(influxDBClient);

            builder.Services.AddSingleton <IFeaturesConfiguration>(featuresConfiguration);
            builder.Services.AddSingleton <ISensorRepository>(sensorRepository);
            builder.Services.AddSensorService();
            builder.Services.AddFeatureService();
        }
Beispiel #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);
            }
Beispiel #3
0
        public ApiClient(InfluxDBClientOptions options, LoggingHandler loggingHandler, GzipHandler gzipHandler)
        {
            _options        = options;
            _loggingHandler = loggingHandler;
            _gzipHandler    = gzipHandler;

            var timeoutTotalMilliseconds = (int)options.Timeout.TotalMilliseconds;
            var totalMilliseconds        = (int)options.ReadWriteTimeout.TotalMilliseconds;

            RestClient = new RestClient(options.Url);
            RestClient.AutomaticDecompression = false;
            Configuration = new Configuration
            {
                ApiClient        = this,
                BasePath         = options.Url,
                Timeout          = timeoutTotalMilliseconds,
                ReadWriteTimeout = totalMilliseconds,
            };
        }
        public static IServiceCollection AddInfluxDbBufferedWriter(this IServiceCollection services, InfluxDBClientOptions clientOptions, BufferedChannelOptions options = null)
        {
            if (clientOptions == null)
            {
                throw new ArgumentNullException(nameof(clientOptions));
            }

            if (options == null)
            {
                options = new BufferedChannelOptions
                {
                    BufferSize    = BufferedChannelOptions.DefaultBufferSize,
                    FlushInterval = BufferedChannelOptions.DefaultFlushInterval
                };
            }

            return(services
                   .AddTransient <IDefaultMetrics, DefaultMetrics>()
                   .AddSingleton <IInfluxDbClientWriter>(p =>
            {
                var client = InfluxDBClientFactory.Create(clientOptions);
                return new InfluxDbClientWriter(client, options);
            }));
        }
        public static async Task Main(string[] args)
        {
            InfluxDBClientOptions options = InfluxDBClientOptions
                                            .Builder
                                            .CreateNew()
                                            .Bucket("bucket_name")
                                            .Url("http://192.168.0.10:8086")
                                            .Org("nothing")
                                            .Build();

            var influxDBClient = InfluxDBClientFactory.Create(options);

            //
            // Write Data
            //
            using (var writeApi = influxDBClient.GetWriteApi())
            {
                //
                // Write by Point
                //
                var point = PointData.Measurement("temperature")
                            .Tag("location", "west")
                            .Field("value", 55D)
                            .Timestamp(DateTime.UtcNow.AddSeconds(-10), WritePrecision.Ns);

                writeApi.WritePoint("bucket_name", "org_id", point);

                //
                // Write by LineProtocol
                //
                writeApi.WriteRecord("bucket_name", "org_id", WritePrecision.Ns, "temperature,location=north value=60.0");

                //
                // Write by POCO
                //
                var temperature = new Temperature {
                    Location = "south", Value = 62D, Time = DateTime.UtcNow
                };
                writeApi.WriteMeasurement("bucket_name", "org_id", WritePrecision.Ns, temperature);
            }

            //
            // Query data
            //
            var flux = "from(bucket:\"bucket_name\") |> range(start: 0)";

            Query d = new Query(query: flux, db: "bucket_name");

            var fluxTables = await influxDBClient.GetQueryApi().QueryAsync(d, "org_id");

            fluxTables.ForEach(fluxTable =>
            {
                var fluxRecords = fluxTable.Records;
                fluxRecords.ForEach(fluxRecord =>
                {
                    Console.WriteLine($"{fluxRecord.GetTime()}: {fluxRecord.GetValue()}");
                });
            });

            influxDBClient.Dispose();
        }
 public Influx2Config(InfluxDBClientOptions options)
 {
     Options = options;
 }