aboutsummaryrefslogtreecommitdiff
path: root/kamon-status-page/src/main/vue/src/api/StatusApi.ts
blob: ee596b8deaee1e88610c3723fa47d4d2a4b59a05 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
import axios, { AxiosResponse } from 'axios'

export interface Environment {
  service: string
  host: string
  instance: string
  tags: { [key: string]: string }
}

export interface Settings {
  version: string
  environment: Environment
  config: any
}

export enum ModuleKind {
  Combined = 'combined',
  Metric = 'metric',
  Span = 'span',
  Plain = 'plain',
  Unknown = 'unknown'
}

export interface Module {
  name: string
  description: string
  clazz: string
  kind: ModuleKind
  programmaticallyRegistered: boolean
  enabled: boolean
  started: boolean
}

export interface Metric {
  name: string
  type: string
  unitDimension: string
  unitMagnitude: string
  tags: { [key: string ]: string }
  search: string
}

export interface ModuleRegistry {
  modules: Module[]
}

export interface MetricRegistry {
  metrics: Metric[]
}

export interface InstrumentationModule {
  name: string
  description: string
  enabled: boolean
  active: boolean
}

export interface Instrumentation {
  active: boolean
  modules: InstrumentationModule[]
  errors: { [key: string]: string[]}
}


export class StatusApi {

  public static settings(): Promise<Settings> {
    return axios.get('/status/settings').then(response => {
      const config = JSON.parse(response.data.config)
      return {
        version: response.data.version,
        environment: response.data.environment,
        config
      }
    })
  }

  public static moduleRegistryStatus(): Promise<ModuleRegistry> {
    return axios.get('/status/modules').then(response => {
      return response.data as ModuleRegistry
    })
  }

  public static metricRegistryStatus(): Promise<MetricRegistry> {
    return axios.get('/status/metrics').then(response => {
      const metricRegistry = response.data as MetricRegistry
      const pair = (key: string, value: string) => key + ':' + value + ' '

      metricRegistry.metrics.forEach(metric => {
        // Fixes the display name for range samplers
        if (metric.type === 'RangeSampler') {
          metric.type = 'Range Sampler'
        }


        // Calculate the "search" string and inject it in all metrics.
        let tagsSearch = ''
        Object.keys(metric.tags).forEach(tag => {
          tagsSearch += pair(tag, metric.tags[tag])
        })

        metric.search =
          pair('name', metric.name.toLowerCase()) +
          pair('type', metric.type.toLowerCase()) +
          tagsSearch
      })

      return metricRegistry
    })
  }

  public static instrumentationStatus(): Promise<Instrumentation> {
    return axios.get('/status/instrumentation').then(response => {
      const instrumentation: Instrumentation = {
        active: response.data.active as boolean,
        modules: [],
        errors: {}
      }

      const rawModules = response.data.modules
      Object.keys(rawModules).forEach(key => {
        const rawModule = JSON.parse(rawModules[key])
        instrumentation.modules.push({
          name: key,
          ...rawModule
        })
      })

      const rawErrors = response.data.errors
      Object.keys(rawErrors).forEach(key => {
        instrumentation.errors[key] = JSON.parse(rawErrors[key])
      })

      return instrumentation
    })
  }
}