Esempio n. 1
0
        /// <summary>
        /// Loads the default settings.
        /// </summary>
        public WsapmSettings GetDefaultSettings()
        {
            var newSettings = new WsapmSettings();

            newSettings.MonitoringTimerInterval    = WsapmTools.GetOptimalCheckIntervalInMinutes();
            newSettings.MaxLogFileSize             = WsapmConvert.ConvertKBToByte(100);
            newSettings.NetworkInterfacesToMonitor = new System.Collections.Generic.List <NetworkInterfaceToMonitor>();
            newSettings.HddsToMonitor = new System.Collections.Generic.List <HddToMonitor>();
            newSettings.EnableCheckNetworkResourceAccess = false;
            newSettings.CheckNetworkResourcesType        = NetworkShareAccessType.Files;
            newSettings.CpuLoad                    = 0.0f;
            newSettings.MemoryLoad                 = 0.0f;
            newSettings.UptimeSchedulers           = new System.Collections.Generic.List <UptimeScheduler>();
            newSettings.WakeSchedulers             = new System.Collections.Generic.List <WakeScheduler>();
            newSettings.LogMode                    = LogMode.Normal;
            newSettings.EnableRemoteShutdown       = false;
            newSettings.RemoteShutdownPort         = 9;
            newSettings.RemoteShutdownPasswordHash = string.Empty;
            return(newSettings);
        }
Esempio n. 2
0
        /// <summary>
        /// Checks if the HDD load is over the HDD load value in the settings.
        /// </summary>
        /// <param name="settings"></param>
        /// <returns>True, if the current HDD load is greater than the HDD load value in the settings, otherwise false.</returns>
        public CheckSuspendResult CheckHddLoad(WsapmSettings settings)
        {
            if (settings == null || !settings.EnableHddsToMonitor)
            {
                return(new CheckSuspendResult(false, String.Empty));
            }

            var availableHdds = WsapmTools.GetAvailableLogicalVolumeNames();

            foreach (var hddToMonitor in settings.HddsToMonitor)
            {
                if (hddToMonitor.Drive != WsapmConstants.AllHddsName && !availableHdds.Contains(hddToMonitor.Drive))
                {
                    // HDD not available -> don't check, just write entry in log.
                    WsapmLog.Log.WriteLine(string.Format(Wsapm.Core.Resources.Wsapm_Core.HddLoadCheck_HddNotAvailable, hddToMonitor.Drive), LogMode.Normal);
                    continue;
                }

                bool   checkAllHdds = false;
                string hddName      = hddToMonitor.Drive;

                if (hddToMonitor.Drive == WsapmConstants.AllHddsName)
                {
                    checkAllHdds = true;
                    hddName      = WsapmTools.GetCommonDiaplayNameAllDrives();
                }

                // Check load.
                try
                {
                    if (hddToMonitor.EnableCheckHddLoad && hddToMonitor.HddLoad != 0.0f)
                    {
                        var averageHddLoad = 0.0f;

                        if (checkAllHdds)
                        {
                            averageHddLoad = this.hddLoad.GetAverageHddLoadAllVolumesInBytesPerSecond(); // Byte/s
                        }
                        else
                        {
                            averageHddLoad = this.hddLoad.GetAverageHddLoadInBytesPerSecond(hddToMonitor.Drive); // Byte/s
                        }
                        var result = averageHddLoad > WsapmConvert.ConvertKBToByte(hddToMonitor.HddLoad);        // Settings are saved as KBit/s.

                        if (result)
                        {
                            return(new CheckSuspendResult(true, String.Format(Resources.Wsapm_Core.HddLoadCheck_HddLoadReason, hddName, hddToMonitor.HddLoad, WsapmConvert.ConvertByteToKB(averageHddLoad).ToString("0"))));
                        }
                        else
                        {
                            return(new CheckSuspendResult(false, String.Empty));
                        }
                    }
                }
                catch (Exception ex)
                {
                    // Might happen if the performance counters get broken.
                    WsapmLog.Log.WriteError(ex);
                }
            }

            return(new CheckSuspendResult(false, String.Empty));
        }
Esempio n. 3
0
 /// <summary>
 /// Initializes a new instance of ServiceLog.
 /// </summary>
 private WsapmLog()
     : this(LogMode.Normal, WsapmConvert.ConvertKBToByte(0))
 {
 }
Esempio n. 4
0
 /// <summary>
 /// Initializes a new instance of ServiceLog.
 /// </summary>
 /// <param name="logMode">The LogMode defining the level of detail of the log.</param>
 private WsapmLog(LogMode logMode)
     : this(logMode, WsapmConvert.ConvertKBToByte(0))
 {
 }
