// /** // * File: Hostalive.cs // * Author: haraldwolff // * // * This file and it's content is copyrighted by the Author and / or copyright holder. // * Any use wihtout proper permission is illegal and may lead to legal actions. // * // * // **/ using System; using ln.types; using ln.skyscanner.entities; using ln.perfdb; using System.Net.NetworkInformation; using ln.logging; using ln.perfdb.storage; namespace ln.skyscanner.checks { public class Hostalive : SkyCheck { Ping Ping { get; } public Hostalive() : base("hostalive") { Ping = new Ping(); } public override bool IsCritical => true; public override bool IsValid(Node node) => node.PrimaryIP != null; public override void Check(SkyChecker skyChecker,ref SkyCheckState checkState,Node node) { long roundTripTime = 0; int success = 0; int n; for (n = 0; n < 4; n++) { PingReply reply = Ping.Send(node.PrimaryIP, 250); if (reply.Status == IPStatus.Success) { success++; roundTripTime += reply.RoundtripTime; } } float fSuccess = (float)success / (float)n; checkState.WritePerformanceValue("replies", fSuccess, 0.8, double.MaxValue, 0.6, double.MaxValue); if (success > 0) { roundTripTime /= success; checkState.WritePerformanceValue("rta", roundTripTime, 0, 40, 0, 80); } checkState.BaseCheckState = CheckState.OK; } } }