prometheus

Форк
0
73 строки · 1.5 Кб
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
  scrapeInterval: string;
16
  scrapeTimeout: string;
17
};
18

19
export interface DroppedTarget {
20
  discoveredLabels: Labels;
21
}
22

23
export interface ScrapePool {
24
  upCount: number;
25
  targets: Target[];
26
}
27

28
export interface ScrapePools {
29
  [scrapePool: string]: ScrapePool;
30
}
31

32
export const groupTargets = (targets: Target[]): ScrapePools =>
33
  targets.reduce((pools: ScrapePools, target: Target) => {
34
    const { health, scrapePool } = target;
35
    const up = health.toLowerCase() === 'up' ? 1 : 0;
36
    if (!pools[scrapePool]) {
37
      pools[scrapePool] = {
38
        upCount: 0,
39
        targets: [],
40
      };
41
    }
42
    pools[scrapePool].targets.push(target);
43
    pools[scrapePool].upCount += up;
44
    return pools;
45
  }, {});
46

47
export const getColor = (health: string): string => {
48
  switch (health.toLowerCase()) {
49
    case 'up':
50
      return 'success';
51
    case 'down':
52
      return 'danger';
53
    default:
54
      return 'warning';
55
  }
56
};
57

58
export interface TargetHealthFilters {
59
  healthy: boolean;
60
  unhealthy: boolean;
61
  unknown: boolean;
62
}
63

64
export const filterTargetsByHealth = (health: string, filters: TargetHealthFilters): boolean => {
65
  switch (health.toLowerCase()) {
66
    case 'up':
67
      return filters.healthy;
68
    case 'down':
69
      return filters.unhealthy;
70
    default:
71
      return filters.unknown;
72
  }
73
};
74

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.