Esempio n. 5
0
        /// <summary>
        /// Checks if the network load is over the network load value in the settings.
        /// </summary>
        /// <param name="settings"></param>
        /// <returns>True, if the current network load is greater than the network load value in the settings, otherwise false.</returns>
        public CheckSuspendResult CheckNetworkLoad(WsapmSettings settings)
        {
            if (settings == null || !settings.EnableNetworkInterfacesToMonitor)
            {
                return(new CheckSuspendResult(false, String.Empty));
            }

            var availableNics = WsapmTools.GetAvailableNetworkInterfaces();

            foreach (var networkInterfaceToMonitor in settings.NetworkInterfacesToMonitor)
            {
                if (networkInterfaceToMonitor.NetworkInterface != WsapmConstants.AllNetworkInterfacesName && !availableNics.Contains(networkInterfaceToMonitor.NetworkInterface))
                {
                    // NIC not available -> don't check, just write entry in log.
                    WsapmLog.Log.WriteLine(string.Format(Wsapm.Core.Resources.Wsapm_Core.NetworkLoadCheck_NicNotAvailable, networkInterfaceToMonitor.NetworkInterface), LogMode.Normal);
                    continue;
                }

                bool   checkAllNics = false;
                string nicName      = networkInterfaceToMonitor.NetworkInterface;

                if (networkInterfaceToMonitor.NetworkInterface == WsapmConstants.AllNetworkInterfacesName)
                {
                    checkAllNics = true;
                    nicName      = WsapmTools.GetCommonDiaplayNameAllNetworkInterfaces();
                }

                // Check total network load.
                try
                {
                    if (networkInterfaceToMonitor.EnableCheckNetworkLoadTotal && networkInterfaceToMonitor.NetworkLoadTotal != 0.0f)
                    {
                        var averageNetworkLoad = 0.0f;

                        if (checkAllNics)
                        {
                            averageNetworkLoad = this.networkLoad.GetAverageNetworkLoadTotalAllNicsInBytesPerSecond(); // Byte/s
                        }
                        else
                        {
                            averageNetworkLoad = this.networkLoad.GeAverageNetworkLoadTotalInBytesPerSecond(networkInterfaceToMonitor.NetworkInterface); // Byte/s
                        }
                        var result = averageNetworkLoad > WsapmConvert.ConvertKBitToByte(networkInterfaceToMonitor.NetworkLoadTotal);                    // Settings are saved as KBit/s.

                        if (result)
                        {
                            return(new CheckSuspendResult(true, String.Format(Resources.Wsapm_Core.NetworkLoadCheck_CombinedNetworkLoadReason, nicName, networkInterfaceToMonitor.NetworkLoadTotal, WsapmConvert.ConvertByteToKBit(averageNetworkLoad).ToString("0"))));
                        }
                        else
                        {
                            return(new CheckSuspendResult(false, String.Empty));
                        }
                    }
                }
                catch (Exception ex)
                {
                    // Might happen if the performance counters get broken.
                    WsapmLog.Log.WriteError(ex);
                }

                // Check download network load.
                try
                {
                    if (networkInterfaceToMonitor.EnableCheckNetworkLoadDownload && networkInterfaceToMonitor.NetworkLoadDownload != 0.0f)
                    {
                        var averageNetworkReceived = 0.0f;

                        if (checkAllNics)
                        {
                            averageNetworkReceived = this.networkLoad.GetAverageNetworkLoadDownloaAllNicsInBytesPerSecond(); //Byte/s
                        }
                        else
                        {
                            averageNetworkReceived = this.networkLoad.GetAverageNetworkLoadDownloadInBytesPerSecond(networkInterfaceToMonitor.NetworkInterface); //Byte/s
                        }
                        var result = averageNetworkReceived > WsapmConvert.ConvertKBitToByte(networkInterfaceToMonitor.NetworkLoadDownload);                     // Settings are saved as KBit/s.

                        if (result)
                        {
                            return(new CheckSuspendResult(true, String.Format(Resources.Wsapm_Core.NetworkLoadCheck_DownloadNetworkLoadReason, nicName, networkInterfaceToMonitor.NetworkLoadDownload, WsapmConvert.ConvertByteToKBit(averageNetworkReceived).ToString("0"))));
                        }
                        else
                        {
                            return(new CheckSuspendResult(false, String.Empty));
                        }
                    }
                }
                catch (Exception ex)
                {
                    // Might happen if the performance counters get broken.
                    WsapmLog.Log.WriteError(ex);
                }

                // Check upload network load.
                try
                {
                    if (networkInterfaceToMonitor.EnableCheckNetworkLoadUpload && networkInterfaceToMonitor.NetworkLoadUpload != 0.0f)
                    {
                        var averageNetworkSent = 0.0f;

                        if (checkAllNics)
                        {
                            averageNetworkSent = this.networkLoad.GetAverageNetworkLoadUploadAllNicsInBytesPerSecond(); // Byte/s
                        }
                        else
                        {
                            averageNetworkSent = this.networkLoad.GetAverageNetworkLoadUploadInBytesPerSecond(networkInterfaceToMonitor.NetworkInterface); // Byte/s
                        }
                        var result = averageNetworkSent > WsapmConvert.ConvertKBitToByte(networkInterfaceToMonitor.NetworkLoadUpload);                     // Settings are saved as KBit/s.

                        if (result)
                        {
                            return(new CheckSuspendResult(true, String.Format(Resources.Wsapm_Core.NetworkLoadCheck_UploadNetworkLoadReason, nicName, networkInterfaceToMonitor.NetworkLoadUpload, WsapmConvert.ConvertByteToKBit(averageNetworkSent).ToString("0"))));
                        }
                        else
                        {
                            return(new CheckSuspendResult(false, String.Empty));
                        }
                    }
                }
                catch (Exception ex)
                {
                    // Might happen if the performance counters get broken.
                    WsapmLog.Log.WriteError(ex);
                }
            }

            return(new CheckSuspendResult(false, String.Empty));
        }