/// <summary> /// Gets the default configuration by setting the <see cref="InfluxConfig.Writer"/> /// property to a new <see cref="InfluxdbUdpWriter"/> instance if it is not set. /// </summary> /// <param name="defaultConfig">The configuration to apply the settings to. If null, creates a new <see cref="InfluxConfig"/> instance.</param> /// <returns>A default <see cref="InfluxConfig"/> instance for the derived type's implementation.</returns> protected override InfluxConfig GetDefaultConfig(InfluxConfig defaultConfig) { var config = base.GetDefaultConfig(defaultConfig) ?? new InfluxConfig(); config.Writer = config.Writer ?? new InfluxdbUdpWriter(config); return(config); }
public void InfluxReport_CanAddRecords_ForMeter() { var config = new InfluxConfig("localhost", "testdb"); var writer = new InfluxdbTestWriter(config); config.Writer = writer; var report = new InfluxdbHttpReport(config); var context = new DefaultMetricsContext("TestContext"); var precision = config.Precision ?? InfluxConfig.Default.Precision; var metricsData = context.DataProvider.CurrentMetricsData; var meter = context.Meter("test_meter", Unit.Bytes, TimeUnit.Seconds, new MetricTags("key1=value1,tag2,tag3,key4=value4")); // add normally meter.Mark(300); metricsData = context.DataProvider.CurrentMetricsData; report.RunReport(metricsData, hsFunc, CancellationToken.None); writer.LastBatch.Should().HaveCount(1); var expTime = InfluxLineProtocol.FormatTimestamp(metricsData.Timestamp, precision); writer.LastBatch[0].ToLineProtocol(precision).Should().StartWith($@"testcontext.test_meter,key1=value1,key4=value4 count=300i,mean_rate=").And.EndWith($@",1_min_rate=0,5_min_rate=0,15_min_rate=0 {expTime}");; // add with set item meter.Mark("item1,item2=ival2,item3=ival3", 100); metricsData = context.DataProvider.CurrentMetricsData; report.RunReport(metricsData, hsFunc, CancellationToken.None); writer.LastBatch.Should().HaveCount(2); expTime = InfluxLineProtocol.FormatTimestamp(metricsData.Timestamp, precision); writer.LastBatch[0].ToLineProtocol(precision).Should().StartWith($@"testcontext.test_meter,key1=value1,key4=value4 count=400i,mean_rate=").And.EndWith($@",1_min_rate=0,5_min_rate=0,15_min_rate=0 {expTime}"); writer.LastBatch[1].ToLineProtocol(precision).Should().StartWith($@"testcontext.test_meter,item2=ival2,item3=ival3,key1=value1,key4=value4 count=100i,percent=25,mean_rate=").And.EndWith($@",1_min_rate=0,5_min_rate=0,15_min_rate=0 {expTime}"); }
public void InfluxReport_CanAddRecords_ForTimer() { var config = new InfluxConfig("localhost", "testdb"); var writer = new InfluxdbTestWriter(config); config.Writer = writer; var report = new InfluxdbHttpReport(config); var context = new DefaultMetricsContext("TestContext"); var precision = config.Precision ?? InfluxConfig.Default.Precision; var metricsData = context.DataProvider.CurrentMetricsData; var timer = context.Timer("test_timer", Unit.Bytes, SamplingType.Default, TimeUnit.Seconds, TimeUnit.Seconds, new MetricTags("key1=value1,tag2,tag3,key4=value4")); // add normally timer.Record(100, TimeUnit.Seconds); metricsData = context.DataProvider.CurrentMetricsData; report.RunReport(metricsData, hsFunc, CancellationToken.None); writer.LastBatch.Should().HaveCount(1); var expTime = InfluxLineProtocol.FormatTimestamp(metricsData.Timestamp, precision); writer.LastBatch[0].ToLineProtocol(precision).Should().StartWith($@"testcontext.test_timer,key1=value1,key4=value4 active_sessions=0i,total_time=100i,count=1i,").And.EndWith($@",1_min_rate=0,5_min_rate=0,15_min_rate=0,last=100,min=100,mean=100,max=100,stddev=0,median=100,sample_size=1i,percentile_75%=100,percentile_95%=100,percentile_98%=100,percentile_99%=100,percentile_99.9%=100 {expTime}"); // add with set item timer.Record(50, TimeUnit.Seconds, "item1,item2=ival2,item3=ival3"); metricsData = context.DataProvider.CurrentMetricsData; report.RunReport(metricsData, hsFunc, CancellationToken.None); writer.LastBatch.Should().HaveCount(1); expTime = InfluxLineProtocol.FormatTimestamp(metricsData.Timestamp, precision); writer.LastBatch[0].ToLineProtocol(precision).Should().StartWith($@"testcontext.test_timer,key1=value1,key4=value4 active_sessions=0i,total_time=150i,count=2i,").And.EndWith($@",1_min_rate=0,5_min_rate=0,15_min_rate=0,last=50,min=50,mean=75,max=100,stddev=25,median=100,sample_size=2i,percentile_75%=100,percentile_95%=100,percentile_98%=100,percentile_99%=100,percentile_99.9%=100 {expTime}"); }
public void InfluxReport_CanAddRecords_ForHistogram() { var config = new InfluxConfig("localhost", "testdb"); var writer = new InfluxdbTestWriter(config); config.Writer = writer; var report = new InfluxdbHttpReport(config); var context = new DefaultMetricsContext("TestContext"); var precision = config.Precision ?? InfluxConfig.Default.Precision; var metricsData = context.DataProvider.CurrentMetricsData; var hist = context.Histogram("test_hist", Unit.Bytes, SamplingType.Default, new MetricTags("key1=value1,tag2,tag3,key4=value4")); // add normally hist.Update(300); metricsData = context.DataProvider.CurrentMetricsData; report.RunReport(metricsData, hsFunc, CancellationToken.None); writer.LastBatch.Should().HaveCount(1); var expTime = InfluxLineProtocol.FormatTimestamp(metricsData.Timestamp, precision); writer.LastBatch[0].ToLineProtocol(precision).Should().Be($@"testcontext.test_hist,key1=value1,key4=value4 count=1i,last=300,min=300,mean=300,max=300,stddev=0,median=300,sample_size=1i,percentile_75%=300,percentile_95%=300,percentile_98%=300,percentile_99%=300,percentile_99.9%=300 {expTime}"); // add with set item hist.Update(100, "item1,item2=ival2,item3=ival3"); metricsData = context.DataProvider.CurrentMetricsData; report.RunReport(metricsData, hsFunc, CancellationToken.None); writer.LastBatch.Should().HaveCount(1); expTime = InfluxLineProtocol.FormatTimestamp(metricsData.Timestamp, precision); writer.LastBatch[0].ToLineProtocol(precision).Should().Be($@"testcontext.test_hist,key1=value1,key4=value4 count=2i,last=100,min=100,mean=200,max=300,stddev=100,median=300,sample_size=2i,percentile_75%=300,percentile_95%=300,percentile_98%=300,percentile_99%=300,percentile_99.9%=300 {expTime}"); }
public void InfluxReport_CanAddRecords_ForHealthCheck() { var config = new InfluxConfig("localhost", "testdb"); var writer = new InfluxdbTestWriter(config); config.Writer = writer; var report = new InfluxdbHttpReport(config); var context = new DefaultMetricsContext("TestContext"); var precision = config.Precision ?? InfluxConfig.Default.Precision; var metricsData = context.DataProvider.CurrentMetricsData; HealthChecks.UnregisterAllHealthChecks(); HealthChecks.RegisterHealthCheck("Health Check 1", () => HealthCheckResult.Healthy($"Healthy check!")); HealthChecks.RegisterHealthCheck("Health Check 2", () => HealthCheckResult.Unhealthy($"Unhealthy check!")); HealthChecks.RegisterHealthCheck("Health Check 3,tag3=key3", () => HealthCheckResult.Healthy($"Healthy check!")); HealthChecks.RegisterHealthCheck("Health Check 4,tag 4=key 4", () => HealthCheckResult.Healthy($"Healthy check!")); HealthChecks.RegisterHealthCheck("Name=Health Check 5,tag5=key5", () => HealthCheckResult.Healthy($"Healthy check!")); metricsData = context.DataProvider.CurrentMetricsData; report.RunReport(metricsData, () => HealthChecks.GetStatus(), CancellationToken.None); HealthChecks.UnregisterAllHealthChecks(); // unreg first in case something below throws writer.LastBatch.Should().HaveCount(5); var expTime = InfluxLineProtocol.FormatTimestamp(metricsData.Timestamp, precision); writer.LastBatch[0].ToLineProtocol(precision).Should().Be($@"health_checks,name=health_check_1 ishealthy=True,message=""Healthy check!"" {expTime}"); writer.LastBatch[1].ToLineProtocol(precision).Should().Be($@"health_checks,name=health_check_2 ishealthy=False,message=""Unhealthy check!"" {expTime}"); writer.LastBatch[2].ToLineProtocol(precision).Should().Be($@"health_checks,name=health_check_3,tag3=key3 ishealthy=True,message=""Healthy check!"" {expTime}"); writer.LastBatch[3].ToLineProtocol(precision).Should().Be($@"health_checks,name=health_check_4,tag_4=key\ 4 ishealthy=True,message=""Healthy check!"" {expTime}"); writer.LastBatch[4].ToLineProtocol(precision).Should().Be($@"health_checks,name=health\ check\ 5,tag5=key5 ishealthy=True,message=""Healthy check!"" {expTime}"); }
/// <summary> /// Schedules an <see cref="InfluxdbJsonReport"/> to be executed at a fixed interval using the deprecated JSON protocol. /// NOTE: It is recommended to NOT use the JSON reporter because of performance issues, and support for JSON has been /// removed from InfluxDB in versions later than v0.9.1. It is recommended to use the HTTP or UDP reporters instead. /// See for more information: https://docs.influxdata.com/influxdb/v0.13/write_protocols/json/ /// </summary> /// <param name="reports">The <see cref="MetricsReports"/> instance.</param> /// <param name="config">The InfluxDB reporter configuration.</param> /// <param name="interval">Interval at which to run the report.</param> /// <param name="filter">Only report metrics that match the filter.</param> /// <param name="configFunc">A lambda expression that allows further configuration of the InfluxDB reporter using fluent syntax.</param> /// <returns>The <see cref="MetricsReports"/> instance.</returns> public static MetricsReports WithInfluxDbJson(this MetricsReports reports, InfluxConfig config, TimeSpan interval, MetricsFilter filter = null, Action <InfluxConfig> configFunc = null) { InfluxConfig conf = config ?? new InfluxConfig(); configFunc?.Invoke(conf); return(reports.WithReport(new InfluxdbJsonReport(conf), interval, filter)); }
/// <summary> /// Creates a new <see cref="InfluxdbHttpWriter"/> with the specified URI. /// NOTE: This protocol is only supported in InfluxDB version v0.9.1 and earlier. /// </summary> /// <param name="config">The InfluxDB configuration.</param> /// <param name="batchSize">The maximum number of records to write per flush. Set to zero to write all records in a single flush. Negative numbers are not allowed.</param> public InfluxdbJsonWriter(InfluxConfig config, Int32 batchSize = 0) : base(batchSize) { this.config = config; if (config == null) { throw new ArgumentNullException(nameof(config)); } if (String.IsNullOrEmpty(config.Database)) { throw new ArgumentNullException(nameof(config.Database)); } if (config.Precision != InfluxPrecision.Seconds) { //log.Warn($"InfluxDB timestamp precision '{config.Precision}' is not supported by the JSON protocol, defaulting to {InfluxPrecision.Seconds}."); throw new ArgumentException($"InfluxDB timestamp precision '{config.Precision}' is not supported by the JSON protocol, which only supports {InfluxPrecision.Seconds} precision.", nameof(config.Precision)); } this.influxDbUri = FormatInfluxUri(config); if (influxDbUri == null) { throw new ArgumentNullException(nameof(influxDbUri)); } if (influxDbUri.Scheme != Uri.UriSchemeHttp && influxDbUri.Scheme != Uri.UriSchemeHttps) { throw new ArgumentException($"The URI scheme must be either http or https. Scheme: {influxDbUri.Scheme}", nameof(influxDbUri)); } }
public async void CanInsertIntoInflux() { var config = new InfluxConfig(new Uri("http://influx:8086"), "mydb", "my_user", "my_pass"); using (var writer = new InfluxWriter(config, "my-pc")) using (var client = new HttpClient()) { for (int attempts = 0; ; attempts++) { try { await writer.ReportMetrics(DateTime.Now, TestSensorCreator.Values()); var resp = await client.GetAsync( "http://influx:8086/query?pretty=true&db=mydb&q=SELECT%20*%20FROM%20Temperature"); Assert.True(resp.IsSuccessStatusCode); var content = await resp.Content.ReadAsStringAsync(); Assert.Contains("/intelcpu/0/temperature/0", content); break; } catch (Exception ex) { if (attempts >= 10) { throw; } Thread.Sleep(TimeSpan.FromSeconds(1)); } } } }
/// <summary> /// Creates a new InfluxDB report that uses the Line Protocol syntax. /// </summary> /// <param name="config">The InfluxDB configuration object.</param> public InfluxdbBaseReport(InfluxConfig config = null) { this.config = GetDefaultConfig(config) ?? new InfluxConfig(); this.converter = config.Converter; this.formatter = config.Formatter; this.writer = config.Writer; ValidateConfig(this.config); }
/// <summary> /// Gets the default configuration by setting the <see cref="InfluxConfig.Writer"/> /// property to a new <see cref="InfluxdbJsonWriter"/> instance if it is not set. /// The <see cref="InfluxConfig.Formatter"/> is set to a no-op default formatter that does not modify identifier names, if the formatter is not set. /// The <see cref="InfluxConfig.Precision"/> is set to <see cref="InfluxPrecision.Seconds"/> because it is the only precision supported by the JSON protocol. /// </summary> /// <param name="defaultConfig">The configuration to apply the settings to. If null, creates a new <see cref="InfluxConfig"/> instance.</param> /// <returns>A default <see cref="InfluxConfig"/> instance for the derived type's implementation.</returns> protected override InfluxConfig GetDefaultConfig(InfluxConfig defaultConfig) { var config = base.GetDefaultConfig(defaultConfig) ?? new InfluxConfig(); config.Precision = InfluxPrecision.Seconds; // JSON only supports seconds config.Formatter = config.Formatter ?? GetDefaultFormatter(); config.Writer = config.Writer ?? new InfluxdbJsonWriter(config); return(config); }
/// <summary> /// Gets the default configuration by setting the <see cref="InfluxConfig.Converter"/> and <see cref="InfluxConfig.Formatter"/> /// properties to <see cref="DefaultConverter"/> and <see cref="DefaultFormatter"/> if either is not set. /// </summary> /// <param name="defaultConfig">The configuration to apply the settings to. If null, creates a new <see cref="InfluxConfig"/> instance.</param> /// <returns>A default <see cref="InfluxConfig"/> instance for the derived type's implementation.</returns> protected override InfluxConfig GetDefaultConfig(InfluxConfig defaultConfig) { var config = base.GetDefaultConfig(defaultConfig) ?? new InfluxConfig(); config.Converter = config.Converter ?? new DefaultConverter(); config.Formatter = config.Formatter ?? new DefaultFormatter(); //config.Writer = config.Writer ?? new InfluxdbHttpWriter(config); return(config); }
/// <summary> /// Creates a new <see cref="InfluxdbLineWriter"/> with the specified configuration and batch size. /// </summary> /// <param name="config">The InfluxDB configuration.</param> /// <param name="batchSize">The maximum number of records to write per flush. Set to zero to write all records in a single flush. Negative numbers are not allowed.</param> public InfluxdbLineWriter(InfluxConfig config, Int32 batchSize = 0) : base(batchSize) { this.config = config; if (config == null) { throw new ArgumentNullException(nameof(config)); } }
/// <summary> /// Creates a new <see cref="InfluxdbUdpWriter"/> with the specified configuration and batch size. /// </summary> /// <param name="config">The InfluxDB configuration.</param> /// <param name="batchSize">The maximum number of records to write per flush. Set to zero to write all records in a single flush. Negative numbers are not allowed.</param> public InfluxdbUdpWriter(InfluxConfig config, Int32 batchSize = 0) : base(config, batchSize) { if (String.IsNullOrEmpty(config.Hostname)) { throw new ArgumentNullException(nameof(config.Hostname)); } if ((config.Port ?? 0) == 0) { throw new ArgumentNullException(nameof(config.Port), "Port is required for UDP connections."); } if ((config.Precision ?? InfluxPrecision.Nanoseconds) != InfluxPrecision.Nanoseconds) { throw new ArgumentException($"Timestamp precision for UDP connections must be Nanoseconds. Actual: {config.Precision}", nameof(config.Precision)); } }
/// <summary> /// Validates the configuration to ensure the configuration is valid and throws an exception on invalid settings. /// </summary> /// <param name="config">The configuration to validate.</param> protected virtual void ValidateConfig(InfluxConfig config) { if (config.Converter == null) { throw new ArgumentNullException(nameof(config.Converter), $"InfluxDB configuration invalid: {nameof(config.Converter)} cannot be null"); } if (config.Formatter == null) { throw new ArgumentNullException(nameof(config.Formatter), $"InfluxDB configuration invalid: {nameof(config.Formatter)} cannot be null"); } if (config.Writer == null) { throw new ArgumentNullException(nameof(config.Writer), $"InfluxDB configuration invalid: {nameof(config.Writer)} cannot be null"); } //log.Debug($"Initialized InfluxDB reporter. Writer: {config.Writer.GetType().Name} Host: {config.Hostname}:{config.Port} Database: {config.Database}"); }
public async void CanInsertIntoPasswordLessInfluxdb() { var testContainersBuilder = new TestcontainersBuilder <TestcontainersContainer>() .WithDockerEndpoint(DockerUtils.DockerEndpoint()) .WithImage("influxdb:1.8-alpine") .WithEnvironment("INFLUXDB_DB", "mydb") .WithEnvironment("INFLUXDB_USER", "my_user") .WithEnvironment("INFLUXDB_HTTP_AUTH_ENABLED", "false") .WithPortBinding(8086, assignRandomHostPort: true) .WithWaitStrategy(Wait.ForUnixContainer().UntilPortIsAvailable(8086)); await using var container = testContainersBuilder.Build(); await container.StartAsync(); var baseUrl = $"http://{container.Hostname}:{container.GetMappedPublicPort(8086)}"; var config = new InfluxConfig(new Uri(baseUrl), "mydb", "my_user", null); using var writer = new InfluxWriter(config, "my-pc"); using var client = new HttpClient(); for (int attempts = 0;; attempts++) { try { await writer.ReportMetrics(DateTime.Now, TestSensorCreator.Values()); var resp = await client.GetAsync( $"{baseUrl}/query?pretty=true&db=mydb&q=SELECT%20*%20FROM%20Temperature"); Assert.True(resp.IsSuccessStatusCode); var content = await resp.Content.ReadAsStringAsync(); Assert.Contains("/intelcpu/0/temperature/0", content); break; } catch (Exception) { if (attempts >= 10) { throw; } Thread.Sleep(TimeSpan.FromSeconds(1)); } } }
public void InfluxReport_CanAddRecords_ForGauge() { var config = new InfluxConfig("localhost", "testdb"); var writer = new InfluxdbTestWriter(config); config.Writer = writer; var report = new InfluxdbHttpReport(config); var context = new DefaultMetricsContext("TestContext"); var precision = config.Precision ?? InfluxConfig.Default.Precision; var metricsData = context.DataProvider.CurrentMetricsData; report.RunReport(metricsData, hsFunc, CancellationToken.None); writer.LastBatch.Should().BeEmpty("Because running a report with no metrics should not result in any records."); context.Gauge("test_gauge", () => 123.456, Unit.Bytes, new MetricTags("key1=value1,tag2,tag3,key4=value4")); metricsData = context.DataProvider.CurrentMetricsData; report.RunReport(metricsData, hsFunc, CancellationToken.None); writer.LastBatch.Should().HaveCount(1); var expTime = InfluxLineProtocol.FormatTimestamp(metricsData.Timestamp, precision); writer.LastBatch[0].ToLineProtocol(precision).Should().Be($@"testcontext.test_gauge,key1=value1,key4=value4 value=123.456 {expTime}"); }
/// <summary> /// Creates a new <see cref="InfluxdbHttpWriter"/> with the specified configuration and batch size. /// </summary> /// <param name="config">The InfluxDB configuration.</param> /// <param name="batchSize">The maximum number of records to write per flush. Set to zero to write all records in a single flush. Negative numbers are not allowed.</param> public InfluxdbHttpWriter(InfluxConfig config, Int32 batchSize = 0) : base(config, batchSize) { if (String.IsNullOrEmpty(config.Hostname)) { throw new ArgumentNullException(nameof(config.Hostname)); } if (String.IsNullOrEmpty(config.Database)) { throw new ArgumentNullException(nameof(config.Database)); } this.influxDbUri = FormatInfluxUri(config); if (influxDbUri == null) { throw new ArgumentNullException(nameof(influxDbUri)); } if (influxDbUri.Scheme != Uri.UriSchemeHttp && influxDbUri.Scheme != Uri.UriSchemeHttps) { throw new ArgumentException($"The URI scheme must be either http or https. Scheme: {influxDbUri.Scheme}", nameof(influxDbUri)); } }
/// <summary> /// Sets the Formatter on the InfluxDB reporter configuration and returns the same instance. /// </summary> /// <param name="config">The InfluxDB reporter configuration.</param> /// <param name="formatter">The InfluxDB metric formatter.</param> /// <param name="configFunc">A lambda expression that allows further configuration of the <see cref="InfluxdbFormatter"/> using fluent syntax.</param> /// <returns>This <see cref="InfluxConfig"/> instance.</returns> public static InfluxConfig WithFormatter(this InfluxConfig config, InfluxdbFormatter formatter, Action <InfluxdbFormatter> configFunc = null) { configFunc?.Invoke(formatter); config.Formatter = formatter; return(config); }
/// <summary> /// Creates a <see cref="DefaultFormatter"/> and passes it to the configuration lambda expression, then sets the formatter on the InfluxDB configuration and returns the same instance. /// </summary> /// <param name="config">The InfluxDB reporter configuration.</param> /// <param name="configFunc">A lambda expression that allows further configuration of the <see cref="InfluxdbFormatter"/> using fluent syntax.</param> /// <returns>This <see cref="InfluxConfig"/> instance.</returns> public static InfluxConfig WithFormatter(this InfluxConfig config, Action <InfluxdbFormatter> configFunc = null) { var formatter = new DefaultFormatter(); return(WithFormatter(config, formatter, configFunc)); }
/// <summary> /// Sets the Converter on the InfluxDB reporter configuration and returns the same instance. /// </summary> /// <param name="config">The InfluxDB reporter configuration.</param> /// <param name="converter">The InfluxDB metric converter.</param> /// <param name="configFunc">A lambda expression that allows further configuration of the <see cref="InfluxdbConverter"/> using fluent syntax.</param> /// <returns>This <see cref="InfluxConfig"/> instance.</returns> public static InfluxConfig WithConverter(this InfluxConfig config, InfluxdbConverter converter, Action <InfluxdbConverter> configFunc = null) { configFunc?.Invoke(converter); config.Converter = converter; return(config); }
/// <summary> /// Creates a <see cref="DefaultConverter"/> and passes it to the configuration lambda expression, then sets the converter on the InfluxDB configuration and returns the same instance. /// </summary> /// <param name="config">The InfluxDB reporter configuration.</param> /// <param name="configFunc">A lambda expression that allows further configuration of the <see cref="InfluxdbConverter"/> using fluent syntax.</param> /// <returns>This <see cref="InfluxConfig"/> instance.</returns> public static InfluxConfig WithConverter(this InfluxConfig config, Action <InfluxdbConverter> configFunc = null) { var converter = new DefaultConverter(); return(WithConverter(config, converter, configFunc)); }
/// <summary> /// Sets the Writer on the InfluxDB reporter configuration and returns the same instance. /// </summary> /// <param name="config">The InfluxDB reporter configuration.</param> /// <param name="writer">The InfluxDB metric writer.</param> /// <param name="configFunc">A lambda expression that allows further configuration of the <see cref="InfluxdbWriter"/> using fluent syntax.</param> /// <returns>This <see cref="InfluxConfig"/> instance.</returns> public static InfluxConfig WithWriter(this InfluxConfig config, InfluxdbWriter writer, Action <InfluxdbWriter> configFunc = null) { configFunc?.Invoke(writer); config.Writer = writer; return(config); }
/// <summary> /// Sets the Writer on the InfluxDB reporter configuration and returns the same instance. /// </summary> /// <param name="config">The InfluxDB reporter configuration.</param> /// <param name="username">The username.</param> /// <param name="password">The username.</param> /// <returns>This <see cref="InfluxConfig"/> instance.</returns> public static InfluxConfig WithCredentials(this InfluxConfig config, String username, String password) { config.Username = username; config.Password = password; return(config); }
/// <summary> /// Creates a new <see cref="InfluxdbTestWriter"/> with the specified configuration and batch size. /// </summary> /// <param name="config">The InfluxDB configuration.</param> /// <param name="batchSize">The maximum number of records to write per flush. Set to zero to write all records in a single flush. Negative numbers are not allowed.</param> public InfluxdbTestWriter(InfluxConfig config, Int32 batchSize = 0) : base(config, batchSize) { }
/// <summary> /// Creates a new InfluxDB report that uses the Line Protocol syntax over HTTP. /// </summary> /// <param name="config">The InfluxDB configuration object.</param> public DefaultInfluxdbReport(InfluxConfig config = null) : base(config) { }
/// <summary> /// Returns an instance with the default configuration for the derived type's implementation. /// If <paramref name="defaultConfig"/> is specified, the default converter, formatter, and /// writer are applied to it if any are not set; otherwise creates and returns a new instance. /// </summary> /// <param name="defaultConfig">The configuration instance to apply the default converter, formatter, and writer to.</param> /// <returns>A default <see cref="InfluxConfig"/> instance for the derived type's implementation.</returns> protected virtual InfluxConfig GetDefaultConfig(InfluxConfig defaultConfig) { return(defaultConfig); }
/// <summary> /// Creates a new InfluxDB report that uses the Line Protocol syntax over UDP. /// </summary> /// <param name="config">The InfluxDB configuration object.</param> public InfluxdbUdpReport(InfluxConfig config = null) : base(config) { }
/// <summary> /// Creates an HTTP URI for InfluxDB using the values specified in the <see cref="InfluxConfig"/> object. /// </summary> /// <param name="config">The configuration object to get the relevant fields to build the HTTP URI from.</param> /// <returns>A new InfluxDB URI using the configuration specified in the <paramref name="config"/> parameter.</returns> protected static Uri FormatInfluxUri(InfluxConfig config) { UInt16 port = (config.Port ?? 0) > 0 ? config.Port.Value : InfluxConfig.Default.PortHttp; return(InfluxUtils.FormatInfluxUri(InfluxUtils.SchemeHttp, config.Hostname, port, config.Database, config.Username, config.Password, config.RetentionPolicy, config.Precision)); }
/// <summary> /// Creates a new <see cref="InfluxdbJsonWriterExt"/> with the specified URI. /// </summary> /// <param name="config">The InfluxDB configuration.</param> /// <param name="batchSize">The maximum number of records to write per flush. Set to zero to write all records in a single flush. Negative numbers are not allowed.</param> public InfluxdbJsonWriterExt(InfluxConfig config, Int32 batchSize = 0) : base(config, batchSize) { }
/// <summary> /// Creates an HTTP JSON URI for InfluxDB using the values specified in the <see cref="InfluxConfig"/> object. /// </summary> /// <param name="config">The configuration object to get the relevant fields to build the HTTP URI from.</param> /// <returns>A new InfluxDB JSON URI using the configuration specified in the <paramref name="config"/> parameter.</returns> protected Uri FormatInfluxUri(InfluxConfig config) { InfluxPrecision prec = config.Precision ?? InfluxConfig.Default.Precision; return(new Uri($@"http://{config.Hostname}:{config.Port}/db/{config.Database}/series?u={config.Username}&p={config.Password}&time_precision={prec.ToShortName()}")); }