diff --git a/db/knex_migrations/2026-01-28-0000-add-numeric-to-stat-tables.js b/db/knex_migrations/2026-01-28-0000-add-numeric-to-stat-tables.js index 5d743d983..c676fb8ca 100644 --- a/db/knex_migrations/2026-01-28-0000-add-numeric-to-stat-tables.js +++ b/db/knex_migrations/2026-01-28-0000-add-numeric-to-stat-tables.js @@ -1,55 +1,19 @@ exports.up = function (knex) { return knex.schema .alterTable("stat_daily", function (table) { - table - .float("numeric_value") - .nullable() - .defaultTo(null) - .comment("Average numeric value during this period"); - table - .float("numeric_min") - .nullable() - .defaultTo(null) - .comment("Minimum numeric value during this period"); - table - .float("numeric_max") - .nullable() - .defaultTo(null) - .comment("Maximum numeric value during this period"); + table.float("numeric_value").nullable().defaultTo(null).comment("Average numeric value during this period"); + table.float("numeric_min").nullable().defaultTo(null).comment("Minimum numeric value during this period"); + table.float("numeric_max").nullable().defaultTo(null).comment("Maximum numeric value during this period"); }) .alterTable("stat_hourly", function (table) { - table - .float("numeric_value") - .nullable() - .defaultTo(null) - .comment("Average numeric value during this period"); - table - .float("numeric_min") - .nullable() - .defaultTo(null) - .comment("Minimum numeric value during this period"); - table - .float("numeric_max") - .nullable() - .defaultTo(null) - .comment("Maximum numeric value during this period"); + table.float("numeric_value").nullable().defaultTo(null).comment("Average numeric value during this period"); + table.float("numeric_min").nullable().defaultTo(null).comment("Minimum numeric value during this period"); + table.float("numeric_max").nullable().defaultTo(null).comment("Maximum numeric value during this period"); }) .alterTable("stat_minutely", function (table) { - table - .float("numeric_value") - .nullable() - .defaultTo(null) - .comment("Average numeric value during this period"); - table - .float("numeric_min") - .nullable() - .defaultTo(null) - .comment("Minimum numeric value during this period"); - table - .float("numeric_max") - .nullable() - .defaultTo(null) - .comment("Maximum numeric value during this period"); + table.float("numeric_value").nullable().defaultTo(null).comment("Average numeric value during this period"); + table.float("numeric_min").nullable().defaultTo(null).comment("Minimum numeric value during this period"); + table.float("numeric_max").nullable().defaultTo(null).comment("Maximum numeric value during this period"); }); }; @@ -71,4 +35,3 @@ exports.down = function (knex) { table.dropColumn("numeric_max"); }); }; - diff --git a/server/jobs/clear-old-data.js b/server/jobs/clear-old-data.js index 4d183fdb2..5889256a2 100644 --- a/server/jobs/clear-old-data.js +++ b/server/jobs/clear-old-data.js @@ -51,7 +51,9 @@ const clearOldData = async () => { // Clean up old monitor_numeric_history data (now using aggregation, but keep for short transition) // Only keep last 7 days of raw data for migration purposes, then delete older data const numericHistoryCutoff = dayjs().subtract(7, "day").utc(); - await R.exec("DELETE FROM monitor_numeric_history WHERE time < ?", [R.isoDateTimeMillis(numericHistoryCutoff)]); + await R.exec("DELETE FROM monitor_numeric_history WHERE time < ?", [ + R.isoDateTimeMillis(numericHistoryCutoff), + ]); if (Database.dbConfig.type === "sqlite") { await R.exec("PRAGMA optimize;"); diff --git a/server/uptime-calculator.js b/server/uptime-calculator.js index 6dbcd21ac..a3118ecf2 100644 --- a/server/uptime-calculator.js +++ b/server/uptime-calculator.js @@ -301,7 +301,8 @@ class UptimeCalculator { minutelyData.minNumeric = numValue; minutelyData.maxNumeric = numValue; } else { - minutelyData.avgNumeric = (minutelyData.avgNumeric * (minutelyData.up - 1) + numValue) / minutelyData.up; + minutelyData.avgNumeric = + (minutelyData.avgNumeric * (minutelyData.up - 1) + numValue) / minutelyData.up; minutelyData.minNumeric = Math.min(minutelyData.minNumeric, numValue); minutelyData.maxNumeric = Math.max(minutelyData.maxNumeric, numValue); } @@ -319,7 +320,8 @@ class UptimeCalculator { hourlyData.minNumeric = numValue; hourlyData.maxNumeric = numValue; } else { - hourlyData.avgNumeric = (hourlyData.avgNumeric * (hourlyData.up - 1) + numValue) / hourlyData.up; + hourlyData.avgNumeric = + (hourlyData.avgNumeric * (hourlyData.up - 1) + numValue) / hourlyData.up; hourlyData.minNumeric = Math.min(hourlyData.minNumeric, numValue); hourlyData.maxNumeric = Math.max(hourlyData.maxNumeric, numValue); } @@ -378,7 +380,8 @@ class UptimeCalculator { dailyStatBean.numeric_max = dailyData.maxNumeric; { // eslint-disable-next-line no-unused-vars - const { up, down, avgPing, minPing, maxPing, avgNumeric, minNumeric, maxNumeric, timestamp, ...extras } = dailyData; + const { up, down, avgPing, minPing, maxPing, avgNumeric, minNumeric, maxNumeric, timestamp, ...extras } = + dailyData; if (Object.keys(extras).length > 0) { dailyStatBean.extras = JSON.stringify(extras); } @@ -401,7 +404,18 @@ class UptimeCalculator { hourlyStatBean.numeric_max = hourlyData.maxNumeric; { // eslint-disable-next-line no-unused-vars - const { up, down, avgPing, minPing, maxPing, avgNumeric, minNumeric, maxNumeric, timestamp, ...extras } = hourlyData; + const { + up, + down, + avgPing, + minPing, + maxPing, + avgNumeric, + minNumeric, + maxNumeric, + timestamp, + ...extras + } = hourlyData; if (Object.keys(extras).length > 0) { hourlyStatBean.extras = JSON.stringify(extras); } @@ -423,7 +437,18 @@ class UptimeCalculator { minutelyStatBean.numeric_max = minutelyData.maxNumeric; { // eslint-disable-next-line no-unused-vars - const { up, down, avgPing, minPing, maxPing, avgNumeric, minNumeric, maxNumeric, timestamp, ...extras } = minutelyData; + const { + up, + down, + avgPing, + minPing, + maxPing, + avgNumeric, + minNumeric, + maxNumeric, + timestamp, + ...extras + } = minutelyData; if (Object.keys(extras).length > 0) { minutelyStatBean.extras = JSON.stringify(extras); }