|
|
@@ -0,0 +1,55 @@
|
|
|
+import { Component, Input } from '@angular/core';
|
|
|
+import { faHardDrive } from '@fortawesome/free-solid-svg-icons';
|
|
|
+import { Subscription } from 'rxjs';
|
|
|
+
|
|
|
+import { ServerApiService } from 'src/app/services/server-api.service';
|
|
|
+
|
|
|
+type FlatServerDataTypes = {
|
|
|
+ type: string;
|
|
|
+ subtype?: string;
|
|
|
+ data?: ReducedValuesPerc;
|
|
|
+};
|
|
|
+
|
|
|
+@Component({
|
|
|
+ selector: 'app-server-metrics-widget',
|
|
|
+ templateUrl: './server-metrics-widget.component.html',
|
|
|
+ styleUrls: ['./server-metrics-widget.component.scss']
|
|
|
+})
|
|
|
+export class ServerMetricsWidgetComponent {
|
|
|
+ @Input() set server(server: ServerConfig) {
|
|
|
+ this._server = server;
|
|
|
+
|
|
|
+ if (!this._typeSubscription) {
|
|
|
+ this._typeSubscription = this.apiService.serverDataTypes$.get(server.id).subscribe({ next: this.onServerDataTypes.bind(this) });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ public get server() {
|
|
|
+ return this._server;
|
|
|
+ }
|
|
|
+
|
|
|
+ public get dataTypes() {
|
|
|
+ return this._dataTypes;
|
|
|
+ }
|
|
|
+
|
|
|
+ public fa = { faHardDrive };
|
|
|
+
|
|
|
+ private _server!: ServerConfig;
|
|
|
+ private _dataTypes: FlatServerDataTypes[] = [];
|
|
|
+ private _typeSubscription?: Subscription;
|
|
|
+
|
|
|
+ constructor(private apiService: ServerApiService) {}
|
|
|
+
|
|
|
+ private async onServerDataTypes(types: ServerDataTypesConfig[]) {
|
|
|
+ this._dataTypes = types.reduce((res, type) => {
|
|
|
+ res.push(...(type.subtypes?.map(sub => ({ type: type.type, subtype: sub.type })) ?? [{ type: type.type }]));
|
|
|
+ return res;
|
|
|
+ }, [] as FlatServerDataTypes[]);
|
|
|
+
|
|
|
+ const end = new Date();
|
|
|
+ const start = new Date(end.getTime() - 1000 * 60 * 60 * 24);
|
|
|
+ for (const type of this._dataTypes) {
|
|
|
+ // Fetch 24h stats of this dataType
|
|
|
+ type.data = await this.apiService.queryServerStats(this.server.id, type.type + (type.subtype ? `:${type.subtype}` : ''), start, end);
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|