public void Initialize(MetricsContext rootContext, MetricsContext receivedMetricContext)
 {
     this.receivedMetricContext = receivedMetricContext;
     receiveLinkState           = rootContext.Context("ReceivedLinkState");
     sendLinkState = rootContext.Context("SentLinkState");
     linkState     = rootContext.Context("LinkState");
     queueState    = rootContext.Context("QueueState");
 }
Exemplo n.º 2
0
        /// <summary>
        /// Creates a new RemoteHostPool using the specified system name and liveliness checker.
        /// </summary>
        /// <param name="reachabilityChecker">A delegate that checks if a given host is reachable or not. Used for background checks of unreachable hosts.
        /// Should return true if the host is reachable, or false if it is unreachable. It should not throw an exception.</param>
        /// <param name="log">An implementation of <see cref="ILog"/> used for logging.</param>
        public RemoteHostPool(
            DeploymentIdentifier deploymentIdentifier
            , IServiceDiscoverySource discovery
            , ReachabilityChecker reachabilityChecker
            , Func <DiscoveryConfig> getDiscoveryConfig
            , ILog log
            , HealthMonitor healthMonitor
            , MetricsContext metrics
            )
        {
            DiscoverySource      = discovery;
            DeploymentIdentifier = deploymentIdentifier;
            ReachabilityChecker  = reachabilityChecker;
            GetDiscoveryConfig   = getDiscoveryConfig;
            Log = log;
            ReachabilityBroadcaster = new BroadcastBlock <ServiceReachabilityStatus>(null);
            Health = healthMonitor.Get(discovery.Deployment);
            Health.SetHealthData(HealthData);

            ReachableHosts            = new List <RemoteHost>();
            UnreachableHosts          = new List <RemoteHost>();
            EndPointsChangedBlockLink = discovery.EndPointsChanged.LinkTo(new ActionBlock <EndPointsResult>(_ => ReloadEndpoints(_)));
            ReloadEndpoints(discovery.Result);
            Metrics = metrics;
            var metricsContext = Metrics.Context(DiscoverySource.Deployment);

            metricsContext.Gauge("ReachableHosts", () => ReachableHosts.Count, Unit.Custom("EndPoints"));
            metricsContext.Gauge("UnreachableHosts", () => UnreachableHosts.Count, Unit.Custom("EndPoints"));
        }
Exemplo n.º 3
0
        public void MetricsContext_EmptyChildContextIsSameContext()
        {
            var child = context.Context(string.Empty);

            object.ReferenceEquals(context, child).Should().BeTrue();
            child = context.Context(null);
            object.ReferenceEquals(context, child).Should().BeTrue();
        }
Exemplo n.º 4
0
        /// <summary>
        /// Configure global NancyFx Metrics.
        /// Available global metrics are: Request Timer, Active Requests Counter, Error Meter
        /// <code>
        /// protected override void ApplicationStartup(TinyIoCContainer container, IPipelines pipelines)
        /// {
        ///     base.ApplicationStartup(container, pipelines);
        ///
        ///     NancyMetrics.Configure()
        ///         .WithGlobalMetrics(config => config.RegisterAllMetrics(pipelines))
        ///         .WithMetricsEndpoint();
        /// }
        /// </code>
        /// </summary>
        /// <param name="config">Action to configure which global metrics to enable.</param>
        /// <param name="context">Name of the MetricsContext where to register the NancyFx metrics.</param>
        /// <returns>This instance to allow chaining of the configuration.</returns>
        public NancyMetricsConfig WithNancyMetrics(Action <NancyGlobalMetrics> config, string context = "NancyFx")
        {
            if (_isDiabled)
            {
                return(this);
            }

            var globalMetrics = new NancyGlobalMetrics(_metricsContext.Context(context), _nancyPipelines);

            config(globalMetrics);
            return(this);
        }
