コード例 #1
0
        /// <inheritdoc/>
        public override async Task ObserveAsync(CancellationToken token)
        {
            if (token.IsCancellationRequested)
            {
                return;
            }

            this.Initialize();

            this.Token = token;

            try
            {
                this.perfCounters = new WindowsPerfCounters();
                await this.GetSystemCpuMemoryValuesAsync(token).ConfigureAwait(true);

                await this.ReportAsync(token).ConfigureAwait(true);

                this.LastRunDateTime = DateTime.Now;
            }
            finally
            {
                // Clean up...
                this.perfCounters?.Dispose();
                this.perfCounters = null;
            }
        }
コード例 #2
0
        /// <inheritdoc/>
        public override async Task ObserveAsync(CancellationToken token)
        {
            // If set, this observer will only run during the supplied interval.
            // See Settings.xml, CertificateObserverConfiguration section, RunInterval parameter for an example...
            if (this.RunInterval > TimeSpan.MinValue &&
                DateTime.Now.Subtract(this.LastRunDateTime) < this.RunInterval)
            {
                return;
            }

            if (token.IsCancellationRequested)
            {
                return;
            }

            this.Initialize();

            this.Token = token;

            try
            {
                this.perfCounters = new WindowsPerfCounters();
                await this.GetSystemCpuMemoryValuesAsync(token).ConfigureAwait(true);

                await this.ReportAsync(token).ConfigureAwait(true);

                this.LastRunDateTime = DateTime.Now;
            }
            finally
            {
                // Clean up...
                this.perfCounters?.Dispose();
                this.perfCounters = null;
            }
        }
コード例 #3
0
        protected override void Dispose(bool disposing)
        {
            if (this.disposed)
            {
                return;
            }

            if (disposing)
            {
                if (this.perfCounters != null)
                {
                    this.perfCounters.Dispose();
                    this.perfCounters = null;
                }

                if (this.diskUsage != null)
                {
                    this.diskUsage.Dispose();
                    this.diskUsage = null;
                }

                // Data lists.
                this.processWatchList?.Clear();
                this.allCpuData?.Clear();
                this.allMemData?.Clear();
                this.evtRecordList?.Clear();

                this.disposed = true;
            }
        }
コード例 #4
0
        /// <inheritdoc/>
        public override async Task ObserveAsync(CancellationToken token)
        {
            // If set, this observer will only run during the supplied interval.
            // See Settings.xml, CertificateObserverConfiguration section, RunInterval parameter for an example.
            if (RunInterval > TimeSpan.MinValue &&
                DateTime.Now.Subtract(LastRunDateTime) < RunInterval)
            {
                return;
            }

            bool initialized = Initialize();

            Token = token;

            if (!initialized)
            {
                HealthReporter.ReportFabricObserverServiceHealth(
                    FabricServiceContext.ServiceName.OriginalString,
                    ObserverName,
                    HealthState.Warning,
                    "This observer was unable to initialize correctly due to missing configuration info.");

                return;
            }

            try
            {
                perfCounters = new WindowsPerfCounters();
                diskUsage    = new DiskUsage();

                foreach (var app in targetList)
                {
                    Token.ThrowIfCancellationRequested();

                    if (string.IsNullOrWhiteSpace(app.Target) &&
                        string.IsNullOrWhiteSpace(app.TargetType))
                    {
                        continue;
                    }

                    await MonitorAppAsync(app).ConfigureAwait(true);
                }

                await ReportAsync(token).ConfigureAwait(true);

                LastRunDateTime = DateTime.Now;
            }
            finally
            {
                // Clean up.
                diskUsage?.Dispose();
                diskUsage = null;
                perfCounters?.Dispose();
                perfCounters = null;
            }
        }
コード例 #5
0
        protected override void Dispose(bool disposing)
        {
            if (this.disposed)
            {
                return;
            }

            if (disposing && this.perfCounters != null)
            {
                this.perfCounters.Dispose();
                this.perfCounters = null;
            }

            this.disposed = true;
        }
コード例 #6
0
        /// <inheritdoc/>
        public override async Task ObserveAsync(CancellationToken token)
        {
            bool initialized = this.Initialize();

            this.Token = token;

            if (!initialized || token.IsCancellationRequested)
            {
                this.Token.ThrowIfCancellationRequested();

                this.HealthReporter.ReportFabricObserverServiceHealth(
                    this.FabricServiceContext.ServiceName.OriginalString,
                    this.ObserverName,
                    HealthState.Warning,
                    "This observer was unable to initialize correctly due to missing configuration info...");

                return;
            }

            try
            {
                this.perfCounters = new WindowsPerfCounters();
                this.diskUsage    = new DiskUsage();

                foreach (var app in this.targetList)
                {
                    this.Token.ThrowIfCancellationRequested();

                    await this.MonitorAppAsync(app).ConfigureAwait(true);
                }

                await this.ReportAsync(token).ConfigureAwait(true);

                this.LastRunDateTime = DateTime.Now;
            }
            finally
            {
                // Clean up...
                this.diskUsage?.Dispose();
                this.diskUsage = null;
                this.perfCounters?.Dispose();
                this.perfCounters = null;
            }
        }
