mirror of
https://github.com/BreizhHardware/express-prom-bundle.git
synced 2026-03-18 21:30:38 +01:00
use collectDefaultMetrics.prefix for up metric
This commit is contained in:
@@ -546,15 +546,37 @@ describe('index', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('calls promClient.collectDefaultMetrics', () => {
|
describe('option collectDefaultMetrics', () => {
|
||||||
const spy = spyOn(promClient, 'collectDefaultMetrics');
|
it('it gets called', () => {
|
||||||
bundle({
|
const spy = spyOn(promClient, 'collectDefaultMetrics');
|
||||||
promClient: {
|
bundle({
|
||||||
collectDefaultMetrics: {
|
promClient: {
|
||||||
|
collectDefaultMetrics: {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
|
expect(spy).toHaveBeenCalledWith({});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('prefix is used for up metric', (done) => {
|
||||||
|
const instance = bundle({
|
||||||
|
promClient: {
|
||||||
|
collectDefaultMetrics: {
|
||||||
|
prefix: 'hello_'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
const app = express();
|
||||||
|
app.use(instance);
|
||||||
|
const agent = supertest(app);
|
||||||
|
agent
|
||||||
|
.get('/metrics')
|
||||||
|
.end((err, res) => {
|
||||||
|
expect(res.status).toBe(200);
|
||||||
|
expect(res.text).toMatch(/^hello_up\s1/m);
|
||||||
|
done();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
expect(spy).toHaveBeenCalledWith({});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('usage of clusterMetrics()', () => {
|
describe('usage of clusterMetrics()', () => {
|
||||||
|
|||||||
@@ -132,8 +132,12 @@ function main(opts) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
if (opts.includeUp !== false) {
|
if (opts.includeUp !== false) {
|
||||||
|
let prefix = '';
|
||||||
|
if (opts.promClient && opts.promClient.collectDefaultMetrics) {
|
||||||
|
prefix = opts.promClient.collectDefaultMetrics.prefix || '';
|
||||||
|
}
|
||||||
metrics.up = new promClient.Gauge({
|
metrics.up = new promClient.Gauge({
|
||||||
name: 'up',
|
name: `${prefix}up`,
|
||||||
help: '1 = up, 0 = not up',
|
help: '1 = up, 0 = not up',
|
||||||
registers: [opts.promRegistry]
|
registers: [opts.promRegistry]
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user