Skip to content

Commit bdb5fdf

Browse files
committed
lib: remove metric report format output
1 parent 989475e commit bdb5fdf

3 files changed

Lines changed: 0 additions & 147 deletions

File tree

doc/api/metrics.md

Lines changed: 0 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -227,62 +227,6 @@ added: REPLACEME
227227
The `performance.now()` timestamp when the measurement was recorded in
228228
milliseconds since `performance.timeOrigin`.
229229

230-
#### `metricReport.toStatsd()`
231-
232-
<!-- YAML
233-
added: REPLACEME
234-
-->
235-
236-
* Returns: {string}
237-
238-
Formats the metric report as a StatsD-compatible string.
239-
240-
```js
241-
console.log(report.toStatsd()); // 'api.calls:1|c'
242-
```
243-
244-
#### `metricReport.toDogStatsd()`
245-
246-
<!-- YAML
247-
added: REPLACEME
248-
-->
249-
250-
* Returns: {string}
251-
252-
Formats the metric report as a DogStatsD-compatible string with tags.
253-
254-
```js
255-
console.log(report.toDogStatsd()); // 'api.calls:1|c|service:web'
256-
```
257-
258-
#### `metricReport.toGraphite()`
259-
260-
<!-- YAML
261-
added: REPLACEME
262-
-->
263-
264-
* Returns: {string}
265-
266-
Formats the metric report as a Graphite-compatible string.
267-
268-
```js
269-
console.log(report.toGraphite()); // 'api.calls 1 1234567890'
270-
```
271-
272-
#### `metricReport.toPrometheus()`
273-
274-
<!-- YAML
275-
added: REPLACEME
276-
-->
277-
278-
* Returns: {string}
279-
280-
Formats the metric report as a Prometheus-compatible string.
281-
282-
```js
283-
console.log(report.toPrometheus()); // 'api_calls{service="web"} 1 1234567890.123'
284-
```
285-
286230
### Class: `Metric`
287231

288232
<!-- YAML

lib/metrics.js

Lines changed: 0 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -120,83 +120,6 @@ class MetricReport {
120120
get time() {
121121
return this.#time;
122122
}
123-
124-
/**
125-
* Convert the metric report to a statsd-compatible string.
126-
* @returns {string} The statsd-formatted metric report.
127-
*/
128-
toStatsd() {
129-
const { type, name, value } = this;
130-
return `${name}:${value}|${this.#statsdType(type)}`;
131-
}
132-
133-
/*
134-
* Convert the metric type to a statsd type.
135-
*
136-
* @param {string} type The metric type.
137-
* @returns {string} The statsd type.
138-
* @private
139-
*/
140-
#statsdType(type) {
141-
return {
142-
counter: 'c',
143-
gauge: 'g',
144-
pullGauge: 'g',
145-
timer: 'ms',
146-
}[type];
147-
}
148-
149-
/**
150-
* Convert the metric report to a Dogstatsd-compatible string.
151-
* @returns {string} The Dogstatsd-formatted metric report.
152-
*/
153-
toDogStatsd() {
154-
return `${this.toStatsd()}${this.#dogstatsdTags()}`;
155-
}
156-
157-
/*
158-
* Pack metadata into Dogstatsd-compatible tags.
159-
*
160-
* @returns {string} The packed metadata.
161-
* @private
162-
*/
163-
#dogstatsdTags() {
164-
const entries = ObjectEntries(this.meta);
165-
const pairs = ArrayPrototypeMap(entries, ({ 0: k, 1: v }) => `${k}:${v}`);
166-
const tags = ArrayPrototypeJoin(pairs, ',');
167-
return tags.length ? `|${tags}` : '';
168-
}
169-
170-
/**
171-
* Convert the metric report to a graphite-compatible string.
172-
* @returns {string} The graphite-formatted metric report.
173-
*/
174-
toGraphite() {
175-
const { name, value, time } = this;
176-
return `${name} ${value} ${MathFloor(time / 1000)}`;
177-
}
178-
179-
/**
180-
* Convert the metric report to a Prometheus-compatible string.
181-
* @returns {string} The Prometheus-formatted metric report.
182-
*/
183-
toPrometheus() {
184-
const { name, value, time } = this;
185-
return `${name}${this.#prometheusLabels()} ${value} ${time}`;
186-
}
187-
188-
/*
189-
* Pack metadata into Prometheus-compatible labels.
190-
*
191-
* @returns {string} The packed metadata.
192-
* @private
193-
*/
194-
#prometheusLabels() {
195-
const entries = ObjectEntries(this.meta);
196-
const pairs = ArrayPrototypeMap(entries, ({ 0: k, 1: v }) => `${k}="${v}"`);
197-
const labels = ArrayPrototypeJoin(pairs, ',');
198-
return labels.length ? `{${labels}}` : '';
199-
}
200123
}
201124

202125
/**

test/parallel/test-metrics-metric-report.js

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,3 @@ assert.strictEqual(report.name, 'test-counter');
1515
assert.strictEqual(report.value, 123);
1616
assert.deepStrictEqual(report.meta, { meta: 'test' });
1717
assert.ok(report.time > 0);
18-
19-
assert.strictEqual(report.toStatsd(), 'test-counter:123|c');
20-
assert.strictEqual(
21-
report.toPrometheus(),
22-
`test-counter{meta="test"} 123 ${report.time}`
23-
);
24-
assert.strictEqual(
25-
report.toDogStatsd(),
26-
'test-counter:123|c|meta:test'
27-
);
28-
assert.strictEqual(
29-
report.toGraphite(),
30-
`test-counter 123 ${Math.floor(report.time / 1000)}`
31-
);

0 commit comments

Comments
 (0)