75 lines
2.1 KiB
C#
75 lines
2.1 KiB
C#
// /**
|
|
// * File: PerformanceValue.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.perfdb.storage;
|
|
using Newtonsoft.Json;
|
|
namespace ln.skyscanner.checks
|
|
{
|
|
public class PerformanceValue
|
|
{
|
|
public string[] PerfPath { get; private set; }
|
|
public string PerfName => string.Join("/", PerfPath);
|
|
|
|
public double LastValue { get; set; }
|
|
|
|
public double WarnLower { get; set; } = Double.MinValue;
|
|
public double WarnUpper { get; set; } = Double.MaxValue;
|
|
public double CritLower { get; set; } = Double.MinValue;
|
|
public double CritUpper { get; set; } = Double.MaxValue;
|
|
|
|
public bool IgnoreLimits;
|
|
|
|
private PerformanceValue()
|
|
{
|
|
}
|
|
public PerformanceValue(string[] perfPath,double wLower = Double.MinValue,double wUpper = Double.MaxValue, double cLower = Double.MinValue, double cUpper = Double.MaxValue)
|
|
{
|
|
PerfPath = perfPath;
|
|
LastValue = 0;
|
|
|
|
WarnLower = wLower;
|
|
WarnUpper = wUpper;
|
|
CritLower = cLower;
|
|
CritUpper = cUpper;
|
|
}
|
|
|
|
public void WritePerfValue(double value)
|
|
{
|
|
LastValue = value;
|
|
|
|
PerfFile perfFile = SkyScanner.Instance.Checker.GetPerfFile(PerfPath);
|
|
lock (perfFile)
|
|
{
|
|
perfFile.EnsureOpen();
|
|
perfFile.Write(DateTimeOffset.Now.ToUnixTimeSeconds(), value);
|
|
perfFile.Close();
|
|
}
|
|
}
|
|
|
|
public CheckState CheckState
|
|
{
|
|
get
|
|
{
|
|
if (IgnoreLimits)
|
|
return CheckState.OK;
|
|
|
|
if ((LastValue < CritLower) || (LastValue > CritUpper))
|
|
return CheckState.CRITICAL;
|
|
if ((LastValue < WarnLower) || (LastValue > WarnUpper))
|
|
return CheckState.WARN;
|
|
|
|
return CheckState.OK;
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|