...
 
Commits (2)
{
"name": "embeddia-front",
"version": "0.0.0",
"version": "0.0.1",
"scripts": {
"ng": "ng",
"start": "ng serve",
......
......@@ -5,7 +5,7 @@ import {LogService} from './log.service';
import {Observable} from 'rxjs';
import {GeneratorResponse} from '../shared/types/GeneratorResponse';
import {catchError, tap} from 'rxjs/operators';
import {Health} from '../shared/types/Health';
import {Health, NLGHealth} from '../shared/types/Health';
@Injectable({
providedIn: 'root'
......@@ -13,6 +13,7 @@ import {Health} from '../shared/types/Health';
export class CoreService {
apiUrl = environment.apiHost + environment.apiBasePath;
nlgUrl = environment.apiNLG;
constructor(private http: HttpClient, private logService: LogService) {
}
......@@ -24,4 +25,11 @@ export class CoreService {
tap(e => this.logService.logStatus(e, 'getHealth')),
catchError(this.logService.handleError<Health>('getHealth')));
}
getNLGHealth(): Observable<NLGHealth | HttpErrorResponse> {
return this.http.get<NLGHealth>(
`${this.nlgUrl}/health/`
).pipe(
tap(e => this.logService.logStatus(e, 'getHealth')),
catchError(this.logService.handleError<NLGHealth>('getHealth')));
}
}
......@@ -17,7 +17,7 @@ export class HealthComponent implements OnInit, OnDestroy {
memory = 0;
memoryObj: Memory;
diskObj: Disk;
services: { key: string, value: boolean }[];
services: { key: string, value: boolean }[] = [];
loading = true;
destroyed$: Subject<boolean> = new Subject<boolean>();
......@@ -27,6 +27,13 @@ export class HealthComponent implements OnInit, OnDestroy {
// router reuse strat? endpoint is slow
ngOnInit(): void {
this.coreService.getNLGHealth().subscribe(x => {
if (x && !(x instanceof HttpErrorResponse)) {
this.services = [...this.services, {key: 'NLG', value: true}];
} else if (x) {
this.services = [...this.services, {key: 'NLG', value: false}];
}
});
this.coreService.getHealth().pipe(takeUntil(this.destroyed$)).subscribe(x => {
if (x && !(x instanceof HttpErrorResponse)) {
this.memoryObj = x.memory;
......@@ -34,10 +41,11 @@ export class HealthComponent implements OnInit, OnDestroy {
this.cpu = x.cpu.percent;
this.disk = Math.ceil(x.disk.used / x.disk.total * 100);
this.memory = Math.ceil(x.memory.used / x.memory.total * 100);
this.services = Object.keys(x.services).flatMap(y => [{key: y, value: x.services[y]}]);
this.services = [...this.services, ...Object.keys(x.services).flatMap(y => [{key: y, value: x.services[y]}])];
}
}, () => null, () => this.loading = false);
}
ngOnDestroy(): void {
this.destroyed$.next(true);
this.destroyed$.complete();
......
......@@ -29,3 +29,7 @@ export interface Health {
}
export interface NLGHealth {
version: string;
}