Exemplo n.º 5
0
        public HapperMetricsConfig WithHapperMetrics(Action <HapperGlobalMetrics> config, string context = "Happer")
        {
            if (_isDiabled)
            {
                return(this);
            }

            var globalMetrics = new HapperGlobalMetrics(_metricsContext.Context(context), _pipelines);

            config(globalMetrics);
            return(this);
        }
Exemplo n.º 6
0
        public void Init()
        {
            _context.Context("CPU").Gauge("Processor Affinity", () => _processorTimePercent.AssignedCoresCount, Unit.Items);
            _context.Context("CPU").Gauge("CPU usage", () => ReadPerfCounter(_processorTimePercent), Unit.Percent);
            _context.Context("CPU").Gauge("CPU total", () => _processorTotalPercent.GetValue() ?? 0, Unit.Percent);
            _context.Context("CPU").Gauge("Thread count", () => { double threads = ReadPerfCounter(_threadCount); return(threads < 0 || threads > 1000000 ? 0 : threads); }, Unit.Items);
            _context.Context("CPU").Gauge("DotNet logical thread count", () => { double threads = ReadPerfCounter(_dotNetThreadCount); return(threads < 0 || threads > 1000000 ? 0 : threads); }, Unit.Items);
            _context.Context("Memory").Gauge("Working set", () => ReadPerfCounter(_workingSet), Unit.Bytes);
            _context.Context("Memory").Gauge("Private", () => ReadPerfCounter(_virtualBytes), Unit.Bytes);
            _context.Context("Memory").Gauge("Virtual", () => ReadPerfCounter(_privateBytes), Unit.Bytes);
            _context.Context("GC").Gauge("Gen-2 collections", () => ReadPerfCounter(_gen2Collections), Unit.Events);
            _context.Context("GC").Gauge("Time in GC", () => ReadPerfCounter(_timeInGc), Unit.Percent);

            _cpuUsageHealthCheck     = new LowSensitivityHealthCheck(CpuUsageHealth, () => _getConfig().MinUnhealthyDuration, _dateTime);
            _threadsCountHealthCheck = new LowSensitivityHealthCheck(ThreadsCountHealth, () => _getConfig().MinUnhealthyDuration, _dateTime);
            _orleansQueueHealthCheck = new LowSensitivityHealthCheck(OrleansRequestQueueHealth, () => _getConfig().MinUnhealthyDuration, _dateTime);

            _healthStatus.RegisterCheck("CPU Usage", _cpuUsageHealthCheck.GetHealthStatus);
            _healthStatus.RegisterCheck("Threads Count", _threadsCountHealthCheck.GetHealthStatus);
            _healthStatus.RegisterCheck("Orleans Queue", _orleansQueueHealthCheck.GetHealthStatus);

            _triggerHealthChecksEvery5Seconds = new Timer(TriggerHealthCheck, null, TimeSpan.FromSeconds(5), TimeSpan.FromSeconds(5));
        }
Exemplo n.º 7
0
        /// <summary>
        /// Configure which Owin metrics to be registered.
        /// </summary>
        /// <param name="config">Action used to configure Owin metrics.</param>
        /// <param name="ignoreRequestPathPatterns">Patterns for paths to ignore.</param>
        /// <param name="owinContext">Name of the metrics context where to register the metrics.</param>
        /// <returns>Chainable configuration object.</returns>
        public OwinMetricsConfig WithRequestMetricsConfig(Action <OwinRequestMetricsConfig> config,
                                                          Regex[] ignoreRequestPathPatterns = null, string owinContext = "Owin")
        {
            if (_isDisabled)
            {
                return(this);
            }

            OwinRequestMetricsConfig requestConfig = new OwinRequestMetricsConfig(_middlewareRegistration, _context.Context(owinContext), ignoreRequestPathPatterns);

            config(requestConfig);
            return(this);
        }
 public static MetricsContext GetWebApplicationContext(this MetricsContext context)
 {
     return(context.Context(WebApplicationRequestsContextName));
 }
 public static MetricsContext GetOAuth2ClientWebRequestsContext(this MetricsContext context)
 {
     return(context.Context(OAuth2ClientWebRequestsContextName));
 }