Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(kener): supports custom threshold for calculations of day uptime #77

Merged
merged 1 commit into from
Apr 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,9 @@ To set the base path of your kener instance you can set the `KENER_BASE_PATH` en

It should be present during both build and run time. If you are using docker you will have to do your own build and set this env variable during `docker build`

Please also adjust files in static folder by prefixing them with the base path. For example if you set `KENER_BASE_PATH=/status` then the logo should be `/status/logo.png`


## Custom Scripts
You can include any script in the `app.html` file like google analytics etc

Expand Down Expand Up @@ -424,6 +427,9 @@ Sample
| defaultStatus | Optional | If no API is given this will be the default status. can be UP/DOWN/DEGRADED |
| hidden | Optional | If set to `true` will not show the monitor in the UI |
| category | Optional | Use this to group your monitors. Make sure you have defined category in `site.yaml` and use the `name` attribute here |
| dayDegradedMinimumCount | Optional | Default is 1. It means minimum this number of count for the day to be classified as DEGRADED(Yellow Bar) in 90 day view. Has to be `number` greater than 0 |
| dayDownMinimumCount | Optional | Default is 1. It means minimum this number of count for the day to be classified as DOWN(Red Bar) in 90 day view. Has to be `number` greater than 0 |
| includeDegradedInDowntime | Optional | By deafault uptime percentage is calculated as (UP+DEGRADED/UP+DEGRADED+DOWN). Setting it as `true` will change the calculation to (UP/UP+DEGRADED+DOWN) |

## cron

Expand Down
39 changes: 31 additions & 8 deletions scripts/ninety.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,13 @@ function getDayMessage(type, numOfMinute){
}
const NO_DATA = "No Data";

function getDayData(day0, startTime, endTime) {
function getDayData(
day0,
startTime,
endTime,
dayDownMinimumCount,
dayDegradedMinimumCount
) {
let dayData = {
UP: 0,
DEGRADED: 0,
Expand Down Expand Up @@ -41,15 +47,15 @@ function getDayData(day0, startTime, endTime) {
let cssClass = StatusObj.UP;
let message = "Status OK";

if (dayData.DEGRADED > 0) {
cssClass = StatusObj.DEGRADED;
if (dayData.DEGRADED >= dayDegradedMinimumCount) {
cssClass = StatusObj.DEGRADED;
message = getDayMessage("DEGRADED", dayData.DEGRADED);
}
if (dayData.DOWN > 0) {
if (dayData.DOWN >= dayDownMinimumCount) {
cssClass = StatusObj.DOWN;
message = getDayMessage("DOWN", dayData.DOWN);
}
if (dayData.DEGRADED + dayData.DOWN + dayData.UP > 0) {
if (dayData.DEGRADED + dayData.DOWN + dayData.UP >= Math.min(dayDownMinimumCount, dayDegradedMinimumCount)) {
dayData.message = message;
dayData.cssClass = cssClass;
}
Expand All @@ -68,6 +74,7 @@ const Ninety = async (monitor) => {
let completeDown = 0;
let completeDegraded = 0;


const secondsInDay = 24 * 60 * 60;
const now = GetMinuteStartNowTimestampUTC();
const midnight = BeginningOfDay({ timeZone: "GMT" });
Expand Down Expand Up @@ -107,7 +114,13 @@ const Ninety = async (monitor) => {
}

for (let i = midnight90DaysAgo; i < midnightTomorrow; i += secondsInDay) {
_90Day[i] = getDayData(day0, i, i + secondsInDay - 1);
_90Day[i] = getDayData(
day0,
i,
i + secondsInDay - 1,
monitor.dayDownMinimumCount,
monitor.dayDegradedMinimumCount
);
}

for (const key in _90Day) {
Expand All @@ -117,12 +130,22 @@ const Ninety = async (monitor) => {
delete _90Day[key].DOWN;
if (element.message == NO_DATA) continue;
}
uptime0Day = ParseUptime(dailyUps + dailyDegraded, dailyUps + dailyDown + dailyDegraded);

let uptime0DayNumerator = dailyUps + dailyDegraded;
let uptime0DayDenominator = dailyUps + dailyDown + dailyDegraded;
let uptime90DayNumerator = completeUps + completeDegraded;
let uptime90DayDenominator = completeUps + completeDown + completeDegraded;

if(monitor.includeDegradedInDowntime === true) {
uptime0DayNumerator = dailyUps;
uptime90DayNumerator = completeUps;
}
uptime0Day = ParseUptime(uptime0DayNumerator, uptime0DayDenominator);

const dataToWrite = {
_90Day: _90Day,
uptime0Day,
uptime90Day: ParseUptime(completeUps + completeDegraded, completeUps + completeDegraded + completeDown),
uptime90Day: ParseUptime(uptime90DayNumerator, uptime90DayDenominator),
dailyUps,
dailyDown,
dailyDegraded,
Expand Down
20 changes: 20 additions & 0 deletions scripts/startup.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,24 @@ const Startup = async () => {
process.exit(1);
}

if(monitor.dayDegradedMinimumCount && (isNaN(monitor.dayDegradedMinimumCount) || monitor.dayDegradedMinimumCount < 1)){
console.log("dayDegradedMinimumCount is not a number or it is less than 1");
process.exit(1);
} else if(monitor.dayDegradedMinimumCount === undefined) {
monitors[i].dayDegradedMinimumCount = 1;
}

if(monitor.dayDownMinimumCount && (isNaN(monitor.dayDownMinimumCount) || monitor.dayDownMinimumCount < 1)){
console.log("dayDownMinimumCount is not a number or it is less than 1");
process.exit(1);
} else if(monitor.dayDownMinimumCount === undefined) {
monitors[i].dayDownMinimumCount = 1;
}

if (monitor.includeDegradedInDowntime === undefined || monitor.includeDegradedInDowntime !== true) {
monitors[i].includeDegradedInDowntime = false;
}

if(hasAPI) {
let url = monitor.api.url;
let method = monitor.api.method;
Expand Down Expand Up @@ -184,6 +202,8 @@ const Startup = async () => {
});
}
}


}
if (site.github === undefined || site.github.owner === undefined || site.github.repo === undefined) {
console.log("github owner and repo are required");
Expand Down