diff options
author | Ivan Topolnjak <ivantopo@gmail.com> | 2019-03-18 13:44:50 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-03-18 13:44:50 +0100 |
commit | 8efb3b408a876a3dfdac79580773279125cb4135 (patch) | |
tree | 96fd746fc13f4ffb914d8e59c4ea074513877556 /kamon-status-page/src/main/vue/src/api/StatusApi.ts | |
parent | e311df4b3a272f4f160857f718a96ec316a2fc06 (diff) | |
parent | ec83a72879378bc9eedea24f828e4d30fed95e92 (diff) | |
download | Kamon-8efb3b408a876a3dfdac79580773279125cb4135.tar.gz Kamon-8efb3b408a876a3dfdac79580773279125cb4135.tar.bz2 Kamon-8efb3b408a876a3dfdac79580773279125cb4135.zip |
Merge pull request #569 from ivantopo/status-page
Status page
Diffstat (limited to 'kamon-status-page/src/main/vue/src/api/StatusApi.ts')
-rw-r--r-- | kamon-status-page/src/main/vue/src/api/StatusApi.ts | 137 |
1 files changed, 137 insertions, 0 deletions
diff --git a/kamon-status-page/src/main/vue/src/api/StatusApi.ts b/kamon-status-page/src/main/vue/src/api/StatusApi.ts new file mode 100644 index 00000000..ee596b8d --- /dev/null +++ b/kamon-status-page/src/main/vue/src/api/StatusApi.ts @@ -0,0 +1,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 + }) + } +} |