コード例 #7
0
        /// <inheritdoc/>
        public override async Task ObserveAsync(CancellationToken token)
        {
            // If set, this observer will only run during the supplied interval.
            // See Settings.xml, CertificateObserverConfiguration section, RunInterval parameter for an example...
            if (this.RunInterval > TimeSpan.MinValue &&
                DateTime.Now.Subtract(this.LastRunDateTime) < this.RunInterval)
            {
                return;
            }

            this.Token = token;

            if (this.Token.IsCancellationRequested)
            {
                return;
            }

            this.Initialize();

            if (this.FabricClientInstance.QueryManager.GetNodeListAsync().GetAwaiter().GetResult()?.Count > 3 &&
                await this.CheckClusterHealthStateAsync(
                    this.unhealthyNodesWarnThreshold,
                    this.unhealthyNodesErrorThreshold).ConfigureAwait(true) == HealthState.Error)
            {
                return;
            }

            this.perfCounters = new WindowsPerfCounters();
            this.diskUsage    = new DiskUsage();

            this.Token.ThrowIfCancellationRequested();

            try
            {
                foreach (var proc in this.processWatchList)
                {
                    this.Token.ThrowIfCancellationRequested();

                    this.GetProcessInfo(proc);
                }
            }
            catch (Exception e)
            {
                if (!(e is OperationCanceledException))
                {
                    this.WriteToLogWithLevel(
                        this.ObserverName,
                        "Unhandled exception in ObserveAsync. Failed to observe CPU and Memory usage of " + string.Join(",", this.processWatchList) + ": " + e.ToString(),
                        LogLevel.Error);
                }

                throw;
            }

            try
            {
                if (this.monitorWinEventLog)
                {
                    this.ReadServiceFabricWindowsEventLog();
                }

                // Set TTL...
                this.stopWatch.Stop();
                this.runtime = this.stopWatch.Elapsed;
                this.stopWatch.Reset();
                await this.ReportAsync(token).ConfigureAwait(true);

                // No need to keep these objects in memory aross healthy iterations...
                if (!this.HasActiveFabricErrorOrWarning)
                {
                    // Clear out/null list objects...
                    this.allAppDiskReadsData.Clear();
                    this.allAppDiskReadsData = null;

                    this.allAppDiskWritesData.Clear();
                    this.allAppDiskWritesData = null;

                    this.allCpuData.Clear();
                    this.allCpuData = null;

                    this.allMemData.Clear();
                    this.allMemData = null;
                }

                this.LastRunDateTime = DateTime.Now;
            }
            finally
            {
                this.diskUsage?.Dispose();
                this.diskUsage = null;
                this.perfCounters?.Dispose();
                this.perfCounters = null;
            }
        }
コード例 #8
0
        /// <inheritdoc/>
        public override async Task ObserveAsync(CancellationToken token)
        {
            // If set, this observer will only run during the supplied interval.
            // See Settings.xml, CertificateObserverConfiguration section, RunInterval parameter for an example.
            if (this.RunInterval > TimeSpan.MinValue &&
                DateTime.Now.Subtract(this.LastRunDateTime) < this.RunInterval)
            {
                return;
            }

            this.stopwatch.Start();
            bool initialized = this.Initialize();

            this.Token = token;

            if (!initialized)
            {
                this.HealthReporter.ReportFabricObserverServiceHealth(
                    this.FabricServiceContext.ServiceName.OriginalString,
                    this.ObserverName,
                    HealthState.Warning,
                    "This observer was unable to initialize correctly due to missing configuration info.");

                return;
            }

            try
            {
                this.perfCounters = new WindowsPerfCounters();
                this.diskUsage    = new DiskUsage();

                foreach (var app in this.targetList)
                {
                    this.Token.ThrowIfCancellationRequested();

                    if (string.IsNullOrWhiteSpace(app.TargetApp) &&
                        string.IsNullOrWhiteSpace(app.TargetAppType))
                    {
                        continue;
                    }

                    await this.MonitorAppAsync(app).ConfigureAwait(true);
                }

                // The time it took to get to ReportAsync.
                // For use in computing actual HealthReport TTL.
                this.stopwatch.Stop();
                this.RunDuration = this.stopwatch.Elapsed;
                this.stopwatch.Reset();

                await this.ReportAsync(token).ConfigureAwait(true);

                this.LastRunDateTime = DateTime.Now;
            }
            finally
            {
                // Clean up.
                this.diskUsage?.Dispose();
                this.diskUsage = null;
                this.perfCounters?.Dispose();
                this.perfCounters = null;
            }
        }