Commit 33b1d676 authored by Annie Ke's avatar Annie Ke Committed by Liam Horne

add metrics.ts and use in base-service

parent 3514ae87
/* Imports: Internal */ /* Imports: Internal */
import { Logger } from './common/logger' import { Logger } from './common/logger'
import { Metrics } from './common/metrics'
type OptionSettings<TOptions> = { type OptionSettings<TOptions> = {
[P in keyof TOptions]?: { [P in keyof TOptions]?: {
...@@ -16,6 +17,7 @@ export class BaseService<T> { ...@@ -16,6 +17,7 @@ export class BaseService<T> {
protected name: string protected name: string
protected options: T protected options: T
protected logger: Logger protected logger: Logger
protected metrics: Metrics
protected initialized: boolean = false protected initialized: boolean = false
protected running: boolean = false protected running: boolean = false
...@@ -24,6 +26,7 @@ export class BaseService<T> { ...@@ -24,6 +26,7 @@ export class BaseService<T> {
this.name = name this.name = name
this.options = mergeDefaultOptions(options, optionSettings) this.options = mergeDefaultOptions(options, optionSettings)
this.logger = new Logger({ name }) this.logger = new Logger({ name })
this.metrics = new Metrics({ prefix: name })
} }
/** /**
......
import prometheus, {
collectDefaultMetrics,
DefaultMetricsCollectorConfiguration,
Registry,
} from 'prom-client'
export interface MetricsOptions {
prefix: string
labels?: Object
}
export class Metrics {
options: MetricsOptions
client: typeof prometheus
registry: Registry
constructor(options: MetricsOptions) {
this.options = options
const metricsOptions: DefaultMetricsCollectorConfiguration = {
prefix: options.prefix,
labels: options.labels,
}
this.client = prometheus
this.registry = prometheus.register
// Collect default metrics (event loop lag, memory, file descriptors etc.)
collectDefaultMetrics(metricsOptions)
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment