예제 #1
0
        public IActionResult DISK(string name = null)
        {
            var results = _pm.GetDriveInfo();

            if (results == null)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, "No Drive Info"));
            }

            name = name?.ToLower().ReplaceMany((" ", ""), (":", ""), ("/", ""), ("\\", ""));

            if (name == null)
            {
                return(StatusCode(StatusCodes.Status200OK, results));
            }

            var drive = results.FirstOrDefault(x => x.name == name);

            if (drive == null)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, $"Drive '{name}' was not found"));
            }

            return(StatusCode(StatusCodes.Status200OK, drive));
        }
        public IActionResult health()
        {
            if (_cfg.diskHealthChecks.IsNullOrEmpty())
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, "Disk Health Checks configuraiton is not defined."));
            }

            var drives    = new List <DiskInfo>();
            var driveInfo = _pm.GetDriveInfo();

            foreach (var di in driveInfo)
            {
                if (_cfg.diskHealthChecks.Any(x => di.NameEquals(x.Key)))
                {
                    drives.Add(di);
                }
            }

            var checks      = _cfg.diskHealthChecks;
            var driveStatus = driveInfo.Where(x => checks.Any(y => x.NameEquals(y.Key)));

            if (driveStatus.IsNullOrEmpty())
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, "No Drive Info"));
            }


            var errorResponse = "";

            foreach (var ds in driveStatus)
            {
                var check = _cfg.diskHealthChecks.First(x => ds.NameEquals(x.Key)).Value;
                var used  = 100 - ds.free;

                if (used > check)
                {
                    errorResponse += $"Capacity of {ds.name} exceeded {check}% ({used}%).\n\r";
                }
            }

            if (!errorResponse.IsNullOrEmpty())
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, errorResponse));
            }

            return(StatusCode(StatusCodes.Status200OK, "healthy"));
        }
예제 #3
0
        public IActionResult GEth()
        {
            var lastSync  = _bs.GetPrivateSyncing()?.TryGetHighestBlock() ?? -1;
            var lastBlock = _bs.GetLastBlockNr(apiOnly: true)?.blockNumber ?? -1;

            lastBlock = Math.Max(lastBlock, lastSync);

            var ourSync  = _bs.GetPrivateSyncing()?.TryGetCurrentBlock() ?? -1;
            var ourBlock = _bs.GetPrivateBlockNr()?.blockNumber ?? -1;

            ourBlock = Math.Max(ourBlock, ourSync);

            var blockTime = _bs.GetAverageBlockTime();
            var syncSpeed = _bs.GetAverageSyncSpeed();

            float syncState = 0;

            if (lastBlock > 0 && ourBlock > 0)
            {
                syncState = 100 - (((float)(lastBlock - ourBlock) / lastBlock) * 100);
            }

            var isHealthy = true;

            var index = _prm.TimeFrameIndexes().FindIndex(x => x == _cfg.healthCheckTimeFrame);

            if (index < 0)
            {
                index = 0;
            }

            var cpuIntensity = _prm.GetMedianCpuResults()[index];

            if (cpuIntensity <= 0)
            {
                cpuIntensity = _prm.GetMedianCpuResults().FirstOrDefault(x => x > 0);
            }

            var ramFree = _prm.GetMedianRamResults()[index];

            if (ramFree <= 0)
            {
                ramFree = _prm.GetMedianRamResults().FirstOrDefault(x => x > 0);
            }

            var driveInfo = _prm.GetDriveInfo()?.FirstOrDefault(x => x.name == _cfg.healthCheckDiskName);
            var diskSpace = (100 - (driveInfo?.availableFreeSpace ?? 0));

            if (lastBlock <= 0 || ourBlock <= 0)
            {
                isHealthy = false;
            }

            if (lastBlock - ourBlock > _cfg.healthCheckBlockDelay)
            {
                isHealthy = false;
            }

            if (cpuIntensity > _cfg.healthCheckCPU)
            {
                isHealthy = false;
            }

            if (diskSpace > _cfg.healthCheckDiskSpace)
            {
                isHealthy = false;
            }

            if (ramFree < _cfg.healthCheckRAM)
            {
                isHealthy = false;
            }

            var hc = new HealthCheck()
            {
                isHealthy    = isHealthy,
                lastBlock    = lastBlock,
                ourBlock     = ourBlock,
                cpuUsed      = cpuIntensity,
                cpuMax       = _cfg.healthCheckCPU,
                ramFree      = ramFree,
                ramMin       = _cfg.healthCheckRAM,
                diskUsed     = diskSpace,
                diskMax      = _cfg.healthCheckDiskSpace,
                blockTimeAvg = blockTime,
                syncState    = syncState,
                syncSpeedAvg = syncSpeed
            };

            if (!isHealthy)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, hc));
            }

            return(StatusCode(StatusCodes.Status200OK, hc));
        }