prometheus
1export interface Labels {
2[key: string]: string;
3}
4
5export type Target = {
6discoveredLabels: Labels;
7labels: Labels;
8scrapePool: string;
9scrapeUrl: string;
10globalUrl: string;
11lastError: string;
12lastScrape: string;
13lastScrapeDuration: number;
14health: string;
15scrapeInterval: string;
16scrapeTimeout: string;
17};
18
19export interface DroppedTarget {
20discoveredLabels: Labels;
21}
22
23export interface ScrapePool {
24upCount: number;
25targets: Target[];
26}
27
28export interface ScrapePools {
29[scrapePool: string]: ScrapePool;
30}
31
32export const groupTargets = (targets: Target[]): ScrapePools =>
33targets.reduce((pools: ScrapePools, target: Target) => {
34const { health, scrapePool } = target;
35const up = health.toLowerCase() === 'up' ? 1 : 0;
36if (!pools[scrapePool]) {
37pools[scrapePool] = {
38upCount: 0,
39targets: [],
40};
41}
42pools[scrapePool].targets.push(target);
43pools[scrapePool].upCount += up;
44return pools;
45}, {});
46
47export const getColor = (health: string): string => {
48switch (health.toLowerCase()) {
49case 'up':
50return 'success';
51case 'down':
52return 'danger';
53default:
54return 'warning';
55}
56};
57
58export interface TargetHealthFilters {
59healthy: boolean;
60unhealthy: boolean;
61unknown: boolean;
62}
63
64export const filterTargetsByHealth = (health: string, filters: TargetHealthFilters): boolean => {
65switch (health.toLowerCase()) {
66case 'up':
67return filters.healthy;
68case 'down':
69return filters.unhealthy;
70default:
71return filters.unknown;
72}
73};
74