import {Injectable} from '@angular/core'; import {Observable} from "rxjs"; import {HttpClient} from "@angular/common/http"; import {Metric} from "../models/Metric"; import {map} from 'rxjs/operators'; import {StatusIntMap} from "../models/StatusIntMap"; import {environment} from '../../../environments/environment'; @Injectable({ providedIn: 'root' }) export class FetchMetricsService { baseUrl:string constructor(private http: HttpClient) { this.baseUrl = environment.baseUrl } private fetchMetrics(url: string): Observable { return this.http.get(this.baseUrl+url, {responseType: 'text'}).pipe(map(value => JSON.parse(value, (key, value) => { if (key === 'timestamp') { value = new Date(value) } return value; }))) } getDead(): Observable { return this.fetchMetrics("/api/v1/metrics/dead"); } getOk(): Observable { return this.fetchMetrics("/api/v1/metrics/ok") } getUnknown(): Observable { return this.fetchMetrics("/api/v1/metrics/unknown") } getNotGood(): Observable { return this.fetchMetrics("/api/v1/metrics/not-good") } getCount(): Observable { return this.http.get(this.baseUrl+"/api/v1/metrics") } }