52 lines
1.3 KiB
TypeScript
52 lines
1.3 KiB
TypeScript
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<Metric[]> {
|
|
return this.http.get(this.baseUrl+url,
|
|
{responseType: 'text'}).pipe<Metric[]>(map(value => JSON.parse(value,
|
|
(key, value) => {
|
|
if (key === 'timestamp') {
|
|
value = new Date(value)
|
|
}
|
|
|
|
return value;
|
|
})))
|
|
}
|
|
|
|
getDead(): Observable<Metric[]> {
|
|
return this.fetchMetrics("/api/v1/metrics/dead");
|
|
}
|
|
|
|
getOk(): Observable<Metric[]> {
|
|
return this.fetchMetrics("/api/v1/metrics/ok")
|
|
}
|
|
|
|
getUnknown(): Observable<Metric[]> {
|
|
return this.fetchMetrics("/api/v1/metrics/unknown")
|
|
}
|
|
|
|
getNotGood(): Observable<Metric[]> {
|
|
return this.fetchMetrics("/api/v1/metrics/not-good")
|
|
}
|
|
|
|
getCount(): Observable<StatusIntMap> {
|
|
return this.http.get<StatusIntMap>(this.baseUrl+"/api/v1/metrics")
|
|
}
|
|
}
|