github.com/thanos-io/thanos@v0.32.5/pkg/ui/react-app/src/pages/targets/target.ts (about) 1 export interface Labels { 2 [key: string]: string; 3 } 4 5 export type Target = { 6 discoveredLabels: Labels; 7 labels: Labels; 8 scrapePool: string; 9 scrapeUrl: string; 10 globalUrl: string; 11 lastError: string; 12 lastScrape: string; 13 lastScrapeDuration: number; 14 health: string; 15 }; 16 17 export interface DroppedTarget { 18 discoveredLabels: Labels; 19 } 20 21 export interface ScrapePool { 22 upCount: number; 23 targets: Target[]; 24 } 25 26 export interface ScrapePools { 27 [scrapePool: string]: ScrapePool; 28 } 29 30 export const groupTargets = (targets: Target[]): ScrapePools => 31 targets.reduce((pools: ScrapePools, target: Target) => { 32 const { health, scrapePool } = target; 33 const up = health.toLowerCase() === 'up' ? 1 : 0; 34 if (!pools[scrapePool]) { 35 pools[scrapePool] = { 36 upCount: 0, 37 targets: [], 38 }; 39 } 40 pools[scrapePool].targets.push(target); 41 pools[scrapePool].upCount += up; 42 return pools; 43 }, {}); 44 45 export const getColor = (health: string): string => { 46 switch (health.toLowerCase()) { 47 case 'up': 48 return 'success'; 49 case 'down': 50 return 'danger'; 51 default: 52 return 'warning'; 53 } 54 };