diff --git a/changelog.d/347.feature b/changelog.d/347.feature new file mode 100644 index 00000000..76d4a2d3 --- /dev/null +++ b/changelog.d/347.feature @@ -0,0 +1 @@ +Add `buckets` option to PrometheusMetrics.addTimer, to specify custom bucket intervals. \ No newline at end of file diff --git a/src/components/prometheusmetrics.ts b/src/components/prometheusmetrics.ts index 61a7c3ea..730dac2d 100644 --- a/src/components/prometheusmetrics.ts +++ b/src/components/prometheusmetrics.ts @@ -38,12 +38,11 @@ interface CounterOpts { help: string; labels?: string[]; } +interface HistogramOpts extends CounterOpts { + buckets?: number[]; +} -interface GagueOpts { - namespace?: string; - name: string; - help: string; - labels?: string[]; +interface GagueOpts extends CounterOpts { refresh?: (gauge: PromClient.Gauge) => void; } @@ -346,12 +345,13 @@ export class PrometheusMetrics { * new metric. Default: "bridge". * @param {string} opts.name The variable name for the new metric. * @param {string} opts.help Descriptive help text for the new metric. + * @param {string} opts.buckets The buckets that should be used for the histogram. * @param {Array=} opts.labels An optional list of string label names * @return {Histogram} A histogram metric. * Once created, the value of this metric can be incremented with the * startTimer method. */ - public addTimer(opts: CounterOpts) { + public addTimer(opts: HistogramOpts): PromClient.Histogram { const name = [opts.namespace || "bridge", opts.name].join("_"); const timer = this.timers[opts.name] = @@ -359,9 +359,9 @@ export class PrometheusMetrics { name, help: opts.help, labelNames: opts.labels || [], - registers: [this.register] + registers: [this.register], + buckets: opts.buckets, }); - return timer; }