public MetricsManager(Executor executor, ISocketFactory socket_factory, AwsCredentialsProvider creds, KPLNETConfiguration config, string region, string cw_namespace = "KinesisProducerLib", Level level = Level.Detailed, Granularity granularity = Granularity.Shard, ExtraDimensions extra_dimensions = null, string custom_endpoint = "", ulong port = 443, double upload_frequency = 1 * 60 * 1000, double retry_frequency = 10 * 1000) { if (extra_dimensions == null) { extra_dimensions = new ExtraDimensions(); } this.creds = creds; this.config_ = config; this.region = region; this.metrics_index = new MetricsIndex(); region_ = Core.Clients.KinesisClient.AwsKinesisClient.MapRegion(config.region); this.cw_namespace = cw_namespace; this.socket_factory_ = socket_factory; this.level = level; this.granularity = granularity; this.upload_frequency = upload_frequency; this.retry_frequency = retry_frequency; this.executor = executor; this.endpoint = string.IsNullOrEmpty(custom_endpoint) ? "monitoring." + region + ".amazonaws.com" : custom_endpoint; this.http_client = new AwsHttpClient(executor, socket_factory_, endpoint, (int)port, true, string.IsNullOrEmpty(custom_endpoint)); retryable_requests = new List <string>(); if (level != Level.None) { StdErrorOut.Instance.StdOut(LogLevel.warn, string.Format("Uploading metrics to {0}:{1}", endpoint, port)); } extra_dimensionsMap[Granularity.Global] = new Dimensions(); extra_dimensionsMap[Granularity.Stream] = new Dimensions(); extra_dimensionsMap[Granularity.Shard] = new Dimensions(); foreach (var t in extra_dimensions) { extra_dimensionsMap[t.Item3].Add(new KeyValuePair <string, string>(t.Item1, t.Item2)); } scheduled_upload = executor.Schedule( () => { try { scheduled_upload.reschedule(upload_frequency); upload(); } catch (Exception ex) { StdErrorOut.Instance.StdError("Scheduled Upload failed.", ex); } }, upload_frequency); scheduled_retry = executor.Schedule( () => { try { scheduled_retry.reschedule(retry_frequency); retry_uploads(); } catch (Exception ex) { StdErrorOut.Instance.StdError("Scheduled Upload failed.", ex); } }, retry_frequency); }
private static string ConvertExtraDimensions(ExtraDimensions dim) { switch (dim) { case ExtraDimensions.Meters: return "пог. м."; case ExtraDimensions.Piece: return "шт."; case ExtraDimensions.SquareMeter: return "кв. м."; } return string.Empty; }