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