示例#1
0
 public void Init()
 {
     Create();
     ConfigCache.ConfigChanged.LinkTo(new ActionBlock <ConfigItemsCollection>(c => Create()));
     InitializeBroadcast();
     healthStatus.RegisterCheck(ObjectType.Name, HealthCheck);
 }
示例#2
0
        public NewServiceDiscovery(string serviceName,
                                   ReachabilityCheck reachabilityCheck,
                                   IEnvironment environment,
                                   ISourceBlock <DiscoveryConfig> configListener,
                                   Func <DiscoveryConfig> discoveryConfigFactory,
                                   ILog log,
                                   IDiscovery discovery,
                                   Func <string, AggregatingHealthStatus> getAggregatingHealthStatus)
        {
            Log          = log;
            _discovery   = discovery;
            _serviceName = serviceName;

            _originatingEnvironmentDeployment = new DeploymentIdentifier(serviceName, environment.DeploymentEnvironment, environment);
            _masterDeployment = new DeploymentIdentifier(serviceName, MASTER_ENVIRONMENT, environment);

            _reachabilityCheck = reachabilityCheck;
            GetConfig          = discoveryConfigFactory;

            _initTask        = Task.Run(() => ReloadRemoteHost(discoveryConfigFactory()));
            _configBlockLink = configListener.LinkTo(new ActionBlock <DiscoveryConfig>(ReloadRemoteHost));

            AggregatingHealthStatus = getAggregatingHealthStatus("Discovery");
            _healthCheck            = AggregatingHealthStatus.RegisterCheck(_serviceName, () => new ValueTask <HealthCheckResult>(_getHealthStatus()));
            _getHealthStatus        = () => HealthCheckResult.Healthy("Initializing. Service was not discovered yet");
        }
示例#3
0
        public ConsulClient(string serviceName, Func <ConsulConfig> getConfig,
                            ISourceBlock <ConsulConfig> configChanged, IEnvironment environment,
                            ILog log, IDateTime dateTime, Func <string, AggregatingHealthStatus> getAggregatedHealthStatus)
        {
            _serviceName       = serviceName;
            _serviceNameOrigin = serviceName;

            GetConfig = getConfig;
            _dateTime = dateTime;
            Log       = log;
            Zone      = environment.Zone;

            _waitForConfigChange = new TaskCompletionSource <bool>();
            configChanged.LinkTo(new ActionBlock <ConsulConfig>(ConfigChanged));

            var address = environment.ConsulAddress ?? $"{CurrentApplicationInfo.HostName}:8500";

            ConsulAddress = new Uri($"http://{address}");
            _httpClient   = new HttpClient {
                BaseAddress = ConsulAddress, Timeout = TimeSpan.FromMinutes(100)
            };                                                                                                 // timeout will be implemented using cancellationToken when calling httpClient
            _aggregatedHealthStatus = getAggregatedHealthStatus("ConsulClient");

            _resultChanged      = new BufferBlock <EndPointsResult>();
            _initializedVersion = new TaskCompletionSource <bool>();
            ShutdownToken       = new CancellationTokenSource();
            _healthCheck        = _aggregatedHealthStatus.RegisterCheck(_serviceNameOrigin, () => _getHealthStatus());
        }
示例#4
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));
        }
示例#5
0
        public ConfigObjectCreator(Type objectType, ConfigCache configCache, UsageTracking usageTracking, ILog log, Func <string, AggregatingHealthStatus> getAggregatedHealthCheck)
        {
            UsageTracking = usageTracking;
            Log           = log;
            ObjectType    = objectType;
            ConfigCache   = configCache;
            ConfigPath    = GetConfigPath();
            Validator     = new DataAnnotationsValidator.DataAnnotationsValidator();

            Create();
            ConfigCache.ConfigChanged.LinkTo(new ActionBlock <ConfigItemsCollection>(c => Create()));
            InitializeBroadcast();
            healthStatus = getAggregatedHealthCheck("Configuration");
            healthStatus.RegisterCheck(ObjectType.Name, HealthCheck);
        }