@3sixty/telemetry-producers 0.0.0-stage → 0.20.0-next.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2024 IOTA Stiftung.
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md CHANGED
@@ -1,3 +1,25 @@
1
- # Temporary Holding Version
1
+ # 3Sixty Telemetry Producers
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ This package provides metrics producers that collect Node.js process and host-level system metrics on each poll cycle and publish them through the shared telemetry component.
4
+
5
+ ## Installation
6
+
7
+ ```shell
8
+ npm install @3sixty/telemetry-producers
9
+ ```
10
+
11
+ ## Examples
12
+
13
+ Usage of the APIs is shown in the examples [docs/examples.md](docs/examples.md)
14
+
15
+ ## Reference
16
+
17
+ Detailed reference documentation for the API can be found in [docs/reference/index.md](docs/reference/index.md)
18
+
19
+ ## Changelog
20
+
21
+ The changes between each version can be found in [docs/changelog.md](docs/changelog.md)
22
+
23
+ ## Origin
24
+
25
+ This package is derived from the original [iotaledger/twin-telemetry](https://github.com/iotaledger/twin-telemetry/tree/next/packages/telemetry-producers) repository.
@@ -0,0 +1,7 @@
1
+ // Copyright 2026 IOTA Stiftung.
2
+ // SPDX-License-Identifier: Apache-2.0.
3
+ export * from "./models/IProcessMetricsProducerConstructorOptions.js";
4
+ export * from "./models/ISystemMetricsProducerConstructorOptions.js";
5
+ export * from "./processMetricsProducer.js";
6
+ export * from "./systemMetricsProducer.js";
7
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,cAAc,uDAAuD,CAAC;AACtE,cAAc,sDAAsD,CAAC;AACrE,cAAc,6BAA6B,CAAC;AAC5C,cAAc,4BAA4B,CAAC","sourcesContent":["// Copyright 2026 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nexport * from \"./models/IProcessMetricsProducerConstructorOptions.js\";\nexport * from \"./models/ISystemMetricsProducerConstructorOptions.js\";\nexport * from \"./processMetricsProducer.js\";\nexport * from \"./systemMetricsProducer.js\";\n"]}
@@ -0,0 +1,4 @@
1
+ // Copyright 2026 IOTA Stiftung.
2
+ // SPDX-License-Identifier: Apache-2.0.
3
+ export {};
4
+ //# sourceMappingURL=IProcessMetricsProducerConstructorOptions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"IProcessMetricsProducerConstructorOptions.js","sourceRoot":"","sources":["../../../src/models/IProcessMetricsProducerConstructorOptions.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC","sourcesContent":["// Copyright 2026 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\n\n/**\n * The options for the process metrics producer constructor.\n */\nexport interface IProcessMetricsProducerConstructorOptions {\n\t/**\n\t * Type name of the telemetry component in `ComponentFactory`.\n\t * @default telemetry\n\t */\n\ttelemetryComponentType?: string;\n\n\t/**\n\t * Per-metric history cap.\n\t * @default 1440\n\t */\n\tmaxHistory?: number;\n}\n"]}
@@ -0,0 +1,4 @@
1
+ // Copyright 2026 IOTA Stiftung.
2
+ // SPDX-License-Identifier: Apache-2.0.
3
+ export {};
4
+ //# sourceMappingURL=ISystemMetricsProducerConstructorOptions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ISystemMetricsProducerConstructorOptions.js","sourceRoot":"","sources":["../../../src/models/ISystemMetricsProducerConstructorOptions.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC","sourcesContent":["// Copyright 2026 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\n\n/**\n * The options for the system metrics producer constructor.\n */\nexport interface ISystemMetricsProducerConstructorOptions {\n\t/**\n\t * Type name of the telemetry component in `ComponentFactory`.\n\t * @default telemetry\n\t */\n\ttelemetryComponentType?: string;\n\n\t/**\n\t * Per-metric history cap.\n\t * @default 1440\n\t */\n\tmaxHistory?: number;\n}\n"]}
@@ -0,0 +1,82 @@
1
+ // Copyright 2026 IOTA Stiftung.
2
+ // SPDX-License-Identifier: Apache-2.0.
3
+ import { ComponentFactory } from "@3sixty/core";
4
+ import { MetricHelper, MetricType } from "@3sixty/telemetry-models";
5
+ /**
6
+ * Metrics producer that emits Node.js process metrics on every poll cycle.
7
+ */
8
+ export class ProcessMetricsProducer {
9
+ /**
10
+ * Runtime name for the class.
11
+ */
12
+ static CLASS_NAME = "ProcessMetricsProducer";
13
+ /**
14
+ * Resolved telemetry component.
15
+ * @internal
16
+ */
17
+ _telemetry;
18
+ /**
19
+ * Per-metric history cap.
20
+ * @internal
21
+ */
22
+ _maxHistory;
23
+ /**
24
+ * Create a new instance of ProcessMetricsProducer.
25
+ * @param options The options for the producer.
26
+ */
27
+ constructor(options) {
28
+ this._telemetry = ComponentFactory.get(options?.telemetryComponentType ?? "telemetry");
29
+ this._maxHistory = options?.maxHistory ?? 1440;
30
+ }
31
+ /**
32
+ * Returns the class name of the component.
33
+ * @returns The class name of the component.
34
+ */
35
+ className() {
36
+ return ProcessMetricsProducer.CLASS_NAME;
37
+ }
38
+ /**
39
+ * Register all process metrics with the telemetry component.
40
+ * @returns A promise that resolves when all process metrics have been registered.
41
+ */
42
+ async register() {
43
+ await MetricHelper.createMetric(this._telemetry, {
44
+ id: "process_memory_rss_bytes",
45
+ label: "RSS memory",
46
+ type: MetricType.Gauge,
47
+ maxHistory: this._maxHistory
48
+ });
49
+ await MetricHelper.createMetric(this._telemetry, {
50
+ id: "process_memory_heap_used_bytes",
51
+ label: "Heap used",
52
+ type: MetricType.Gauge,
53
+ maxHistory: this._maxHistory
54
+ });
55
+ await MetricHelper.createMetric(this._telemetry, {
56
+ id: "process_memory_heap_total_bytes",
57
+ label: "Heap total",
58
+ type: MetricType.Gauge,
59
+ maxHistory: this._maxHistory
60
+ });
61
+ await MetricHelper.createMetric(this._telemetry, {
62
+ id: "process_uptime_seconds",
63
+ label: "Process uptime",
64
+ type: MetricType.Gauge,
65
+ maxHistory: this._maxHistory
66
+ });
67
+ }
68
+ /**
69
+ * Read the current process metric values.
70
+ * @returns The current values for the process metrics.
71
+ */
72
+ async collect() {
73
+ const mem = process.memoryUsage();
74
+ return [
75
+ { id: "process_memory_rss_bytes", value: mem.rss },
76
+ { id: "process_memory_heap_used_bytes", value: mem.heapUsed },
77
+ { id: "process_memory_heap_total_bytes", value: mem.heapTotal },
78
+ { id: "process_uptime_seconds", value: Number(process.uptime().toFixed(1)) }
79
+ ];
80
+ }
81
+ }
82
+ //# sourceMappingURL=processMetricsProducer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"processMetricsProducer.js","sourceRoot":"","sources":["../../src/processMetricsProducer.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAEhD,OAAO,EACN,YAAY,EACZ,UAAU,EAIV,MAAM,0BAA0B,CAAC;AAGlC;;GAEG;AACH,MAAM,OAAO,sBAAsB;IAClC;;OAEG;IACI,MAAM,CAAU,UAAU,4BAA4C;IAE7E;;;OAGG;IACc,UAAU,CAAsB;IAEjD;;;OAGG;IACc,WAAW,CAAS;IAErC;;;OAGG;IACH,YAAY,OAAmD;QAC9D,IAAI,CAAC,UAAU,GAAG,gBAAgB,CAAC,GAAG,CACrC,OAAO,EAAE,sBAAsB,IAAI,WAAW,CAC9C,CAAC;QACF,IAAI,CAAC,WAAW,GAAG,OAAO,EAAE,UAAU,IAAI,IAAI,CAAC;IAChD,CAAC;IAED;;;OAGG;IACI,SAAS;QACf,OAAO,sBAAsB,CAAC,UAAU,CAAC;IAC1C,CAAC;IAED;;;OAGG;IACI,KAAK,CAAC,QAAQ;QACpB,MAAM,YAAY,CAAC,YAAY,CAAC,IAAI,CAAC,UAAU,EAAE;YAChD,EAAE,EAAE,0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["// Copyright 2026 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { ComponentFactory } from \"@3sixty/core\";\nimport { nameof } from \"@3sixty/nameof\";\nimport {\n\tMetricHelper,\n\tMetricType,\n\ttype IMetricsProducer,\n\ttype ITelemetryComponent,\n\ttype ITelemetryMetricValueEntry\n} from \"@3sixty/telemetry-models\";\nimport type { IProcessMetricsProducerConstructorOptions } from \"./models/IProcessMetricsProducerConstructorOptions.js\";\n\n/**\n * Metrics producer that emits Node.js process metrics on every poll cycle.\n */\nexport class ProcessMetricsProducer implements IMetricsProducer {\n\t/**\n\t * Runtime name for the class.\n\t */\n\tpublic static readonly CLASS_NAME: string = nameof<ProcessMetricsProducer>();\n\n\t/**\n\t * Resolved telemetry component.\n\t * @internal\n\t */\n\tprivate readonly _telemetry: ITelemetryComponent;\n\n\t/**\n\t * Per-metric history cap.\n\t * @internal\n\t */\n\tprivate readonly _maxHistory: number;\n\n\t/**\n\t * Create a new instance of ProcessMetricsProducer.\n\t * @param options The options for the producer.\n\t */\n\tconstructor(options?: IProcessMetricsProducerConstructorOptions) {\n\t\tthis._telemetry = ComponentFactory.get<ITelemetryComponent>(\n\t\t\toptions?.telemetryComponentType ?? \"telemetry\"\n\t\t);\n\t\tthis._maxHistory = options?.maxHistory ?? 1440;\n\t}\n\n\t/**\n\t * Returns the class name of the component.\n\t * @returns The class name of the component.\n\t */\n\tpublic className(): string {\n\t\treturn ProcessMetricsProducer.CLASS_NAME;\n\t}\n\n\t/**\n\t * Register all process metrics with the telemetry component.\n\t * @returns A promise that resolves when all process metrics have been registered.\n\t */\n\tpublic async register(): Promise<void> {\n\t\tawait MetricHelper.createMetric(this._telemetry, {\n\t\t\tid: \"process_memory_rss_bytes\",\n\t\t\tlabel: \"RSS memory\",\n\t\t\ttype: MetricType.Gauge,\n\t\t\tmaxHistory: this._maxHistory\n\t\t});\n\t\tawait MetricHelper.createMetric(this._telemetry, {\n\t\t\tid: \"process_memory_heap_used_bytes\",\n\t\t\tlabel: \"Heap used\",\n\t\t\ttype: MetricType.Gauge,\n\t\t\tmaxHistory: this._maxHistory\n\t\t});\n\t\tawait MetricHelper.createMetric(this._telemetry, {\n\t\t\tid: \"process_memory_heap_total_bytes\",\n\t\t\tlabel: \"Heap total\",\n\t\t\ttype: MetricType.Gauge,\n\t\t\tmaxHistory: this._maxHistory\n\t\t});\n\t\tawait MetricHelper.createMetric(this._telemetry, {\n\t\t\tid: \"process_uptime_seconds\",\n\t\t\tlabel: \"Process uptime\",\n\t\t\ttype: MetricType.Gauge,\n\t\t\tmaxHistory: this._maxHistory\n\t\t});\n\t}\n\n\t/**\n\t * Read the current process metric values.\n\t * @returns The current values for the process metrics.\n\t */\n\tpublic async collect(): Promise<ITelemetryMetricValueEntry[]> {\n\t\tconst mem = process.memoryUsage();\n\n\t\treturn [\n\t\t\t{ id: \"process_memory_rss_bytes\", value: mem.rss },\n\t\t\t{ id: \"process_memory_heap_used_bytes\", value: mem.heapUsed },\n\t\t\t{ id: \"process_memory_heap_total_bytes\", value: mem.heapTotal },\n\t\t\t{ id: \"process_uptime_seconds\", value: Number(process.uptime().toFixed(1)) }\n\t\t];\n\t}\n}\n"]}
@@ -0,0 +1,125 @@
1
+ // Copyright 2026 IOTA Stiftung.
2
+ // SPDX-License-Identifier: Apache-2.0.
3
+ import * as os from "node:os";
4
+ import { ComponentFactory } from "@3sixty/core";
5
+ import { MetricHelper, MetricType } from "@3sixty/telemetry-models";
6
+ /**
7
+ * Metrics producer that emits host-level OS metrics on every poll cycle.
8
+ */
9
+ export class SystemMetricsProducer {
10
+ /**
11
+ * Runtime name for the class.
12
+ */
13
+ static CLASS_NAME = "SystemMetricsProducer";
14
+ /**
15
+ * Resolved telemetry component.
16
+ * @internal
17
+ */
18
+ _telemetry;
19
+ /**
20
+ * Per-metric history cap.
21
+ * @internal
22
+ */
23
+ _maxHistory;
24
+ /**
25
+ * Snapshot of CPU times from the previous tick - used to compute deltas.
26
+ * @internal
27
+ */
28
+ _prevCpuTimes;
29
+ /**
30
+ * Create a new instance of SystemMetricsProducer.
31
+ * @param options The options for the producer.
32
+ */
33
+ constructor(options) {
34
+ this._telemetry = ComponentFactory.get(options?.telemetryComponentType ?? "telemetry");
35
+ this._maxHistory = options?.maxHistory ?? 1440;
36
+ this._prevCpuTimes = os.cpus().map(c => c.times);
37
+ }
38
+ /**
39
+ * Returns the class name of the component.
40
+ * @returns The class name of the component.
41
+ */
42
+ className() {
43
+ return SystemMetricsProducer.CLASS_NAME;
44
+ }
45
+ /**
46
+ * Register all system metrics with the telemetry component.
47
+ * @returns A promise that resolves when all system metrics have been registered.
48
+ */
49
+ async register() {
50
+ await MetricHelper.createMetric(this._telemetry, {
51
+ id: "system_cpu_usage_percent",
52
+ label: "CPU usage",
53
+ type: MetricType.Gauge,
54
+ maxHistory: this._maxHistory
55
+ });
56
+ await MetricHelper.createMetric(this._telemetry, {
57
+ id: "system_memory_total_bytes",
58
+ label: "Memory total",
59
+ type: MetricType.Gauge,
60
+ maxHistory: this._maxHistory
61
+ });
62
+ await MetricHelper.createMetric(this._telemetry, {
63
+ id: "system_memory_used_bytes",
64
+ label: "Memory used",
65
+ type: MetricType.Gauge,
66
+ maxHistory: this._maxHistory
67
+ });
68
+ await MetricHelper.createMetric(this._telemetry, {
69
+ id: "system_memory_free_bytes",
70
+ label: "Memory free",
71
+ type: MetricType.Gauge,
72
+ maxHistory: this._maxHistory
73
+ });
74
+ await MetricHelper.createMetric(this._telemetry, {
75
+ id: "system_memory_usage_percent",
76
+ label: "Memory usage",
77
+ type: MetricType.Gauge,
78
+ maxHistory: this._maxHistory
79
+ });
80
+ await MetricHelper.createMetric(this._telemetry, {
81
+ id: "system_uptime_seconds",
82
+ label: "System uptime",
83
+ type: MetricType.Gauge,
84
+ maxHistory: this._maxHistory
85
+ });
86
+ }
87
+ /**
88
+ * Read the current system metric values.
89
+ * @returns The current values for the system metrics.
90
+ */
91
+ async collect() {
92
+ const currCpuTimes = os.cpus().map(c => c.times);
93
+ const usages = currCpuTimes.map((curr, i) => {
94
+ const prev = this._prevCpuTimes[i];
95
+ const idle = curr.idle - prev.idle;
96
+ const total = curr.user -
97
+ prev.user +
98
+ curr.nice -
99
+ prev.nice +
100
+ curr.sys -
101
+ prev.sys +
102
+ curr.idle -
103
+ prev.idle +
104
+ curr.irq -
105
+ prev.irq;
106
+ const idleDivision = idle / total;
107
+ const idlePercent = 1 - idleDivision;
108
+ return total === 0 ? 0 : 100 * idlePercent;
109
+ });
110
+ this._prevCpuTimes = currCpuTimes;
111
+ const avgCpu = usages.reduce((a, b) => a + b, 0) / Math.max(1, usages.length);
112
+ const total = os.totalmem();
113
+ const free = os.freemem();
114
+ const used = total - free;
115
+ return [
116
+ { id: "system_cpu_usage_percent", value: Number(avgCpu.toFixed(2)) },
117
+ { id: "system_memory_total_bytes", value: total },
118
+ { id: "system_memory_used_bytes", value: used },
119
+ { id: "system_memory_free_bytes", value: free },
120
+ { id: "system_memory_usage_percent", value: Number(((100 * used) / total).toFixed(2)) },
121
+ { id: "system_uptime_seconds", value: Number(os.uptime().toFixed(1)) }
122
+ ];
123
+ }
124
+ }
125
+ //# sourceMappingURL=systemMetricsProducer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"systemMetricsProducer.js","sourceRoot":"","sources":["../../src/systemMetricsProducer.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAEhD,OAAO,EACN,YAAY,EACZ,UAAU,EAIV,MAAM,0BAA0B,CAAC;AAGlC;;GAEG;AACH,MAAM,OAAO,qBAAqB;IACjC;;OAEG;IACI,MAAM,CAAU,UAAU,2BAA2C;IAE5E;;;OAGG;IACc,UAAU,CAAsB;IAEjD;;;OAGG;IACc,WAAW,CAAS;IAErC;;;OAGG;IACK,aAAa,CAAwB;IAE7C;;;OAGG;IACH,YAAY,OAAkD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AG,WAAW,CAAC;QAC5C,CAAC,CAAC,CAAC;QACH,IAAI,CAAC,aAAa,GAAG,YAAY,CAAC;QAClC,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC;QAE9E,MAAM,KAAK,GAAG,EAAE,CAAC,QAAQ,EAAE,CAAC;QAC5B,MAAM,IAAI,GAAG,EAAE,CAAC,OAAO,EAAE,CAAC;QAC1B,MAAM,IAAI,GAAG,KAAK,GAAG,IAAI,CAAC;QAE1B,OAAO;YACN,EAAE,EAAE,EAAE,0BAA0B,EAAE,KAAK,EAAE,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,EAAE;YACpE,EAAE,EAAE,EAAE,2BAA2B,EAAE,KAAK,EAAE,KAAK,EAAE;YACjD,EAAE,EAAE,EAAE,0BAA0B,EAAE,KAAK,EAAE,IAAI,EAAE;YAC/C,EAAE,EAAE,EAAE,0BAA0B,EAAE,KAAK,EAAE,IAAI,EAAE;YAC/C,EAAE,EAAE,EAAE,6BAA6B,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC,CAAC,GAAG,GAAG,IAAI,CAAC,GAAG,KAAK,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,EAAE;YACvF,EAAE,EAAE,EAAE,uBAAuB,EAAE,KAAK,EAAE,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,EAAE;SACtE,CAAC;IACH,CAAC","sourcesContent":["// Copyright 2026 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport * as os from \"node:os\";\nimport { ComponentFactory } from \"@3sixty/core\";\nimport { nameof } from \"@3sixty/nameof\";\nimport {\n\tMetricHelper,\n\tMetricType,\n\ttype IMetricsProducer,\n\ttype ITelemetryComponent,\n\ttype ITelemetryMetricValueEntry\n} from \"@3sixty/telemetry-models\";\nimport type { ISystemMetricsProducerConstructorOptions } from \"./models/ISystemMetricsProducerConstructorOptions.js\";\n\n/**\n * Metrics producer that emits host-level OS metrics on every poll cycle.\n */\nexport class SystemMetricsProducer implements IMetricsProducer {\n\t/**\n\t * Runtime name for the class.\n\t */\n\tpublic static readonly CLASS_NAME: string = nameof<SystemMetricsProducer>();\n\n\t/**\n\t * Resolved telemetry component.\n\t * @internal\n\t */\n\tprivate readonly _telemetry: ITelemetryComponent;\n\n\t/**\n\t * Per-metric history cap.\n\t * @internal\n\t */\n\tprivate readonly _maxHistory: number;\n\n\t/**\n\t * Snapshot of CPU times from the previous tick - used to compute deltas.\n\t * @internal\n\t */\n\tprivate _prevCpuTimes: os.CpuInfo[\"times\"][];\n\n\t/**\n\t * Create a new instance of SystemMetricsProducer.\n\t * @param options The options for the producer.\n\t */\n\tconstructor(options?: ISystemMetricsProducerConstructorOptions) {\n\t\tthis._telemetry = ComponentFactory.get<ITelemetryComponent>(\n\t\t\toptions?.telemetryComponentType ?? \"telemetry\"\n\t\t);\n\t\tthis._maxHistory = options?.maxHistory ?? 1440;\n\t\tthis._prevCpuTimes = os.cpus().map(c => c.times);\n\t}\n\n\t/**\n\t * Returns the class name of the component.\n\t * @returns The class name of the component.\n\t */\n\tpublic className(): string {\n\t\treturn SystemMetricsProducer.CLASS_NAME;\n\t}\n\n\t/**\n\t * Register all system metrics with the telemetry component.\n\t * @returns A promise that resolves when all system metrics have been registered.\n\t */\n\tpublic async register(): Promise<void> {\n\t\tawait MetricHelper.createMetric(this._telemetry, {\n\t\t\tid: \"system_cpu_usage_percent\",\n\t\t\tlabel: \"CPU usage\",\n\t\t\ttype: MetricType.Gauge,\n\t\t\tmaxHistory: this._maxHistory\n\t\t});\n\t\tawait MetricHelper.createMetric(this._telemetry, {\n\t\t\tid: \"system_memory_total_bytes\",\n\t\t\tlabel: \"Memory total\",\n\t\t\ttype: MetricType.Gauge,\n\t\t\tmaxHistory: this._maxHistory\n\t\t});\n\t\tawait MetricHelper.createMetric(this._telemetry, {\n\t\t\tid: \"system_memory_used_bytes\",\n\t\t\tlabel: \"Memory used\",\n\t\t\ttype: MetricType.Gauge,\n\t\t\tmaxHistory: this._maxHistory\n\t\t});\n\t\tawait MetricHelper.createMetric(this._telemetry, {\n\t\t\tid: \"system_memory_free_bytes\",\n\t\t\tlabel: \"Memory free\",\n\t\t\ttype: MetricType.Gauge,\n\t\t\tmaxHistory: this._maxHistory\n\t\t});\n\t\tawait MetricHelper.createMetric(this._telemetry, {\n\t\t\tid: \"system_memory_usage_percent\",\n\t\t\tlabel: \"Memory usage\",\n\t\t\ttype: MetricType.Gauge,\n\t\t\tmaxHistory: this._maxHistory\n\t\t});\n\t\tawait MetricHelper.createMetric(this._telemetry, {\n\t\t\tid: \"system_uptime_seconds\",\n\t\t\tlabel: \"System uptime\",\n\t\t\ttype: MetricType.Gauge,\n\t\t\tmaxHistory: this._maxHistory\n\t\t});\n\t}\n\n\t/**\n\t * Read the current system metric values.\n\t * @returns The current values for the system metrics.\n\t */\n\tpublic async collect(): Promise<ITelemetryMetricValueEntry[]> {\n\t\tconst currCpuTimes = os.cpus().map(c => c.times);\n\t\tconst usages = currCpuTimes.map((curr, i) => {\n\t\t\tconst prev = this._prevCpuTimes[i];\n\t\t\tconst idle = curr.idle - prev.idle;\n\t\t\tconst total =\n\t\t\t\tcurr.user -\n\t\t\t\tprev.user +\n\t\t\t\tcurr.nice -\n\t\t\t\tprev.nice +\n\t\t\t\tcurr.sys -\n\t\t\t\tprev.sys +\n\t\t\t\tcurr.idle -\n\t\t\t\tprev.idle +\n\t\t\t\tcurr.irq -\n\t\t\t\tprev.irq;\n\t\t\tconst idleDivision = idle / total;\n\t\t\tconst idlePercent = 1 - idleDivision;\n\t\t\treturn total === 0 ? 0 : 100 * idlePercent;\n\t\t});\n\t\tthis._prevCpuTimes = currCpuTimes;\n\t\tconst avgCpu = usages.reduce((a, b) => a + b, 0) / Math.max(1, usages.length);\n\n\t\tconst total = os.totalmem();\n\t\tconst free = os.freemem();\n\t\tconst used = total - free;\n\n\t\treturn [\n\t\t\t{ id: \"system_cpu_usage_percent\", value: Number(avgCpu.toFixed(2)) },\n\t\t\t{ id: \"system_memory_total_bytes\", value: total },\n\t\t\t{ id: \"system_memory_used_bytes\", value: used },\n\t\t\t{ id: \"system_memory_free_bytes\", value: free },\n\t\t\t{ id: \"system_memory_usage_percent\", value: Number(((100 * used) / total).toFixed(2)) },\n\t\t\t{ id: \"system_uptime_seconds\", value: Number(os.uptime().toFixed(1)) }\n\t\t];\n\t}\n}\n"]}
@@ -0,0 +1,4 @@
1
+ export * from "./models/IProcessMetricsProducerConstructorOptions.js";
2
+ export * from "./models/ISystemMetricsProducerConstructorOptions.js";
3
+ export * from "./processMetricsProducer.js";
4
+ export * from "./systemMetricsProducer.js";
@@ -0,0 +1,15 @@
1
+ /**
2
+ * The options for the process metrics producer constructor.
3
+ */
4
+ export interface IProcessMetricsProducerConstructorOptions {
5
+ /**
6
+ * Type name of the telemetry component in `ComponentFactory`.
7
+ * @default telemetry
8
+ */
9
+ telemetryComponentType?: string;
10
+ /**
11
+ * Per-metric history cap.
12
+ * @default 1440
13
+ */
14
+ maxHistory?: number;
15
+ }
@@ -0,0 +1,15 @@
1
+ /**
2
+ * The options for the system metrics producer constructor.
3
+ */
4
+ export interface ISystemMetricsProducerConstructorOptions {
5
+ /**
6
+ * Type name of the telemetry component in `ComponentFactory`.
7
+ * @default telemetry
8
+ */
9
+ telemetryComponentType?: string;
10
+ /**
11
+ * Per-metric history cap.
12
+ * @default 1440
13
+ */
14
+ maxHistory?: number;
15
+ }
@@ -0,0 +1,31 @@
1
+ import { type IMetricsProducer, type ITelemetryMetricValueEntry } from "@3sixty/telemetry-models";
2
+ import type { IProcessMetricsProducerConstructorOptions } from "./models/IProcessMetricsProducerConstructorOptions.js";
3
+ /**
4
+ * Metrics producer that emits Node.js process metrics on every poll cycle.
5
+ */
6
+ export declare class ProcessMetricsProducer implements IMetricsProducer {
7
+ /**
8
+ * Runtime name for the class.
9
+ */
10
+ static readonly CLASS_NAME: string;
11
+ /**
12
+ * Create a new instance of ProcessMetricsProducer.
13
+ * @param options The options for the producer.
14
+ */
15
+ constructor(options?: IProcessMetricsProducerConstructorOptions);
16
+ /**
17
+ * Returns the class name of the component.
18
+ * @returns The class name of the component.
19
+ */
20
+ className(): string;
21
+ /**
22
+ * Register all process metrics with the telemetry component.
23
+ * @returns A promise that resolves when all process metrics have been registered.
24
+ */
25
+ register(): Promise<void>;
26
+ /**
27
+ * Read the current process metric values.
28
+ * @returns The current values for the process metrics.
29
+ */
30
+ collect(): Promise<ITelemetryMetricValueEntry[]>;
31
+ }
@@ -0,0 +1,31 @@
1
+ import { type IMetricsProducer, type ITelemetryMetricValueEntry } from "@3sixty/telemetry-models";
2
+ import type { ISystemMetricsProducerConstructorOptions } from "./models/ISystemMetricsProducerConstructorOptions.js";
3
+ /**
4
+ * Metrics producer that emits host-level OS metrics on every poll cycle.
5
+ */
6
+ export declare class SystemMetricsProducer implements IMetricsProducer {
7
+ /**
8
+ * Runtime name for the class.
9
+ */
10
+ static readonly CLASS_NAME: string;
11
+ /**
12
+ * Create a new instance of SystemMetricsProducer.
13
+ * @param options The options for the producer.
14
+ */
15
+ constructor(options?: ISystemMetricsProducerConstructorOptions);
16
+ /**
17
+ * Returns the class name of the component.
18
+ * @returns The class name of the component.
19
+ */
20
+ className(): string;
21
+ /**
22
+ * Register all system metrics with the telemetry component.
23
+ * @returns A promise that resolves when all system metrics have been registered.
24
+ */
25
+ register(): Promise<void>;
26
+ /**
27
+ * Read the current system metric values.
28
+ * @returns The current values for the system metrics.
29
+ */
30
+ collect(): Promise<ITelemetryMetricValueEntry[]>;
31
+ }
File without changes
@@ -0,0 +1,49 @@
1
+ # Telemetry Producers Examples
2
+
3
+ These examples show how to register runtime and host metrics with a telemetry component and emit values during a polling cycle. Each snippet uses a small in-memory component so you can see how metric registration and collection fit together.
4
+
5
+ ## ProcessMetricsProducer
6
+
7
+ ```typescript
8
+ import { ProcessMetricsProducer } from '@3sixty/telemetry-producers';
9
+
10
+ const producer = new ProcessMetricsProducer({
11
+ telemetryComponentType: 'telemetry',
12
+ maxHistory: 120
13
+ });
14
+
15
+ console.log(producer.className()); // ProcessMetricsProducer
16
+
17
+ await producer.register();
18
+
19
+ const registeredMetrics = await telemetryComponent.query(MetricType.Gauge);
20
+ console.log(registeredMetrics.entities.map(metric => metric.id)); // ["process_memory_rss_bytes", "process_memory_heap_used_bytes", "process_memory_heap_total_bytes", "process_uptime_seconds"]
21
+
22
+ await producer.collect();
23
+
24
+ const uptimeValues = await telemetryComponent.queryValues('process_uptime_seconds');
25
+ console.log(uptimeValues.entities.length); // 1
26
+ ```
27
+
28
+ ## SystemMetricsProducer
29
+
30
+ ```typescript
31
+ import { SystemMetricsProducer } from '@3sixty/telemetry-producers';
32
+
33
+ const producer = new SystemMetricsProducer({
34
+ telemetryComponentType: 'telemetry',
35
+ maxHistory: 288
36
+ });
37
+
38
+ console.log(producer.className()); // SystemMetricsProducer
39
+
40
+ await producer.register();
41
+
42
+ const registeredMetrics = await telemetryComponent.query(MetricType.Gauge);
43
+ console.log(registeredMetrics.entities.map(metric => metric.id)); // ["system_cpu_usage_percent", "system_memory_total_bytes", "system_memory_used_bytes", "system_memory_free_bytes", "system_memory_usage_percent", "system_uptime_seconds"]
44
+
45
+ await producer.collect();
46
+
47
+ const cpuValues = await telemetryComponent.queryValues('system_cpu_usage_percent');
48
+ console.log(cpuValues.entities.length); // 1
49
+ ```
@@ -0,0 +1,89 @@
1
+ # Class: ProcessMetricsProducer
2
+
3
+ Metrics producer that emits Node.js process metrics on every poll cycle.
4
+
5
+ ## Implements
6
+
7
+ - `IMetricsProducer`
8
+
9
+ ## Constructors
10
+
11
+ ### Constructor
12
+
13
+ > **new ProcessMetricsProducer**(`options?`): `ProcessMetricsProducer`
14
+
15
+ Create a new instance of ProcessMetricsProducer.
16
+
17
+ #### Parameters
18
+
19
+ ##### options?
20
+
21
+ [`IProcessMetricsProducerConstructorOptions`](../interfaces/IProcessMetricsProducerConstructorOptions.md)
22
+
23
+ The options for the producer.
24
+
25
+ #### Returns
26
+
27
+ `ProcessMetricsProducer`
28
+
29
+ ## Properties
30
+
31
+ ### CLASS\_NAME {#class_name}
32
+
33
+ > `readonly` `static` **CLASS\_NAME**: `string`
34
+
35
+ Runtime name for the class.
36
+
37
+ ## Methods
38
+
39
+ ### className() {#classname}
40
+
41
+ > **className**(): `string`
42
+
43
+ Returns the class name of the component.
44
+
45
+ #### Returns
46
+
47
+ `string`
48
+
49
+ The class name of the component.
50
+
51
+ #### Implementation of
52
+
53
+ `IMetricsProducer.className`
54
+
55
+ ***
56
+
57
+ ### register() {#register}
58
+
59
+ > **register**(): `Promise`\<`void`\>
60
+
61
+ Register all process metrics with the telemetry component.
62
+
63
+ #### Returns
64
+
65
+ `Promise`\<`void`\>
66
+
67
+ A promise that resolves when all process metrics have been registered.
68
+
69
+ #### Implementation of
70
+
71
+ `IMetricsProducer.register`
72
+
73
+ ***
74
+
75
+ ### collect() {#collect}
76
+
77
+ > **collect**(): `Promise`\<`ITelemetryMetricValueEntry`[]\>
78
+
79
+ Read the current process metric values.
80
+
81
+ #### Returns
82
+
83
+ `Promise`\<`ITelemetryMetricValueEntry`[]\>
84
+
85
+ The current values for the process metrics.
86
+
87
+ #### Implementation of
88
+
89
+ `IMetricsProducer.collect`
@@ -0,0 +1,89 @@
1
+ # Class: SystemMetricsProducer
2
+
3
+ Metrics producer that emits host-level OS metrics on every poll cycle.
4
+
5
+ ## Implements
6
+
7
+ - `IMetricsProducer`
8
+
9
+ ## Constructors
10
+
11
+ ### Constructor
12
+
13
+ > **new SystemMetricsProducer**(`options?`): `SystemMetricsProducer`
14
+
15
+ Create a new instance of SystemMetricsProducer.
16
+
17
+ #### Parameters
18
+
19
+ ##### options?
20
+
21
+ [`ISystemMetricsProducerConstructorOptions`](../interfaces/ISystemMetricsProducerConstructorOptions.md)
22
+
23
+ The options for the producer.
24
+
25
+ #### Returns
26
+
27
+ `SystemMetricsProducer`
28
+
29
+ ## Properties
30
+
31
+ ### CLASS\_NAME {#class_name}
32
+
33
+ > `readonly` `static` **CLASS\_NAME**: `string`
34
+
35
+ Runtime name for the class.
36
+
37
+ ## Methods
38
+
39
+ ### className() {#classname}
40
+
41
+ > **className**(): `string`
42
+
43
+ Returns the class name of the component.
44
+
45
+ #### Returns
46
+
47
+ `string`
48
+
49
+ The class name of the component.
50
+
51
+ #### Implementation of
52
+
53
+ `IMetricsProducer.className`
54
+
55
+ ***
56
+
57
+ ### register() {#register}
58
+
59
+ > **register**(): `Promise`\<`void`\>
60
+
61
+ Register all system metrics with the telemetry component.
62
+
63
+ #### Returns
64
+
65
+ `Promise`\<`void`\>
66
+
67
+ A promise that resolves when all system metrics have been registered.
68
+
69
+ #### Implementation of
70
+
71
+ `IMetricsProducer.register`
72
+
73
+ ***
74
+
75
+ ### collect() {#collect}
76
+
77
+ > **collect**(): `Promise`\<`ITelemetryMetricValueEntry`[]\>
78
+
79
+ Read the current system metric values.
80
+
81
+ #### Returns
82
+
83
+ `Promise`\<`ITelemetryMetricValueEntry`[]\>
84
+
85
+ The current values for the system metrics.
86
+
87
+ #### Implementation of
88
+
89
+ `IMetricsProducer.collect`
@@ -0,0 +1,11 @@
1
+ # @3sixty/telemetry-producers
2
+
3
+ ## Classes
4
+
5
+ - [ProcessMetricsProducer](classes/ProcessMetricsProducer.md)
6
+ - [SystemMetricsProducer](classes/SystemMetricsProducer.md)
7
+
8
+ ## Interfaces
9
+
10
+ - [IProcessMetricsProducerConstructorOptions](interfaces/IProcessMetricsProducerConstructorOptions.md)
11
+ - [ISystemMetricsProducerConstructorOptions](interfaces/ISystemMetricsProducerConstructorOptions.md)
@@ -0,0 +1,31 @@
1
+ # Interface: IProcessMetricsProducerConstructorOptions
2
+
3
+ The options for the process metrics producer constructor.
4
+
5
+ ## Properties
6
+
7
+ ### telemetryComponentType? {#telemetrycomponenttype}
8
+
9
+ > `optional` **telemetryComponentType?**: `string`
10
+
11
+ Type name of the telemetry component in `ComponentFactory`.
12
+
13
+ #### Default
14
+
15
+ ```ts
16
+ telemetry
17
+ ```
18
+
19
+ ***
20
+
21
+ ### maxHistory? {#maxhistory}
22
+
23
+ > `optional` **maxHistory?**: `number`
24
+
25
+ Per-metric history cap.
26
+
27
+ #### Default
28
+
29
+ ```ts
30
+ 1440
31
+ ```
@@ -0,0 +1,31 @@
1
+ # Interface: ISystemMetricsProducerConstructorOptions
2
+
3
+ The options for the system metrics producer constructor.
4
+
5
+ ## Properties
6
+
7
+ ### telemetryComponentType? {#telemetrycomponenttype}
8
+
9
+ > `optional` **telemetryComponentType?**: `string`
10
+
11
+ Type name of the telemetry component in `ComponentFactory`.
12
+
13
+ #### Default
14
+
15
+ ```ts
16
+ telemetry
17
+ ```
18
+
19
+ ***
20
+
21
+ ### maxHistory? {#maxhistory}
22
+
23
+ > `optional` **maxHistory?**: `number`
24
+
25
+ Per-metric history cap.
26
+
27
+ #### Default
28
+
29
+ ```ts
30
+ 1440
31
+ ```
@@ -0,0 +1 @@
1
+ {}
package/package.json CHANGED
@@ -1,6 +1,52 @@
1
1
  {
2
- "name": "@3sixty/telemetry-producers",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
2
+ "name": "@3sixty/telemetry-producers",
3
+ "version": "0.20.0-next.0",
4
+ "description": "Metrics producers for collecting Node.js process and system telemetry.",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "git+https://github.com/3sixtyglobal/telemetry.git",
8
+ "directory": "packages/telemetry-producers"
9
+ },
10
+ "author": "adrian.sanchez.sequeira@iota.org",
11
+ "license": "Apache-2.0",
12
+ "type": "module",
13
+ "engines": {
14
+ "node": ">=24.0.0"
15
+ },
16
+ "dependencies": {
17
+ "@3sixty/core": "next",
18
+ "@3sixty/nameof": "next",
19
+ "@3sixty/telemetry-models": "0.20.0-next.0"
20
+ },
21
+ "main": "./dist/es/index.js",
22
+ "types": "./dist/types/index.d.ts",
23
+ "exports": {
24
+ ".": {
25
+ "types": "./dist/types/index.d.ts",
26
+ "import": "./dist/es/index.js",
27
+ "default": "./dist/es/index.js"
28
+ },
29
+ "./locales/*.json": "./locales/*.json"
30
+ },
31
+ "files": [
32
+ "dist/es",
33
+ "dist/types",
34
+ "locales",
35
+ "docs"
36
+ ],
37
+ "keywords": [
38
+ "twin",
39
+ "trade",
40
+ "iota",
41
+ "framework",
42
+ "blockchain",
43
+ "telemetry",
44
+ "service",
45
+ "microservice",
46
+ "business-logic"
47
+ ],
48
+ "bugs": {
49
+ "url": "git+https://github.com/3sixtyglobal/telemetry/issues"
50
+ },
51
+ "homepage": "https://3sixty.global"
52
+ }