Ejemplo n.º 1
0
        public StreamConsumer([NotNull] StreamConsumerSettings <T> settings, [CanBeNull] ILog log)
        {
            this.settings = settings ?? throw new ArgumentNullException(nameof(settings));
            this.log      = (log ?? LogProvider.Get()).ForContext <StreamConsumer <T> >();

            streamReader = new StreamReader <T>(
                new StreamReaderSettings <T>(
                    settings.StreamName,
                    settings.StreamClient)
            {
                EventsReadTimeout   = settings.EventsReadTimeout,
                EventsReadBatchSize = settings.EventsReadBatchSize,
                EventsReadAttempts  = settings.EventsReadAttempts,
                DelayOnError        = settings.DelayOnError
            },
                log);

            eventsMetric = settings.MetricContext?.CreateIntegerGauge("events", "type", new IntegerGaugeConfig {
                ResetOnScrape = true
            });
            iterationMetric = settings.MetricContext?.CreateSummary("iteration", "type", new SummaryConfig {
                Quantiles = new[] { 0.5, 0.75, 1 }
            });
            settings.MetricContext?.CreateFuncGauge("events", "type").For("remaining").SetValueProvider(() => CountStreamRemainingEvents());
        }
            public ReportingObserver(IMetricContext metricContext, TimeSpan?period)
            {
                var config = new FloatingGaugeConfig
                {
                    ResetOnScrape = true,
                    Unit          = WellKnownUnits.Milliseconds,
                    ScrapePeriod  = period
                };

                gcTotalDuration   = metricContext.CreateFloatingGauge("GcTotalDurationMs", "GcType", config);
                gcLongestDuration = metricContext.CreateFloatingGauge("GcLongestDurationMs", "GcType", config);
            }
        public WindowedStreamConsumer([NotNull] WindowedStreamConsumerSettings <T, TKey> settings, [CanBeNull] ILog log)
            : base(settings, log)
        {
            this.settings = settings ?? throw new ArgumentNullException(nameof(settings));
            this.log      = (log ?? LogProvider.Get()).ForContext <WindowedStreamConsumer <T, TKey> >();
            tracer        = settings.Tracer ?? TracerProvider.Get();

            windows = new Dictionary <TKey, Windows <T, TKey> >();

            var applicationMetricContext = settings.ApplicationMetricContext ?? new DevNullMetricContext();

            eventLagMetric = applicationMetricContext.CreateHistogram("eventLag", new HistogramConfig {
                Buckets = HistogramHelper.CreateDefaultBuckets(), Unit = WellKnownUnits.Milliseconds
            });

            var instanceMetricContext = settings.InstanceMetricContext ?? new DevNullMetricContext();

            stateMetric = instanceMetricContext.CreateIntegerGauge("state", "type");

            var settingsOnBatchEnd = settings.OnBatchEnd;

            settings.OnBatchEnd = c =>
            {
                FlushWindows();
                Task.Run(() => settings.LeftCoordinatesStorage.AdvanceAsync(leftCoordinates));
                settingsOnBatchEnd?.Invoke(c);
            };

            var settingsOnEvent = settings.OnEvent;

            settings.OnEvent = (e, c) =>
            {
                AddEvent(e, c);
                settingsOnEvent?.Invoke(e, c);
            };

            var settingsOnRestart = settings.OnRestart;

            settings.OnRestart = c =>
            {
                Restart(c).GetAwaiter().GetResult();
                settingsOnRestart?.Invoke(c);
            };

            var settingsOnStop = settings.OnStop;

            settings.OnStop = c =>
            {
                Stop(c).GetAwaiter().GetResult();
                settingsOnStop?.Invoke(c);
            };
        }
