private string CreateWriteUrl(string db, InfluxWriteOptions options) { var url = $"write?db={UriHelper.SafeEscapeDataString(db)}&precision={options.Precision.GetQueryParameter()}&consistency={options.Consistency.GetQueryParameter()}"; if (!string.IsNullOrEmpty(options.RetentionPolicy)) { url += $"&rp={options.RetentionPolicy}"; } return(new Uri(_endpoint, url).ToString()); }
private InfluxClient(Uri endpoint, string username, string password, HttpClient client, bool disposeHttpClient) { _disposeHttpClientHandler = disposeHttpClient; _seriesMetaCache = new Dictionary <DatabaseMeasurementInfoKey, DatabaseMeasurementInfo>(); _endpoint = endpoint; _client = client; DefaultWriteOptions = new InfluxWriteOptions(); DefaultQueryOptions = new InfluxQueryOptions(); TimestampParserRegistry = new DefaultTimestampParserRegistry(); if (!string.IsNullOrEmpty(username) && !string.IsNullOrEmpty(password)) { var encoding = Encoding.GetEncoding("ISO-8859-1"); var credentials = username + ":" + password; var encodedCredentialBytes = encoding.GetBytes(credentials); var encodedCredentials = Convert.ToBase64String(encodedCredentialBytes); _authzHeader = new AuthenticationHeaderValue("Basic", encodedCredentials); } }
/// <summary> /// Constructs an InfluxClient that uses the specified credentials. /// </summary> /// <param name="endpoint"></param> /// <param name="username"></param> /// <param name="password"></param> public InfluxClient(Uri endpoint, string username, string password) { _handler = new HttpClientHandler(); _handler.AutomaticDecompression = DecompressionMethods.Deflate | DecompressionMethods.GZip; _client = new HttpClient(_handler, false); _client.BaseAddress = endpoint; _seriesMetaCache = new Dictionary <DatabaseMeasurementInfoKey, DatabaseMeasurementInfo>(); DefaultWriteOptions = new InfluxWriteOptions(); DefaultQueryOptions = new InfluxQueryOptions(); if (!string.IsNullOrEmpty(username) && !string.IsNullOrEmpty(password)) { var encoding = Encoding.GetEncoding("ISO-8859-1"); var credentials = username + ":" + password; var encodedCredentialBytes = encoding.GetBytes(credentials); var encodedCredentials = Convert.ToBase64String(encodedCredentialBytes); _client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", encodedCredentials); } }
/// <summary> /// Writes the rows with the specified write options. /// </summary> /// <typeparam name="TInfluxRow"></typeparam> /// <param name="db"></param> /// <param name="measurementName"></param> /// <param name="rows"></param> /// <param name="options"></param> /// <returns></returns> public Task WriteAsync <TInfluxRow>(string db, string measurementName, IEnumerable <TInfluxRow> rows, InfluxWriteOptions options) where TInfluxRow : new() { List <HttpContent> contents = new List <HttpContent>(); foreach (var groupOfRows in rows.GroupBy(x => x.GetType())) { var info = MetadataCache.GetOrCreate(groupOfRows.Key); var c = info.CreateHttpContentFor(this, groupOfRows, measurementName, options); contents.Add(c); } if (contents.Count == 0) { return(TaskHelpers.CompletedTask); } var content = contents.Count == 1 ? contents[0] : new MultiContent(contents); if (options.UseGzip) { content = new GzipContent(content); } return(PostInternalIgnoreResultAsync(CreateWriteUrl(db, options), content)); }
private string CreateWriteUrl(string db, InfluxWriteOptions options) { return($"write?db={Uri.EscapeDataString( db )}&precision={options.Precision.GetQueryParameter()}&consistency={options.Consistency.GetQueryParameter()}"); }
private Task WriteAsync <TInfluxRow>(string db, Func <TInfluxRow, string> getMeasurementName, IEnumerable <TInfluxRow> rows, InfluxWriteOptions options) where TInfluxRow : new() { return(PostInternalIgnoreResultAsync(CreateWriteUrl(db, options), new InfluxRowContent <TInfluxRow>(rows, getMeasurementName, options.Precision))); }
/// <summary> /// Writes the rows with the specified write options. /// </summary> /// <typeparam name="TInfluxRow"></typeparam> /// <param name="db"></param> /// <param name="rows"></param> /// <param name="options"></param> /// <returns></returns> public Task WriteAsync <TInfluxRow>(string db, IEnumerable <TInfluxRow> rows, InfluxWriteOptions options) where TInfluxRow : IHaveMeasurementName, new() { return(WriteAsync(db, x => x.MeasurementName, rows, options)); }
/// <summary> /// Writes the rows with the specified write options. /// </summary> /// <typeparam name="TInfluxRow"></typeparam> /// <param name="client">The IInfluxClient that performs operation.</param> /// <param name="db"></param> /// <param name="rows"></param> /// <param name="options"></param> /// <returns></returns> public static Task WriteAsync <TInfluxRow>(this IInfluxClient client, string db, IEnumerable <TInfluxRow> rows, InfluxWriteOptions options) where TInfluxRow : new() { return(client.WriteAsync(db, null, rows, options)); }