// /** // * 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.check { public class Hostalive : Check { public static String CalcCheckName(Node host) { return String.Format("hostalive-{0}", host.PrimaryIP.ToString()); } public Node Host; public Hostalive(Node node) :base(CalcCheckName(node)) { Host = node; } public override void CheckImplementation(IPerfFileProvider perfProvider) { Ping ping = new Ping(); long roundTripTime = 0; int success = 0; int n; for (n = 0; n < 4; n++) { PingReply reply = ping.Send(Host.PrimaryIP, 250); if (reply.Status == IPStatus.Success) { success++; roundTripTime += reply.RoundtripTime; } } float fSuccess = (float)success / (float)n; PerfFile pfSuccess = perfProvider.GetPerfFile(GetPerfName("LOSS")); pfSuccess.Write(new PerfValue(fSuccess)); if (success > 0) { roundTripTime /= success; Logging.Log(LogLevel.INFO, "HOSTALIVE: IP {0} reachable ({1}/10) {2}ms", Host.PrimaryIP, success, roundTripTime); PerfFile pfRoundTrip = perfProvider.GetPerfFile(GetPerfName("RTA")); pfRoundTrip.Write(new PerfValue(roundTripTime)); } else { Logging.Log(LogLevel.INFO, "HOSTALIVE: IP {0} unreachable", Host.PrimaryIP); } } } }