prometheus/web/ui/react-app/src/pages/targets/target.ts
Dustin Hooten ca60bf298c React UI: Implement /targets page (#6276)
* Add LastScrapeDuration to targets endpoint

Signed-off-by: Dustin Hooten <dhooten@splunk.com>

* Add Scrape job name to targets endpoint

Signed-off-by: Dustin Hooten <dhooten@splunk.com>

* Implement the /targets page in react

Signed-off-by: Dustin Hooten <dhooten@splunk.com>

* Add state query param to targets endpoint

Signed-off-by: Dustin Hooten <dhooten@splunk.com>

* Use state filter in api call

Signed-off-by: Dustin Hooten <dhooten@splunk.com>

* api feedback

Signed-off-by: Dustin Hooten <dhooten@splunk.com>

* pr feedback frontend

Signed-off-by: Dustin Hooten <dhooten@splunk.com>

* Implement and use localstorage hook

Signed-off-by: Dustin Hooten <dhooten@splunk.com>

* PR feedback

Signed-off-by: Dustin Hooten <dhooten@splunk.com>
2019-11-11 22:42:24 +01:00

50 lines
1.0 KiB
TypeScript

export interface Labels {
[key: string]: string;
}
export interface Target {
discoveredLabels: Labels;
labels: Labels;
scrapePool: string;
scrapeUrl: string;
lastError: string;
lastScrape: string;
lastScrapeDuration: number;
health: string;
}
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';
}
};