Skip to content

Commit b8ee5d7

Browse files
committed
add source to metrics, add histogram and summary to client
1 parent bbd74bc commit b8ee5d7

File tree

1 file changed

+34
-2
lines changed

1 file changed

+34
-2
lines changed

lib/client.js

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ const Metric = require('@metrics/metric');
99

1010
const Counter = require('./counter');
1111
const Gauge = require('./gauge');
12+
const Summary = require('./summary');
13+
const Histogram = require('./histogram');
1214

1315
const push = Symbol('push');
1416

@@ -46,16 +48,44 @@ const MetricsClient = class MetricsClient extends stream.Transform {
4648

4749
counter(options) {
4850
const counter = new Counter(options);
49-
counter.on('metric', metric => this[push](metric));
51+
counter.on('metric', metric => {
52+
// eslint-disable-next-line no-param-reassign
53+
metric.source = this.source;
54+
this[push](metric);
55+
});
5056
return counter;
5157
}
5258

5359
gauge(options) {
5460
const gauge = new Gauge(options);
55-
gauge.on('metric', metric => this[push](metric));
61+
gauge.on('metric', metric => {
62+
// eslint-disable-next-line no-param-reassign
63+
metric.source = this.source;
64+
this[push](metric);
65+
});
5666
return gauge;
5767
}
5868

69+
summary(options) {
70+
const summary = new Summary(options);
71+
summary.on('metric', metric => {
72+
// eslint-disable-next-line no-param-reassign
73+
metric.source = this.source;
74+
this[push](metric);
75+
});
76+
return summary;
77+
}
78+
79+
histogram(options) {
80+
const histogram = new Histogram(options);
81+
histogram.on('metric', metric => {
82+
// eslint-disable-next-line no-param-reassign
83+
metric.source = this.source;
84+
this[push](metric);
85+
});
86+
return histogram;
87+
}
88+
5989
timer(options = {}) {
6090
const end = timeSpan();
6191
return (opts = {}) => {
@@ -68,12 +98,14 @@ const MetricsClient = class MetricsClient extends stream.Transform {
6898
...opts,
6999
meta,
70100
});
101+
metric.source = this.source;
71102
this[push](metric);
72103
};
73104
}
74105

75106
metric(options) {
76107
const metric = new Metric(options);
108+
metric.source = this.source;
77109
this[push](metric);
78110
}
79111

0 commit comments

Comments
 (0)