Ejemplo n.º 4
0
        public ThrottlingMetrics(
            [NotNull] IThrottlingProvider provider,
            [NotNull] IMetricContext metricContext,
            [NotNull] ThrottlingMetricsOptions options)
        {
            eventSubscription  = provider.Subscribe(this as IObserver <IThrottlingEvent>);
            resultSubscription = provider.Subscribe(this as IObserver <IThrottlingResult>);

            var integerGaugeConfig = new IntegerGaugeConfig {
                InitialValue = 0, ResetOnScrape = true
            };
            var propertiesGaugeConfig = new IntegerGaugeConfig {
                InitialValue = 0, ResetOnScrape = true, SendZeroValues = false
            };
            var floatingGaugeConfig = new FloatingGaugeConfig {
                InitialValue = 0, ResetOnScrape = true
            };
            var summaryConfig = new SummaryConfig();
            var counterConfig = new CounterConfig();

            if (options.ScrapePeriod != null)
            {
                integerGaugeConfig.ScrapePeriod     = options.ScrapePeriod;
                floatingGaugeConfig.ScrapePeriod    = options.ScrapePeriod;
                summaryConfig.ScrapePeriod          = options.ScrapePeriod;
                counterConfig.ScrapePeriod          = options.ScrapePeriod;
                counterConfig.AggregationParameters = new Dictionary <string, string>().SetAggregationPeriod(options.ScrapePeriod.Value);
            }

            waitTimeSummary  = metricContext.CreateSummary("queueWaitTime", summaryConfig);
            rejectionCounter = metricContext.CreateCounter("rejectionsCount", "status", counterConfig);

            maxCapacityLimit       = metricContext.CreateIntegerGauge("maxCapacityLimit", integerGaugeConfig);
            maxCapacityConsumed    = metricContext.CreateIntegerGauge("maxCapacityConsumed", integerGaugeConfig);
            maxCapacityUtilization = metricContext.CreateFloatingGauge("maxCapacityUtilization", floatingGaugeConfig);

            maxQueueLimit       = metricContext.CreateIntegerGauge("maxQueueLimit", integerGaugeConfig);
            maxQueueSize        = metricContext.CreateIntegerGauge("maxQueueSize", integerGaugeConfig);
            maxQueueUtilization = metricContext.CreateFloatingGauge("maxQueueUtilization", floatingGaugeConfig);

            maxConsumptionPerProperty = options.PropertiesWithConsumptionTracking
                                        .ToDictionary(
                property => property,
                property => metricContext
                .WithTag("scope", "property")
                .WithTag("propertyName", property)
                .CreateIntegerGauge("maxConsumption", "propertyValue", propertiesGaugeConfig));
            propertyConsumptionTrackingThreshold = options.PropertyConsumptionTrackingThreshold;
        }
Ejemplo n.º 5
0
        public StreamBinaryWriter([NotNull] StreamBinaryWriterSettings settings, [CanBeNull] ILog log)
        {
            this.settings = settings ?? throw new ArgumentNullException(nameof(settings));
            this.log      = log = (log ?? LogProvider.Get()).ForContext <StreamBinaryWriter>();

            var bufferPool = new BufferPool(settings.MaxPooledBufferSize, settings.MaxPooledBuffersPerBucket);

            client = new GateRequestSender(settings.GateCluster, log /*.WithErrorsTransformedToWarns()*/, bufferPool, settings.GateClientAdditionalSetup);
            tracer = settings.Tracer ?? TracerProvider.Get();

            eventsMetric = settings.MetricContext?.CreateIntegerGauge("events", "type", new IntegerGaugeConfig {
                ResetOnScrape = true
            });
            iterationMetric = settings.MetricContext?.CreateSummary("iteration", "type", new SummaryConfig {
                Quantiles = new[] { 0.5, 0.75, 1 }
            });
            settings.MetricContext?.CreateFuncGauge("buffer", "type").For("rented_writer").SetValueProvider(() => BufferPool.Rented);
        }
Ejemplo n.º 6
0
        public StreamBinaryEventsWriter(StreamBinaryEventsWriterSettings settings, ILog log)
        {
            this.settings = settings ?? throw new ArgumentNullException(nameof(settings));
            this.log      = (log ?? LogProvider.Get()).ForContext <StreamBinaryEventsWriter>();

            iterationMetric = settings.MetricContext.CreateSummary("iteration", "type", new SummaryConfig {
                Quantiles = new[] { 0.5, 0.75, 1 }
            });

            emptyWriters = Channel.CreateUnbounded <Writer>(new UnboundedChannelOptions
            {
                SingleReader = true,
                SingleWriter = false,
                AllowSynchronousContinuations = false
            });

            for (var i = 0; i < settings.WritersPoolCapacity; i++)
            {
                emptyWriters.Writer.WriteAsync(new Writer(settings.WriterCapacity.Bytes)).AsTask().GetAwaiter().GetResult();
            }
        }
        public BatchesStreamConsumer([NotNull] BatchesStreamConsumerSettings <T> settings, [CanBeNull] ILog log)
        {
            this.settings = settings ?? throw new ArgumentNullException(nameof(settings));
            this.log      = log = (log ?? LogProvider.Get()).ForContext <BatchesStreamConsumer <T> >();
            tracer        = settings.Tracer ?? TracerProvider.Get();

            var bufferPool = new BufferPool(settings.MaxPooledBufferSize, settings.MaxPooledBuffersPerBucket);

            client = new StreamApiRequestSender(settings.StreamApiCluster, log /*.WithErrorsTransformedToWarns()*/, bufferPool, settings.StreamApiClientAdditionalSetup);

            var instanceMetricContext = settings.InstanceMetricContext ?? new DevNullMetricContext();

            eventsMetric = instanceMetricContext.CreateIntegerGauge("events", "type", new IntegerGaugeConfig {
                ResetOnScrape = true
            });
            iterationMetric = instanceMetricContext.CreateSummary("iteration", "type", new SummaryConfig {
                Quantiles = new[] { 0.5, 0.75, 1 }
            });
            instanceMetricContext.CreateFuncGauge("events", "type").For("remaining").SetValueProvider(CountStreamRemainingEvents);
            instanceMetricContext.CreateFuncGauge("buffer", "type").For("rented_reader").SetValueProvider(() => BufferPool.Rented);
        }
