Esempio n. 1
0
        private static void KillPlex()
        {
            string processes = string.Empty;

            ProcessCpuUsages.Get().ForEach(d =>
                                           processes += $"\n{d.Value:00.00}% - {d.Key}"
                                           );
            Communicate.SendNotification($"CPU Usage is high\n\n{processes}");

            foreach (Process process in Process.GetProcessesByName("PlexScriptHost"))
            {
                process.Kill();
            }
            foreach (Process process in Process.GetProcessesByName("python"))
            {
                process.Kill();
            }
        }
Esempio n. 2
0
        private void Display()
        {
            _count = (_count < 3) ? _count + 1 : 0;

            LblHeading.Text = Running[_count];

            _cpuUsage = CpuCounter.NextValue();

            if (_count != 3)
            {
                return;
            }

            #region Battery
            if (SystemInformation.PowerStatus.PowerLineStatus == PowerLineStatus.Offline) //On Battery
            {
                if ((_isBatteryPower == false) && (_battNotify))
                {
                    Communicate.SendNotification(_isBatteryPower);
                    _isBatteryPower = true;
                }
                LblBattey.Text = @"On Battery";
            }
            else // Plugged In
            {
                if (_isBatteryPower && _battNotify)
                {
                    Communicate.SendNotification(_isBatteryPower);
                    _isBatteryPower = false;
                }
                LblBattey.Text = @"On Charge";
            }
            #endregion Battery

            #region cpuAverage
            if (_cpuUsage > 75)
            {
                if (_cpuNotify)
                {
                    _cpuOverLimitCount++;
                }
            }
            else if (_cpuUsage < 20)
            {
                _cpuOverLimitCount = 0;
            }

            if (_cpuOverLimitCount > 9)
            {
                if (_cpuNotify)
                {
                    KillPlex();
                    _cpuOverLimitCount = 0;
                }
            }

            LblHighCPU.Text = $@"Count: {_cpuOverLimitCount}";
            LblCPU.Text     = $@"CPU: {CpuUsageDisplay(_cpuUsage)} %";
            #endregion

            #region Network
            if (_networkNotify)
            {
                PingHost(IpAddress, delegate(PingResult ping)
                {
                    if (ping.Success)
                    {
                        _pingCount       = 0;
                        _pingIsAlive     = true;
                        _oldResponseTime = PingTimeDisplay(ping.RoundtripTime);
                        LblPing.Text     = _oldResponseTime;
                    }
                    else
                    {
                        _pingCount++;
                    }

                    if (_pingCount <= 9)
                    {
                        return;
                    }
                    if (!_pingIsAlive)
                    {
                        return;
                    }

                    _pingIsAlive = false;
                    Communicate.SendNotification(IpAddress, _pingCount, _oldResponseTime);
                });
            }

            LblPingCount.Text = $@"Count: {_pingCount}";
            #endregion
        }