77 lines
1.9 KiB
C#
77 lines
1.9 KiB
C#
|
// /**
|
|||
|
// * File: Service.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.logging;
|
|||
|
using System.Linq.Expressions;
|
|||
|
using ln.perfdb;
|
|||
|
namespace ln.skyscanner
|
|||
|
{
|
|||
|
public abstract class Check
|
|||
|
{
|
|||
|
public readonly String CheckID;
|
|||
|
|
|||
|
public DateTime LastCheck;
|
|||
|
public DateTime NextCheck;
|
|||
|
public TimeSpan CheckInterval;
|
|||
|
|
|||
|
public long LastCheckTime;
|
|||
|
|
|||
|
public String Name;
|
|||
|
|
|||
|
public Check()
|
|||
|
{
|
|||
|
CheckInterval = TimeSpan.FromSeconds(60);
|
|||
|
}
|
|||
|
|
|||
|
public Check(String checkID)
|
|||
|
{
|
|||
|
CheckID = checkID;
|
|||
|
CheckInterval = TimeSpan.FromSeconds(60);
|
|||
|
}
|
|||
|
|
|||
|
public string GetPerfName(string perfName)
|
|||
|
{
|
|||
|
return string.Format("{0}_{1}",CheckID,perfName);
|
|||
|
}
|
|||
|
|
|||
|
public void Mark()
|
|||
|
{
|
|||
|
NextCheck += CheckInterval;
|
|||
|
if (NextCheck < DateTime.Now)
|
|||
|
NextCheck = DateTime.Now + CheckInterval;
|
|||
|
}
|
|||
|
|
|||
|
public void Run(IPerfFileProvider perfProvider)
|
|||
|
{
|
|||
|
long tStart = DateTimeOffset.Now.ToUnixTimeMilliseconds();
|
|||
|
|
|||
|
try
|
|||
|
{
|
|||
|
CheckImplementation(perfProvider);
|
|||
|
|
|||
|
LastCheck = DateTime.Now;
|
|||
|
} catch (Exception e)
|
|||
|
{
|
|||
|
Logging.Log(LogLevel.WARNING, "Check {0} caught exception: {1}", CheckID, e);
|
|||
|
Logging.Log(e);
|
|||
|
}
|
|||
|
|
|||
|
LastCheckTime = DateTimeOffset.Now.ToUnixTimeMilliseconds() - tStart;
|
|||
|
}
|
|||
|
|
|||
|
public abstract void CheckImplementation(IPerfFileProvider perfProvider);
|
|||
|
|
|||
|
public override int GetHashCode()
|
|||
|
{
|
|||
|
return CheckID.GetHashCode();
|
|||
|
}
|
|||
|
}
|
|||
|
}
|