ln.skyscanner/checks/Hostalive.cs

59 lines
1.5 KiB
C#

// /**
// * 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;
skyChecker.WritePerfValue(this,"replies",node,fSuccess);
if (success > 0)
{
roundTripTime /= success;
skyChecker.WritePerfValue(this, "rta", node, roundTripTime);
}
}
}
}