2019-11-11 13:42:24 -08:00
|
|
|
export interface Labels {
|
|
|
|
[key: string]: string;
|
|
|
|
}
|
|
|
|
|
2022-01-10 06:53:14 -08:00
|
|
|
export type Target = {
|
2019-11-11 13:42:24 -08:00
|
|
|
discoveredLabels: Labels;
|
|
|
|
labels: Labels;
|
|
|
|
scrapePool: string;
|
|
|
|
scrapeUrl: string;
|
2020-02-17 09:19:15 -08:00
|
|
|
globalUrl: string;
|
2019-11-11 13:42:24 -08:00
|
|
|
lastError: string;
|
|
|
|
lastScrape: string;
|
|
|
|
lastScrapeDuration: number;
|
|
|
|
health: string;
|
2021-08-31 08:37:32 -07:00
|
|
|
scrapeInterval: string;
|
|
|
|
scrapeTimeout: string;
|
2022-01-10 06:53:14 -08:00
|
|
|
};
|
2019-11-11 13:42:24 -08:00
|
|
|
|
2019-12-31 09:41:50 -08:00
|
|
|
export interface DroppedTarget {
|
|
|
|
discoveredLabels: Labels;
|
|
|
|
}
|
|
|
|
|
2019-11-11 13:42:24 -08:00
|
|
|
export interface ScrapePool {
|
|
|
|
upCount: number;
|
|
|
|
targets: Target[];
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface ScrapePools {
|
|
|
|
[scrapePool: string]: ScrapePool;
|
|
|
|
}
|
|
|
|
|
|
|
|
export const groupTargets = (targets: Target[]): ScrapePools =>
|
|
|
|
targets.reduce((pools: ScrapePools, target: Target) => {
|
|
|
|
const { health, scrapePool } = target;
|
|
|
|
const up = health.toLowerCase() === 'up' ? 1 : 0;
|
|
|
|
if (!pools[scrapePool]) {
|
|
|
|
pools[scrapePool] = {
|
|
|
|
upCount: 0,
|
|
|
|
targets: [],
|
|
|
|
};
|
|
|
|
}
|
|
|
|
pools[scrapePool].targets.push(target);
|
|
|
|
pools[scrapePool].upCount += up;
|
|
|
|
return pools;
|
|
|
|
}, {});
|
|
|
|
|
|
|
|
export const getColor = (health: string): string => {
|
|
|
|
switch (health.toLowerCase()) {
|
|
|
|
case 'up':
|
|
|
|
return 'success';
|
|
|
|
case 'down':
|
|
|
|
return 'danger';
|
|
|
|
default:
|
|
|
|
return 'warning';
|
|
|
|
}
|
|
|
|
};
|