Ejemplo n.º 8
0
        public MetricsProvider(IMetricContext metricContext, string environment, string clientName)
        {
            var sendZeroValuesCounterConfig = new CounterConfig
            {
                ScrapePeriod   = TimeSpan.FromMinutes(1),
                SendZeroValues = false
            };

            var metricsTags = new MetricTags(
                new MetricTag("project", SingularConstants.ProjectName),
                new MetricTag("environment", environment),
                new MetricTag("application", SingularConstants.ServiceName),
                new MetricTag("cluster", SingularConstants.DefaultCluster),
                new MetricTag("version", Version),
                new MetricTag("clientName", clientName)
                );

            var metricsContext = metricContext.WithTags(metricsTags);

            requestReasonsCounter = metricsContext.CreateCounter("client", "reason", sendZeroValuesCounterConfig);
        }
Ejemplo n.º 9
0
        public WindowedStreamConsumer([NotNull] WindowedStreamConsumerSettings <T, TKey> settings, [CanBeNull] ILog log)
            : base(settings, log)
        {
            this.settings = settings ?? throw new ArgumentNullException(nameof(settings));
            this.log      = (log ?? LogProvider.Get()).ForContext <WindowedStreamConsumer <T, TKey> >();
            tracer        = settings.Tracer ?? TracerProvider.Get();

            windows = new Dictionary <TKey, Windows <T, TKey> >();

            var settingsOnBatchEnd = settings.OnBatchEnd;

            settings.OnBatchEnd = c =>
            {
                FlushWindows();
                settings.LeftCoordinatesStorage.AdvanceAsync(leftCoordinates);
                settingsOnBatchEnd?.Invoke(c);
            };

            var settingsOnEvent = settings.OnEvent;

            settings.OnEvent = (e, c) =>
            {
                AddEvent(e, c);
                settingsOnEvent?.Invoke(e, c);
            };

            var settingsOnRestart = settings.OnRestart;

            settings.OnRestart = c =>
            {
                Restart(c).GetAwaiter().GetResult();
                settingsOnRestart?.Invoke(c);
            };

            var metricContext = settings.MetricContext ?? new DevNullMetricContext();

            stateMetric = metricContext.CreateIntegerGauge("state", "type");
        }
Ejemplo n.º 10
0
            public TransformingEventHandler(StreamTransformerSettings settings, ILog log)
            {
                this.settings = settings;
                this.log      = log;

                buffer = new List <HerculesEvent>();

                writer = new StreamWriter(
                    new StreamWriterSettings(settings.TargetStreamName, settings.GateClient)
                {
                    DelayOnError         = settings.DelayOnError,
                    EventsWriteBatchSize = settings.EventsWriteBatchSize,
                    EventsWriteTimeout   = settings.EventsWriteTimeout
                },
                    log);

                eventsMetric = settings.MetricContext?.CreateIntegerGauge("events", "type", new IntegerGaugeConfig {
                    ResetOnScrape = true
                });
                iterationMetric = settings.MetricContext?.CreateSummary("iteration", "type", new SummaryConfig {
                    Quantiles = new[] { 0.5, 0.75, 1 }
                });
            }
Ejemplo n.º 11
0
 public MetricsModule(IMetricContext metricContext)
 {
     codesCounter = metricContext.CreateCounter("code", "value");
     timer        = metricContext.CreateTimer("time");
 }