//****************************************************************************************************** // SystemPerformanceMonitor.cs - Gbtc // // Copyright © 2021, Grid Protection Alliance. All Rights Reserved. // // Licensed to the Grid Protection Alliance (GPA) under one or more contributor license agreements. See // the NOTICE file distributed with this work for additional information regarding copyright ownership. // The GPA licenses this file to you under the MIT License (MIT), the "License"; you may not use this // file except in compliance with the License. You may obtain a copy of the License at: // // http://opensource.org/licenses/MIT // // Unless agreed to in writing, the subject software distributed under the License is distributed on an // "AS-IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. Refer to the // License for the specific language governing permissions and limitations. // // Code Modification History: // ---------------------------------------------------------------------------------------------------- // 04/29/2021 - J. Ritchie Carroll // Generated original version of source code. // //****************************************************************************************************** namespace GSF.Diagnostics { /// /// Represents a system performance monitor for system level performance statistics, e.g., /// CPU utilization and available memory. /// public class SystemPerformanceMonitor : PerformanceMonitorBase { #region [ Constructors ] /// /// Creates a new . /// /// /// Interval, in milliseconds, at which the /// are to be sampled. /// /// /// It is recommended to use the instance of this class /// instead of creating a new instance where applicable. /// public SystemPerformanceMonitor(double samplingInterval = DefaultSamplingInterval) : base(samplingInterval) { // This counter matches task manager for process utilization: AddCounter("Processor Information", "% Processor Utility", "_Total", "CPU Utilization", "Average %", 1.0F, true, sampleFilter: value => value <= 0.0D); AddCounter("Memory", "Available MBytes", "", "Available Memory", "GB", 1024.0F); } #endregion #region [ Properties ] /// /// Gets the that monitors the processor utilization of the system. /// /// This is added by default. public PerformanceCounter CPUUsage => FindCounter("% Processor Utility"); /// /// Gets the that monitors the remaining available memory of the system in GB. /// /// This is added by default. public PerformanceCounter AvailableMemory => FindCounter("Available MBytes"); #endregion #region [ Static ] // Static Fields private static SystemPerformanceMonitor s_systemPerformanceMonitor; // Static Properties /// /// Gets default reference of . /// public static SystemPerformanceMonitor Default => s_systemPerformanceMonitor ??= new SystemPerformanceMonitor(); #endregion } }