public void CollectMetrics(IMetricsCollector metricsCollector) { if (metricsCollector != null) { this.MetricsCollector = metricsCollector; } }
public void Initialize(IMetricsCollector collector) { if (_throwOnInitialize) { throw new Exception("Arghhhhh! Initialization blew up!"); } }
public override void Detach(IMetricsCollector collector) { if (_throwOnDetach) { throw new Exception("Arghhhhh! Detach blew up!"); } }
internal AgentComponents( IApmLogger logger, IConfigurationReader configurationReader, IPayloadSender payloadSender, IMetricsCollector metricsCollector, ICurrentExecutionSegmentsContainer currentExecutionSegmentsContainer ) { var tempLogger = logger ?? ConsoleLogger.LoggerOrDefault(configurationReader?.LogLevel); ConfigurationReader = configurationReader ?? new EnvironmentConfigurationReader(tempLogger); Logger = logger ?? ConsoleLogger.LoggerOrDefault(ConfigurationReader.LogLevel); Service = Service.GetDefaultService(ConfigurationReader, Logger); var systemInfoHelper = new SystemInfoHelper(Logger); var system = systemInfoHelper.ReadContainerId(Logger); PayloadSender = payloadSender ?? new PayloadSenderV2(Logger, ConfigurationReader, Service, system); MetricsCollector = metricsCollector ?? new MetricsCollector(Logger, PayloadSender, ConfigurationReader); MetricsCollector.StartCollecting(); TracerInternal = new Tracer(Logger, Service, PayloadSender, ConfigurationReader, currentExecutionSegmentsContainer ?? new CurrentExecutionSegmentsContainer(Logger)); }
internal AgentComponents( IMetricsCollector metricsCollector, IApmLogger logger = null, IConfigurationReader configurationReader = null, IPayloadSender payloadSender = null ) : this(logger, configurationReader, payloadSender) => (MetricsCollector = metricsCollector ?? new MetricsCollector(Logger, PayloadSender, ConfigurationReader)).StartCollecting();
/// <inheritdoc/> public void Initialize(IMetricsCollector collector) { const string MicrosoftAspNetCoreHostingEventSourceName = "Microsoft.AspNetCore.Hosting"; _diagnosticsCollector.AddSource( new EventPipeProvider( MicrosoftAspNetCoreHostingEventSourceName, EventLevel.Informational, arguments: new Dictionary <string, string>() { { "EventCounterIntervalSec", collector.ReportingInterval.TotalSeconds.ToString() } } ) ); void AddCounterCallback(string name, Counter counter) => _diagnosticsCollector.AddCounterCallback(MicrosoftAspNetCoreHostingEventSourceName, name, counter.Increment); void AddGaugeCallback(string name, SamplingGauge gauge) => _diagnosticsCollector.AddGaugeCallback(MicrosoftAspNetCoreHostingEventSourceName, name, gauge.Record); var requestsPerSec = collector.CreateMetric <Counter>("dotnet.kestrel.requests.per_sec", "requests/sec", "Requests per second", includePrefix: false); var totalRequests = collector.CreateMetric <SamplingGauge>("dotnet.kestrel.requests.total", "requests", "Total requests", includePrefix: false); var currentRequests = collector.CreateMetric <SamplingGauge>("dotnet.kestrel.requests.current", "requests", "Currently executing requests", includePrefix: false); var failedRequests = collector.CreateMetric <SamplingGauge>("dotnet.kestrel.requests.failed", "requests", "Failed requests", includePrefix: false); AddCounterCallback("requests-per-sec", requestsPerSec); AddGaugeCallback("total-requests", totalRequests); AddGaugeCallback("current-requests", currentRequests); AddGaugeCallback("failed-requests", failedRequests); }
/// <inheritdoc/> public void Initialize(IMetricsCollector collector) { _processorTime = collector.CreateMetric <SamplingGauge>("dotnet.cpu.processortime", "seconds", "Total processor time", includePrefix: false); _virtual = collector.CreateMetric <SamplingGauge>("dotnet.mem.virtual", "bytes", "Virtual memory for the process", includePrefix: false); _paged = collector.CreateMetric <SamplingGauge>("dotnet.mem.paged", "bytes", "Paged memory for the process", includePrefix: false); _threads = collector.CreateMetric <SamplingGauge>("dotnet.cpu.threads", "threads", "Threads for the process", includePrefix: false); }
internal AgentComponents( IApmLogger logger, IConfigurationReader configurationReader, IPayloadSender payloadSender, IMetricsCollector metricsCollector, ICurrentExecutionSegmentsContainer currentExecutionSegmentsContainer, ICentralConfigFetcher centralConfigFetcher ) { var tempLogger = logger ?? ConsoleLogger.LoggerOrDefault(configurationReader?.LogLevel); ConfigurationReader = configurationReader ?? new EnvironmentConfigurationReader(tempLogger); Logger = logger ?? ConsoleLogger.LoggerOrDefault(ConfigurationReader.LogLevel); Service = Service.GetDefaultService(ConfigurationReader, Logger); var systemInfoHelper = new SystemInfoHelper(Logger); var system = systemInfoHelper.ParseSystemInfo(); ConfigStore = new ConfigStore(new ConfigSnapshotFromReader(ConfigurationReader, "local"), Logger); PayloadSender = payloadSender ?? new PayloadSenderV2(Logger, ConfigStore.CurrentSnapshot, Service, system); MetricsCollector = metricsCollector ?? new MetricsCollector(Logger, PayloadSender, ConfigurationReader); MetricsCollector.StartCollecting(); CentralConfigFetcher = centralConfigFetcher ?? new CentralConfigFetcher(Logger, ConfigStore, Service); TracerInternal = new Tracer(Logger, Service, PayloadSender, ConfigStore, currentExecutionSegmentsContainer ?? new CurrentExecutionSegmentsContainer()); }
/// <summary> /// Initializes a new instance of the <see cref="EventHorizonConnectionFactory"/> class. /// </summary> /// <param name="reverseCallClients">The reverse call clients to use for creating event horizon clients.</param> /// <param name="metrics">The system for collecting metrics.</param> /// <param name="loggerFactory">The logger factory to use for creating loggers for the event horizon connections</param> public EventHorizonConnectionFactory( IReverseCallClients reverseCallClients, IMetricsCollector metrics, ILoggerFactory loggerFactory) { _reverseCallClients = reverseCallClients; _metrics = metrics; _loggerFactory = loggerFactory; }
/// <summary> /// Initializes a new instance of the <see cref="ReverseCallClients"/> class. /// </summary> /// <param name="clientManager">The client manager to use for creating gRPC clients.</param> /// <param name="metrics">The metrics collector to use for collecting metrics for reverse call clients.</param> /// <param name="loggerFactory">The logger factory to use for creating loggers.</param> public ReverseCallClients( IClientManager clientManager, IMetricsCollector metrics, ILoggerFactory loggerFactory) { _clientManager = clientManager; _metrics = metrics; _loggerFactory = loggerFactory; }
/// <summary> /// Initializes a new instance of the <see cref="SystemDiagnostics"/> class. /// </summary> /// <param name="logger">The object that logs the given messages.</param> /// <param name="metrics">The object that provides metrics collection methods. May be <see langword="null" />.</param> /// <exception cref="ArgumentNullException"> /// Thrown if <paramref name="logger"/> is <see langword="null" />. /// </exception> public SystemDiagnostics(ILogger logger, IMetricsCollector metrics) { if (logger == null) { throw new ArgumentNullException("logger"); } _logger = logger; _metrics = metrics; }
/// <inheritdoc/> public void Initialize(IMetricsCollector collector) { const string SystemRuntimeEventSourceName = "System.Runtime"; _diagnosticsCollector.AddSource( new EventPipeProvider( SystemRuntimeEventSourceName, EventLevel.Informational, arguments: new Dictionary <string, string>() { { "EventCounterIntervalSec", collector.ReportingInterval.TotalSeconds.ToString() } } ) ); void AddCounterCallback(string name, Counter counter) => _diagnosticsCollector.AddCounterCallback(SystemRuntimeEventSourceName, name, counter.Increment); void AddGaugeCallback(string name, SamplingGauge gauge) => _diagnosticsCollector.AddGaugeCallback(SystemRuntimeEventSourceName, name, gauge.Record); var cpuUsage = collector.CreateMetric <SamplingGauge>("dotnet.cpu.usage", "percent", "% CPU usage", includePrefix: false); var workingSet = collector.CreateMetric <SamplingGauge>("dotnet.mem.working_set", "bytes", "Working set for the process", includePrefix: false); AddGaugeCallback("cpu-usage", cpuUsage); AddGaugeCallback("working-set", workingSet); // GC var gen0 = collector.CreateMetric <Counter>("dotnet.mem.collections.gen0", "collections", "Number of gen-0 collections", includePrefix: false); var gen1 = collector.CreateMetric <Counter>("dotnet.mem.collections.gen1", "collections", "Number of gen-1 collections", includePrefix: false); var gen2 = collector.CreateMetric <Counter>("dotnet.mem.collections.gen2", "collections", "Number of gen-2 collections", includePrefix: false); var gen0Size = collector.CreateMetric <SamplingGauge>("dotnet.mem.size.gen0", "bytes", "Total number of bytes in gen-0", includePrefix: false); var gen1Size = collector.CreateMetric <SamplingGauge>("dotnet.mem.size.gen1", "bytes", "Total number of bytes in gen-1", includePrefix: false); var gen2Size = collector.CreateMetric <SamplingGauge>("dotnet.mem.size.gen2", "bytes", "Total number of bytes in gen-2", includePrefix: false); var heapSize = collector.CreateMetric <SamplingGauge>("dotnet.mem.size.heap", "bytes", "Total number of bytes across all heaps", includePrefix: false); var lohSize = collector.CreateMetric <SamplingGauge>("dotnet.mem.size.loh", "bytes", "Total number of bytes in the LOH", includePrefix: false); var allocRate = collector.CreateMetric <Counter>("dotnet.mem.allocation_rate", "bytes/sec", "Allocation Rate (Bytes / sec)", includePrefix: false); AddGaugeCallback("gc-heap-size", heapSize); AddGaugeCallback("gen-0-size", gen0Size); AddGaugeCallback("gen-1-size", gen1Size); AddGaugeCallback("gen-2-size", gen2Size); AddCounterCallback("gen-0-gc-count", gen0); AddCounterCallback("gen-1-gc-count", gen1); AddCounterCallback("gen-2-gc-count", gen2); AddGaugeCallback("loh-size", lohSize); AddCounterCallback("alloc-rate", allocRate); // thread pool var threadPoolCount = collector.CreateMetric <SamplingGauge>("dotnet.threadpool.count", "threads", "Number of threads in the threadpool", includePrefix: false); var threadPoolQueueLength = collector.CreateMetric <SamplingGauge>("dotnet.threadpool.queue_length", "workitems", "Number of work items queued to the threadpool", includePrefix: false); var timerCount = collector.CreateMetric <SamplingGauge>("dotnet.timers.count", "timers", "Number of active timers", includePrefix: false); AddGaugeCallback("threadpool-thread-count", threadPoolCount); AddGaugeCallback("threadpool-queue-length", threadPoolQueueLength); AddGaugeCallback("active-timer-count", timerCount); }
/// <summary> /// Initializes a new instance of the <see cref="EventHorizonConnection" /> class. /// </summary> /// <param name="executionContext">The <see cref="ExecutionContext"/>.</param> /// <param name="reverseCallClient">The reverse call client.</param> /// <param name="metrics">The system for collecting metrics.</param> /// <param name="logger">The logger.</param> public EventHorizonConnection( ExecutionContext executionContext, IReverseCallClient <ConsumerSubscriptionRequest, Contracts.SubscriptionResponse, ConsumerRequest, ConsumerResponse> reverseCallClient, IMetricsCollector metrics, ILogger logger) { _executionContext = executionContext; _reverseCallClient = reverseCallClient; _metrics = metrics; _logger = logger; }
/// <summary> /// Initializes a new instance of the <see cref="ProjectionPersister"/> class. /// </summary> /// <param name="projectionStore">The projection store to persist to.</param> /// <param name="copyStores">The copy stores to persist to.</param> /// <param name="metrics">The metrics collector to use.</param> /// <param name="logger">The logger to use.</param> public ProjectionPersister( IProjectionStore projectionStore, IEnumerable <IProjectionCopyStore> copyStores, IMetricsCollector metrics, ILogger logger) { _projectionStore = projectionStore; _copyStores = copyStores; _metrics = metrics; _logger = logger; }
/// <summary> /// Initializes a new instance of the <see cref="SubscriptionsService"/> class. /// </summary> /// <param name="executionContextCreator">The execution context creator to use for verifying incoming execution contexts.</param> /// <param name="getSubscriptionsFor">The factory to use to create an <see cref="ISubscriptions"/> for a tenant.</param> /// <param name="metrics">The system for capturing metrics.</param> /// <param name="logger">The logger to use for logging.</param> public SubscriptionsService( ICreateExecutionContexts executionContextCreator, Func <TenantId, ISubscriptions> getSubscriptionsFor, IMetricsCollector metrics, ILogger logger) { _executionContextCreator = executionContextCreator; _getSubscriptionsFor = getSubscriptionsFor; _metrics = metrics; _logger = logger; }
/// <summary> /// Initializes a new instance of the <see cref="ProjectionStore"/> class. /// </summary> /// <param name="projectionStates">The <see cref="IProjectionStates"/> to use for getting projection states.</param> /// <param name="projectionDefinitions">The <see cref="IProjectionStates"/> to use for getting initial projection states.</param> /// <param name="metrics">The metrics collector to use.</param> /// <param name="logger">The logger to use.</param> public ProjectionStore( IProjectionStates projectionStates, IProjectionDefinitions projectionDefinitions, IMetricsCollector metrics, ILogger logger ) { _projectionStates = projectionStates; _projectionDefinitions = projectionDefinitions; _metrics = metrics; _logger = logger; }
internal AgentComponents( IApmLogger logger, IConfigurationReader configurationReader, IPayloadSender payloadSender, IMetricsCollector metricsCollector, ICurrentExecutionSegmentsContainer currentExecutionSegmentsContainer, ICentralConfigFetcher centralConfigFetcher, IApmServerInfo apmServerInfo, BreakdownMetricsProvider breakdownMetricsProvider = null ) { try { var tempLogger = logger ?? ConsoleLogger.LoggerOrDefault(configurationReader?.LogLevel); ConfigurationReader = configurationReader ?? new EnvironmentConfigurationReader(tempLogger); Logger = logger ?? ConsoleLogger.LoggerOrDefault(ConfigurationReader.LogLevel); Service = Service.GetDefaultService(ConfigurationReader, Logger); var systemInfoHelper = new SystemInfoHelper(Logger); var system = systemInfoHelper.ParseSystemInfo(ConfigurationReader.HostName); ConfigStore = new ConfigStore(new ConfigSnapshotFromReader(ConfigurationReader, "local"), Logger); ApmServerInfo = apmServerInfo ?? new ApmServerInfo(); PayloadSender = payloadSender ?? new PayloadSenderV2(Logger, ConfigStore.CurrentSnapshot, Service, system, ApmServerInfo, isEnabled: ConfigurationReader.Enabled); HttpTraceConfiguration = new HttpTraceConfiguration(); if (ConfigurationReader.Enabled) { breakdownMetricsProvider ??= new BreakdownMetricsProvider(Logger); CentralConfigFetcher = centralConfigFetcher ?? new CentralConfigFetcher(Logger, ConfigStore, Service); MetricsCollector = metricsCollector ?? new MetricsCollector(Logger, PayloadSender, ConfigStore, breakdownMetricsProvider); MetricsCollector.StartCollecting(); } else { Logger.Info()?.Log("The Elastic APM .NET Agent is disabled - the agent won't capture traces and metrics."); } TracerInternal = new Tracer(Logger, Service, PayloadSender, ConfigStore, currentExecutionSegmentsContainer ?? new CurrentExecutionSegmentsContainer(), ApmServerInfo, breakdownMetricsProvider); } catch (Exception e) { Logger.Error()?.LogException(e, "Failed initializing agent."); } }
/// <summary> /// Initializes a new instance of the <see cref="ReverseCallDispatchers"/> class. /// </summary> /// <param name="requestIdentifier">The <see cref="IIdentifyRequests"/> for identifying requests.</param> /// <param name="executionContextCreator">The <see cref="ICreateExecutionContexts"/> to use.</param> /// <param name="metricsCollector">The <see cref="IMetricsCollector"/>.</param> /// <param name="loggerFactory">The <see cref="ILoggerFactory"/> to use for creating instances of <see cref="ILogger"/>.</param> /// <param name="pingedConnectionFactory">The <see cref="IKeepConnectionsAlive"/> for creating pinged connections.</param> public ReverseCallDispatchers( IIdentifyRequests requestIdentifier, ICreateExecutionContexts executionContextCreator, IMetricsCollector metricsCollector, ILoggerFactory loggerFactory, IKeepConnectionsAlive pingedConnectionFactory) { _requestIdentifier = requestIdentifier; _executionContextCreator = executionContextCreator; _metricsCollector = metricsCollector; _loggerFactory = loggerFactory; _pingedConnectionFactory = pingedConnectionFactory; }
/// <summary> /// Initializes an instance of the <see cref="StreamProcessor" /> class. /// </summary> /// <param name="streamProcessorStates">The <see cref="IResilientStreamProcessorStateRepository" />.</param> /// <param name="externalEventsCommitter">The <see cref="ICommitExternalEvents"/></param> /// <param name="eventsFetcherPolicy">The <see cref="IAsyncPolicyFor{T}"/> <see cref="ICanFetchEventsFromStream" />.</param> /// <param name="metrics">The system for collecting metrics.</param> /// <param name="loggerFactory">The <see cref="ILoggerFactory" />.</param> public StreamProcessorFactory( IResilientStreamProcessorStateRepository streamProcessorStates, ICommitExternalEvents externalEventsCommitter, IEventFetcherPolicies eventsFetcherPolicy, IMetricsCollector metrics, ILoggerFactory loggerFactory ) { _streamProcessorStates = streamProcessorStates; _externalEventsCommitter = externalEventsCommitter; _eventsFetcherPolicy = eventsFetcherPolicy; _metrics = metrics; _loggerFactory = loggerFactory; }
/// <summary> /// Initializes a new instance of the <see cref="WrappedAsyncStreamReader{TClientMessage, TServerMessage, TConnectArguments, TConnectResponse, TRequest, TResponse}"/> class. /// </summary> /// <param name="requestId">The request id for the gRPC method call.</param> /// <param name="originalStream">The original gRPC stream reader to wrap.</param> /// <param name="messageConverter">The message converter to use to convert the first message received.</param> /// <param name="metrics">The metrics collector to use for metrics about reverse call stream reads.</param> /// <param name="logger">The logger to use.</param> /// <param name="cancellationToken">A cancellation token to use for cancelling pending and future reads.</param> public WrappedAsyncStreamReader( RequestId requestId, IAsyncStreamReader <TClientMessage> originalStream, IConvertReverseCallMessages <TClientMessage, TServerMessage, TConnectArguments, TConnectResponse, TRequest, TResponse> messageConverter, IMetricsCollector metrics, ILogger logger, CancellationToken cancellationToken) { _requestId = requestId; _originalStream = originalStream; _messageConverter = messageConverter; _metrics = metrics; _logger = logger; _cancellationToken = cancellationToken; }
/// <summary> /// Initializes a new instance of the <see cref="EventProcessor"/> class. /// </summary> /// <param name="consentId">THe <see cref="ConsentId" />.</param> /// <param name="subscription">The <see cref="Subscription" />.</param> /// <param name="externalEventsCommitter">The <see cref="ICommitExternalEvents"/>.</param> /// <param name="metrics">The system for collecting metrics.</param> /// <param name="logger">The <see cref="ILogger" />.</param> public EventProcessor( ConsentId consentId, SubscriptionId subscription, ICommitExternalEvents externalEventsCommitter, IMetricsCollector metrics, ILogger logger) { _consentId = consentId; Scope = subscription.ScopeId; Identifier = subscription.ProducerTenantId.Value; _subscriptionId = subscription; _externalEventsCommitter = externalEventsCommitter; _metrics = metrics; _logger = logger; }
/// <summary> /// Initializes a new instance of the <see cref="ConsumerService"/> class. /// </summary> /// <param name="getEventHorizonsConfiguration">The <see cref="Func{TResult}"/> callback for getting <see cref="EventHorizonsPerMicroserviceConfiguration"/> tenant specific configuration.</param> /// <param name="tenants">The <see cref="ITenants"/> system.</param> /// <param name="reverseCalls">The <see cref="IInitiateReverseCallServices" />.</param> /// <param name="protocol">The <see cref="IConsumerProtocol" />.</param> /// <param name="eventHorizons">The <see cref="IEventHorizons"/>.</param> /// <param name="metrics">The system for capturing metrics.</param> /// <param name="logger"><see cref="ILogger"/> for logging.</param> public ConsumerService( Func <TenantId, IOptions <EventHorizonsPerMicroserviceConfiguration> > getEventHorizonsConfiguration, ITenants tenants, IInitiateReverseCallServices reverseCalls, IConsumerProtocol protocol, IEventHorizons eventHorizons, IMetricsCollector metrics, ILogger logger) { _getEventHorizonsConfiguration = getEventHorizonsConfiguration; _tenants = tenants; _reverseCalls = reverseCalls; _protocol = protocol; _eventHorizons = eventHorizons; _metrics = metrics; _logger = logger; }
/// <summary> /// Initializes a new instance of the <see cref="SubscriptionFactory"/> class. /// </summary> /// <param name="streamProcessorFactory">The factory to use for creating stream processors that write the received events.</param> /// <param name="eventHorizonConnectionFactory">The factory to use for creating new connections to the producer Runtime.</param> /// <param name="subscriptionPolicies">The policy to use for handling the <see cref="SubscribeLoop(CancellationToken)"/>.</param> /// <param name="subscriptionPositions">The system to use for getting the next event to receive for a subscription.</param> /// <param name="metrics">The system for collecting metrics.</param> /// <param name="processingMetrics">The system for collecting metrics for event horizon consumer processing.</param> /// <param name="loggerFactory">The logger factory to use for creating loggers.</param> public SubscriptionFactory( IStreamProcessorFactory streamProcessorFactory, IEventHorizonConnectionFactory eventHorizonConnectionFactory, ISubscriptionPolicies subscriptionPolicies, IGetNextEventToReceiveForSubscription subscriptionPositions, IMetricsCollector metrics, Processing.IMetricsCollector processingMetrics, ILoggerFactory loggerFactory) { _loggerFactory = loggerFactory; _streamProcessorFactory = streamProcessorFactory; _eventHorizonConnectionFactory = eventHorizonConnectionFactory; _subscriptionPolicies = subscriptionPolicies; _subscriptionPositions = subscriptionPositions; _metrics = metrics; _processingMetrics = processingMetrics; }
public ClusterMetricsCollector() { _cluster = Cluster.Get(Context.System); _collector = new MetricsCollectorBuilder().Build(Context.System); var metrics = ClusterMetrics.Get(Context.System); // Start periodic gossip to random nodes in cluster var gossipInitialDelay = metrics.Settings.PeriodicTasksInitialDelay.Max(metrics.Settings.CollectorGossipInterval); _gossipTask = Context.System.Scheduler.ScheduleTellRepeatedlyCancelable( gossipInitialDelay, metrics.Settings.CollectorGossipInterval, Self, GossipTick.Instance, Self); // Start periodic metrics collection var sampleInitialDelay = metrics.Settings.PeriodicTasksInitialDelay.Max(metrics.Settings.CollectorSampleInterval); _sampleTask = Context.System.Scheduler.ScheduleTellRepeatedlyCancelable( sampleInitialDelay, metrics.Settings.CollectorSampleInterval, Self, MetricsTick.Instance, Self); }
/// <summary> /// Initializes a new instance of the <see cref="StreamProcessor"/> class. /// </summary> /// <param name="subscriptionId">The identifier of the subscription the stream processor will receive events for.</param> /// <param name="executionContext">The <see cref="ExecutionContext"/>.</param> /// <param name="eventProcessor">The event processor that writes the received events to a scoped event log.</param> /// <param name="eventsFetcher">The event fetcher that receives fetches events over an event horizon connection.</param> /// <param name="streamProcessorStates">The repository to use for getting the subscription state.</param> /// <param name="eventsFetcherPolicy">The policy around fetching events.</param> /// <param name="metrics">The system for collecting metrics.</param> /// <param name="loggerFactory">The factory for creating loggers.</param> public StreamProcessor( SubscriptionId subscriptionId, ExecutionContext executionContext, IEventProcessor eventProcessor, EventsFromEventHorizonFetcher eventsFetcher, IResilientStreamProcessorStateRepository streamProcessorStates, IEventFetcherPolicies eventsFetcherPolicy, IMetricsCollector metrics, ILoggerFactory loggerFactory) { _identifier = subscriptionId; _executionContext = executionContext; _eventProcessor = eventProcessor; _streamProcessorStates = streamProcessorStates; _eventsFetcher = eventsFetcher; _eventsFetcherPolicy = eventsFetcherPolicy; _metrics = metrics; _loggerFactory = loggerFactory; _logger = loggerFactory.CreateLogger <StreamProcessor>(); }
private void EnsureMetricCollector(IConsumingContext <T> context) { if (this.metricsCollectorInitialized) { return; } lock (this) { try { this.metricsCollector = (context.Bus as AbstractBus)?.Configuration?.MetricsCollector; } catch (Exception e) { Log.Warn(m => m("Could not get metric collector"), e); } this.metricsCollectorInitialized = true; } }
/// <summary> /// Gets metrics from the source. /// </summary> /// <param name="collector">Collector that stores the resulting metrics snapshot as records.</param> /// <param name="all">If true, gets metric values even if they are unchanged.</param> public void GetMetrics(IMetricsCollector collector, bool all) { lock (_lock) { var rb = collector.CreateRecord(_recordName) .SetContext(_sourceContext) .AddTag("TaskOrContextName", _contextOrTaskName) .AddTag("EvaluatorId", _evaluatorId) .AddTag("SourceType", "DefaultSource"); var request = new SnapshotRequest(rb, all); foreach (var entry in _observers) { entry.OnNext(request); } foreach (var entry in _tags) { rb.Add(entry.Value); } } }
/// <summary> /// Initializes a new instance of the <see cref="PingedConnection{TClientMessage, TServerMessage, TConnectArguments, TConnectResponse, TRequest, TResponse}"/> class. /// </summary> /// <param name="requestId">The request id for the gRPC method call.</param> /// <param name="runtimeStream">The <see cref="IAsyncStreamReader{TClientMessage}"/> to read messages to the Runtime.</param> /// <param name="clientStream">The <see cref="IServerStreamWriter{TServerMessage}"/> to write messages to the Client.</param> /// <param name="context">The <see cref="ServerCallContext"/> of the method call.</param> /// <param name="messageConverter">The <see cref="MethodConverter"/> to use for decoding the connect arguments and reading the desired ping interval from.</param> /// <param name="keepalive">The keepalive token canceller to use for keeping track of ping timeouts.</param> /// <param name="pingScheduler">The callback scheduler to use for scheduling accurate pings.</param> /// <param name="metrics">The metrics collector to use for metrics about reverse calls.</param> /// <param name="loggerFactory">The logger factory to use to create loggers.</param> public PingedConnection( RequestId requestId, IAsyncStreamReader <TClientMessage> runtimeStream, IAsyncStreamWriter <TServerMessage> clientStream, ServerCallContext context, IConvertReverseCallMessages <TClientMessage, TServerMessage, TConnectArguments, TConnectResponse, TRequest, TResponse> messageConverter, ICancelTokenIfDeadlineIsMissed keepalive, ICallbackScheduler pingScheduler, IMetricsCollector metrics, ILoggerFactory loggerFactory) { _cancellationTokenSource = CancellationTokenSource.CreateLinkedTokenSource(context.CancellationToken, keepalive.Token); _requestId = requestId; _keepalive = keepalive; _pingScheduler = pingScheduler; _wrappedReader = new WrappedAsyncStreamReader <TClientMessage, TServerMessage, TConnectArguments, TConnectResponse, TRequest, TResponse>( requestId, runtimeStream, messageConverter, metrics, loggerFactory.CreateLogger <WrappedAsyncStreamReader <TClientMessage, TServerMessage, TConnectArguments, TConnectResponse, TRequest, TResponse> >(), _cancellationTokenSource.Token); _wrappedWriter = new WrappedAsyncStreamWriter <TClientMessage, TServerMessage, TConnectArguments, TConnectResponse, TRequest, TResponse>( requestId, clientStream, messageConverter, metrics, loggerFactory.CreateLogger <WrappedAsyncStreamWriter <TClientMessage, TServerMessage, TConnectArguments, TConnectResponse, TRequest, TResponse> >(), _cancellationTokenSource.Token); _metrics = metrics; _logger = loggerFactory.CreateLogger <PingedConnection <TClientMessage, TServerMessage, TConnectArguments, TConnectResponse, TRequest, TResponse> >(); WaitForCallContextInFirstMessageThenStartPinging(); _keepAliveExpiredRegistration = keepalive.Token.Register(NotifyKeepaliveTimedOut); }
/// <summary> /// Initializes a new instance of the <see cref="EventHorizon"/> class. /// </summary> /// <param name="id">The <see cref="EventHorizonId"/>.</param> /// <param name="consent">The <see cref="ConsentId"/>.</param> /// <param name="currentPosition">The initial current <see cref="StreamPosition"/> of the event horizon.</param> /// <param name="dispatcher">The reverse call dispatcher.</param> /// <param name="executionContexts">The <see cref="ICreateExecutionContexts"/>.</param> /// <param name="getEventFetchers">The <see cref="Func{TResult}"/> callback for getting <see cref="IEventFetchers"/> in a tenant container.</param> /// <param name="getStreamWaiter">The <see cref="Func{TResult}"/> callback for getting <see cref="IStreamEventWatcher"/> in a tenant container</param> /// <param name="metrics">The <see cref="IMetricsCollector"/>.</param> /// <param name="logger">The <see cref="ILogger"/>.</param> /// <param name="cancellationToken">The cancellation token.</param> public EventHorizon( EventHorizonId id, ConsentId consent, StreamPosition currentPosition, IReverseCallDispatcher <EventHorizonConsumerToProducerMessage, EventHorizonProducerToConsumerMessage, ConsumerSubscriptionRequest, SubscriptionResponse, ConsumerRequest, ConsumerResponse> dispatcher, ICreateExecutionContexts executionContexts, Func <TenantId, IEventFetchers> getEventFetchers, Func <TenantId, IStreamEventWatcher> getStreamWaiter, IMetricsCollector metrics, ILogger logger, CancellationToken cancellationToken) { Consent = consent; _dispatcher = dispatcher; _executionContexts = executionContexts; _getEventFetchers = getEventFetchers; _getStreamWaiter = getStreamWaiter; _metrics = metrics; _logger = logger; Id = id; CurrentPosition = currentPosition; _cancellationTokenSource = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken); }
/// <summary> /// Called when an <see cref="IMetricsCollector"/> is stopping in order to detach /// any event handlers, etc. the source may be attached to. /// </summary> /// <param name="collector"> /// An <see cref="IMetricsCollector"/>. /// </param> public virtual void Detach(IMetricsCollector collector) { }
public MetricsGossipSpec() { _collector = CreateMetricsCollector(); }
public MetricValuesSpec() { _collector = CreateMetricsCollector(); _node1 = new NodeMetrics(new Address("akka.tcp", "sys", "a", 2554), 1, _collector.Sample().Metrics); _node2 = new NodeMetrics(new Address("akka.tcp", "sys", "a", 2555), 1, _collector.Sample().Metrics); }
public EWMASpec() { _collector = CreateMetricsCollector(); }