|
|
@@ -247,6 +247,47 @@ export class Database extends SQLiteController {
|
|
|
return result.rows.map(r => ({ time: new Date(r.Timegroup), avg: r.avg, peak: r.peak, max: r.max }));
|
|
|
}
|
|
|
|
|
|
+ public async queryServerStats(serverID: number, type: ServerDataType, from: Date, to: Date): Promise<ReducedValuesPerc> {
|
|
|
+ const select_max = type !== 'cpu';
|
|
|
+ const select_types = select_max ? [type, type, type] : [type, type];
|
|
|
+ const result = await this.stmt(
|
|
|
+ `
|
|
|
+ SELECT
|
|
|
+ AVG(VALUE_AVG.Value) as 'avg',
|
|
|
+ AVG(VALUE_PEAK.Value) as 'peak'${
|
|
|
+ select_max
|
|
|
+ ? `,
|
|
|
+ MAX(VALUE_MAX.Value) as 'max'`
|
|
|
+ : ''
|
|
|
+ }
|
|
|
+ FROM ServerDataEntry
|
|
|
+ JOIN ServerDataValue AS VALUE_AVG ON ServerDataEntry.ID = VALUE_AVG.EntryID AND VALUE_AVG.Type = ? AND VALUE_AVG.Key = 'avg'
|
|
|
+ JOIN ServerDataValue AS VALUE_PEAK ON ServerDataEntry.ID = VALUE_PEAK.EntryID AND VALUE_PEAK.Type = ? AND VALUE_PEAK.Key = 'peak'
|
|
|
+ ${
|
|
|
+ select_max
|
|
|
+ ? "JOIN ServerDataValue AS VALUE_MAX ON ServerDataEntry.ID = VALUE_MAX.EntryID AND VALUE_MAX.Type = ? AND VALUE_MAX.Key = 'max'"
|
|
|
+ : ''
|
|
|
+ }
|
|
|
+ WHERE ServerDataEntry.ServerID = ?
|
|
|
+ AND ServerDataEntry.Timestamp BETWEEN ? AND ?;
|
|
|
+ `,
|
|
|
+ [...select_types, serverID, from.getTime(), to.getTime()]
|
|
|
+ );
|
|
|
+
|
|
|
+ const row = result.rows[0];
|
|
|
+ if (Object.keys(row).includes('max')) {
|
|
|
+ return {
|
|
|
+ avg: ((row['avg'] as number) / (row['max'] as number)) * 100,
|
|
|
+ peak: ((row['peak'] as number) / (row['peak'] as number)) * 100
|
|
|
+ };
|
|
|
+ } else {
|
|
|
+ return {
|
|
|
+ avg: row['avg'] as number,
|
|
|
+ peak: row['peak'] as number
|
|
|
+ };
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
private async getHealthCheckConfigs(serverID?: number, type = 'http') {
|
|
|
const res = await this.stmt(
|
|
|
`SELECT
|