Skip to content

Commit

Permalink
fix: monitoring
Browse files Browse the repository at this point in the history
  • Loading branch information
zdm committed Aug 31, 2024
1 parent 836d601 commit e8e7ba3
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import sql from "#lib/sql";

const STATS_PERIODS = {
"1 hour": "minute",
"7 days": "hour",
"30 days": "hour",
};

const SQL = {
"getInstances": sql`SELECT * FROM monitoring_instance WHERE last_updated > CURRENT_TIMESTAMP - INTERVAL '1 hour'`.prepare(),

Expand Down Expand Up @@ -60,11 +66,6 @@ export default Super =>
}

async API_getInstanceStats ( ctx, instanceId, period ) {
if ( period === "1 hour" ) {
return this.dbh.select( SQL.getStats, [ "60 minutes", "minute", instanceId ] );
}
else {
return this.dbh.select( SQL.getStats, [ "30 days", "hour", instanceId ] );
}
return this.dbh.select( SQL.getStats, [ period, STATS_PERIODS[ period ], instanceId ] );
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ methods:
schema: { type: integer }
- name: period
required: true
schema: { enum: [1 hour, 30 days] }
schema: { enum: [1 hour, 7 days, 30 days] }
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import sql from "#lib/sql";

const STATS_PERIODS = {
"1 hour": "minute",
"7 days": "hour",
"30 days": "hour",
};

const SQL = {
"getMethods": sql`
WITH total AS (
Expand Down Expand Up @@ -107,12 +113,7 @@ export default Super =>
}

async API_getMonitoringMethodStats ( ctx, monitoringMethodId, period ) {
if ( period === "1 hour" ) {
return this.dbh.select( SQL.getStats, [ "60 minutes", "minute", monitoringMethodId ] );
}
else {
return this.dbh.select( SQL.getStats, [ "30 days", "hour", monitoringMethodId ] );
}
return this.dbh.select( SQL.getStats, [ period, STATS_PERIODS[ period ], monitoringMethodId ] );
}

async API_getMethodExceptionsList ( ctx, options = {} ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ methods:
schema: { type: integer }
- name: period
required: true
schema: { enum: [1 hour, 30 days] }
schema: { enum: [1 hour, 7 days, 30 days] }

get-method-exceptions-list:
title: Read the method exceptions
Expand Down

0 comments on commit e8e7ba3

Please sign in to comment.