Ejemplo n.º 1
0
        public IActionResult PrivateHeight()
        {
            var bnr = _bsm.GetPrivateBlockNr().TryGetBlockNumber();

            if (bnr <= 0)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError));
            }

            return(StatusCode(StatusCodes.Status200OK, bnr));
        }
Ejemplo n.º 2
0
        protected override async Task Process()
        {
            var bn    = _bsm.GetPrivateBlockNr();
            var delay = 100;

            if (bn != null && (DateTime.UtcNow - bn.TimeStamp).TotalSeconds < _cfg.privateRequestDelay)
            {
                var timeUntilNextExecution = (_cfg.privateRequestDelay * 1000) - (DateTime.UtcNow - bn.TimeStamp).TotalMilliseconds;
                if (timeUntilNextExecution > delay)
                {
                    delay = (int)timeUntilNextExecution;
                }
            }

            await Task.Delay(delay);

            await _bsm.TryUpdatePrivateSyncing();
        }
Ejemplo n.º 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));
        }