Skip to content

Commit

Permalink
Merge pull request #347 from matrix-org/hs/buckets
Browse files Browse the repository at this point in the history
Allow specifying bucket sizes for timers
  • Loading branch information
Half-Shot authored Aug 9, 2021
2 parents 916b401 + c0ee72e commit 4a80d46
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
1 change: 1 addition & 0 deletions changelog.d/347.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add `buckets` option to PrometheusMetrics.addTimer, to specify custom bucket intervals.
16 changes: 8 additions & 8 deletions src/components/prometheusmetrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>) => void;
}

Expand Down Expand Up @@ -346,22 +345,23 @@ export class PrometheusMetrics {
* new metric. Default: <code>"bridge"</code>.
* @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<string>=} 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
* <code>startTimer</code> method.
*/
public addTimer(opts: CounterOpts) {
public addTimer(opts: HistogramOpts): PromClient.Histogram<string> {
const name = [opts.namespace || "bridge", opts.name].join("_");

const timer = this.timers[opts.name] =
new PromClient.Histogram({
name,
help: opts.help,
labelNames: opts.labels || [],
registers: [this.register]
registers: [this.register],
buckets: opts.buckets,
});

return timer;
}

Expand Down

0 comments on commit 4a80d46

Please sign in to comment.