@xyo-network/prometheus-node-plugin 2.99.4 → 2.99.5
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/dist/neutral/Payload.d.cts +1 -1
- package/dist/neutral/Payload.d.mts +1 -1
- package/dist/neutral/Payload.d.ts +1 -1
- package/dist/neutral/Plugin.d.cts +2 -2
- package/dist/neutral/Plugin.d.mts +2 -2
- package/dist/neutral/Plugin.d.ts +2 -2
- package/dist/neutral/index.cjs +34 -19
- package/dist/neutral/index.cjs.map +1 -1
- package/dist/neutral/index.d.cts +4 -4
- package/dist/neutral/index.d.mts +4 -4
- package/dist/neutral/index.d.ts +4 -4
- package/dist/neutral/{index.js → index.mjs} +37 -20
- package/dist/neutral/{index.js.map → index.mjs.map} +1 -1
- package/dist/node/Payload.d.cts +1 -1
- package/dist/node/Payload.d.mts +1 -1
- package/dist/node/Payload.d.ts +1 -1
- package/dist/node/Plugin.d.cts +2 -2
- package/dist/node/Plugin.d.mts +2 -2
- package/dist/node/Plugin.d.ts +2 -2
- package/dist/node/index.cjs +40 -21
- package/dist/node/index.cjs.map +1 -1
- package/dist/node/index.d.cts +4 -4
- package/dist/node/index.d.mts +4 -4
- package/dist/node/index.d.ts +4 -4
- package/dist/node/index.mjs +93 -0
- package/dist/node/{index.js.map → index.mjs.map} +1 -1
- package/package.json +13 -13
- package/src/Payload.ts +1 -1
- package/src/Plugin.ts +2 -2
- package/src/Witness.ts +2 -2
- package/src/index.ts +4 -4
- package/dist/node/index.js +0 -72
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Payload } from '@xyo-network/payload-model';
|
|
2
2
|
import { Aggregator, MetricType } from 'prom-client';
|
|
3
|
-
import { PrometheusMetricValueSchema } from './Schema.
|
|
3
|
+
import { PrometheusMetricValueSchema } from './Schema.ts';
|
|
4
4
|
export type PrometheusMetricValuePayload = Payload<{
|
|
5
5
|
aggregator: Aggregator;
|
|
6
6
|
name: string;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Payload } from '@xyo-network/payload-model';
|
|
2
2
|
import { Aggregator, MetricType } from 'prom-client';
|
|
3
|
-
import { PrometheusMetricValueSchema } from './Schema.
|
|
3
|
+
import { PrometheusMetricValueSchema } from './Schema.ts';
|
|
4
4
|
export type PrometheusMetricValuePayload = Payload<{
|
|
5
5
|
aggregator: Aggregator;
|
|
6
6
|
name: string;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Payload } from '@xyo-network/payload-model';
|
|
2
2
|
import { Aggregator, MetricType } from 'prom-client';
|
|
3
|
-
import { PrometheusMetricValueSchema } from './Schema.
|
|
3
|
+
import { PrometheusMetricValueSchema } from './Schema.ts';
|
|
4
4
|
export type PrometheusMetricValuePayload = Payload<{
|
|
5
5
|
aggregator: Aggregator;
|
|
6
6
|
name: string;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { PrometheusNodeWitness } from './Witness.
|
|
1
|
+
import { PrometheusNodeWitness } from './Witness.ts';
|
|
2
2
|
export declare const PrometheusNodePlugin: () => import("@xyo-network/payloadset-plugin").PayloadSetWitnessPlugin<PrometheusNodeWitness<import("@xylabs/object").BaseParamsFields & {
|
|
3
3
|
account?: import("@xyo-network/account-model").AccountInstance | "random";
|
|
4
4
|
addToResolvers?: boolean;
|
|
@@ -8,7 +8,7 @@ export declare const PrometheusNodePlugin: () => import("@xyo-network/payloadset
|
|
|
8
8
|
schema: "network.xyo.prometheus.node.witness.config";
|
|
9
9
|
} & {
|
|
10
10
|
port?: number;
|
|
11
|
-
schema: import("./Witness.
|
|
11
|
+
schema: import("./Witness.ts").PrometheusNodeWitnessConfigSchema;
|
|
12
12
|
}, "schema"> & {
|
|
13
13
|
schema: "network.xyo.prometheus.node.witness.config";
|
|
14
14
|
}, "schema"> & {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { PrometheusNodeWitness } from './Witness.
|
|
1
|
+
import { PrometheusNodeWitness } from './Witness.ts';
|
|
2
2
|
export declare const PrometheusNodePlugin: () => import("@xyo-network/payloadset-plugin").PayloadSetWitnessPlugin<PrometheusNodeWitness<import("@xylabs/object").BaseParamsFields & {
|
|
3
3
|
account?: import("@xyo-network/account-model").AccountInstance | "random";
|
|
4
4
|
addToResolvers?: boolean;
|
|
@@ -8,7 +8,7 @@ export declare const PrometheusNodePlugin: () => import("@xyo-network/payloadset
|
|
|
8
8
|
schema: "network.xyo.prometheus.node.witness.config";
|
|
9
9
|
} & {
|
|
10
10
|
port?: number;
|
|
11
|
-
schema: import("./Witness.
|
|
11
|
+
schema: import("./Witness.ts").PrometheusNodeWitnessConfigSchema;
|
|
12
12
|
}, "schema"> & {
|
|
13
13
|
schema: "network.xyo.prometheus.node.witness.config";
|
|
14
14
|
}, "schema"> & {
|
package/dist/neutral/Plugin.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { PrometheusNodeWitness } from './Witness.
|
|
1
|
+
import { PrometheusNodeWitness } from './Witness.ts';
|
|
2
2
|
export declare const PrometheusNodePlugin: () => import("@xyo-network/payloadset-plugin").PayloadSetWitnessPlugin<PrometheusNodeWitness<import("@xylabs/object").BaseParamsFields & {
|
|
3
3
|
account?: import("@xyo-network/account-model").AccountInstance | "random";
|
|
4
4
|
addToResolvers?: boolean;
|
|
@@ -8,7 +8,7 @@ export declare const PrometheusNodePlugin: () => import("@xyo-network/payloadset
|
|
|
8
8
|
schema: "network.xyo.prometheus.node.witness.config";
|
|
9
9
|
} & {
|
|
10
10
|
port?: number;
|
|
11
|
-
schema: import("./Witness.
|
|
11
|
+
schema: import("./Witness.ts").PrometheusNodeWitnessConfigSchema;
|
|
12
12
|
}, "schema"> & {
|
|
13
13
|
schema: "network.xyo.prometheus.node.witness.config";
|
|
14
14
|
}, "schema"> & {
|
package/dist/neutral/index.cjs
CHANGED
|
@@ -3,6 +3,7 @@ var __defProp = Object.defineProperty;
|
|
|
3
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
6
7
|
var __export = (target, all) => {
|
|
7
8
|
for (var name in all)
|
|
8
9
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -44,7 +45,13 @@ var import_prom_client = require("prom-client");
|
|
|
44
45
|
var PrometheusNodeWitnessConfigSchema = "network.xyo.prometheus.node.witness.config";
|
|
45
46
|
(0, import_module_model.creatableModule)();
|
|
46
47
|
var PrometheusNodeWitness = class extends import_abstract_witness.AbstractWitness {
|
|
47
|
-
static
|
|
48
|
+
static {
|
|
49
|
+
__name(this, "PrometheusNodeWitness");
|
|
50
|
+
}
|
|
51
|
+
static configSchemas = [
|
|
52
|
+
...super.configSchemas,
|
|
53
|
+
PrometheusNodeWitnessConfigSchema
|
|
54
|
+
];
|
|
48
55
|
static defaultConfigSchema = PrometheusNodeWitnessConfigSchema;
|
|
49
56
|
_registry = new import_prom_client.Registry();
|
|
50
57
|
server;
|
|
@@ -55,7 +62,9 @@ var PrometheusNodeWitness = class extends import_abstract_witness.AbstractWitnes
|
|
|
55
62
|
return await this.generateMetricValues();
|
|
56
63
|
}
|
|
57
64
|
async startHandler() {
|
|
58
|
-
(0, import_prom_client.collectDefaultMetrics)({
|
|
65
|
+
(0, import_prom_client.collectDefaultMetrics)({
|
|
66
|
+
register: this._registry
|
|
67
|
+
});
|
|
59
68
|
if (this.config.port) {
|
|
60
69
|
this.server = (0, import_node_http.createServer)(async (_request, response) => {
|
|
61
70
|
response.writeHead(200);
|
|
@@ -70,25 +79,31 @@ var PrometheusNodeWitness = class extends import_abstract_witness.AbstractWitnes
|
|
|
70
79
|
return await super.stopHandler();
|
|
71
80
|
}
|
|
72
81
|
async generateMetricValues() {
|
|
73
|
-
return (0, import_lodash.compact)(
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
82
|
+
return (0, import_lodash.compact)((await this._registry.getMetricsAsJSON()).map((metric) => {
|
|
83
|
+
const values = metric.values;
|
|
84
|
+
if (values) {
|
|
85
|
+
return {
|
|
86
|
+
aggregator: metric.aggregator,
|
|
87
|
+
name: metric.name,
|
|
88
|
+
schema: PrometheusMetricValueSchema,
|
|
89
|
+
type: metric.type,
|
|
90
|
+
values
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
}));
|
|
81
94
|
}
|
|
82
95
|
};
|
|
83
96
|
|
|
84
97
|
// src/Plugin.ts
|
|
85
|
-
var PrometheusNodePlugin = () => (0, import_payloadset_plugin.createPayloadSetWitnessPlugin)(
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
98
|
+
var PrometheusNodePlugin = /* @__PURE__ */ __name(() => (0, import_payloadset_plugin.createPayloadSetWitnessPlugin)({
|
|
99
|
+
required: {
|
|
100
|
+
[PrometheusMetricValueSchema]: 1
|
|
101
|
+
},
|
|
102
|
+
schema: import_payload_model.PayloadSetSchema
|
|
103
|
+
}, {
|
|
104
|
+
witness: /* @__PURE__ */ __name(async (params) => {
|
|
105
|
+
const result = await PrometheusNodeWitness.create(params);
|
|
106
|
+
return result;
|
|
107
|
+
}, "witness")
|
|
108
|
+
}), "PrometheusNodePlugin");
|
|
94
109
|
//# sourceMappingURL=index.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/index.ts","../../src/Plugin.ts","../../src/Schema.ts","../../src/Witness.ts"],"sourcesContent":["export * from './Payload.
|
|
1
|
+
{"version":3,"sources":["../../src/index.ts","../../src/Plugin.ts","../../src/Schema.ts","../../src/Witness.ts"],"sourcesContent":["export * from './Payload.ts'\n// eslint-disable-next-line import/no-default-export\nexport { PrometheusNodePlugin as default, PrometheusNodePlugin } from './Plugin.ts'\nexport * from './Schema.ts'\nexport * from './Witness.ts'\n","import { PayloadSetSchema } from '@xyo-network/payload-model'\nimport { createPayloadSetWitnessPlugin } from '@xyo-network/payloadset-plugin'\n\nimport { PrometheusMetricValueSchema } from './Schema.ts'\nimport { PrometheusNodeWitness } from './Witness.ts'\n\nexport const PrometheusNodePlugin = () =>\n createPayloadSetWitnessPlugin<PrometheusNodeWitness>(\n { required: { [PrometheusMetricValueSchema]: 1 }, schema: PayloadSetSchema },\n {\n witness: async (params) => {\n const result = await PrometheusNodeWitness.create(params)\n return result\n },\n },\n )\n","export type PrometheusMetricValueSchema = 'network.xyo.prometheus.metric.value'\nexport const PrometheusMetricValueSchema: PrometheusMetricValueSchema = 'network.xyo.prometheus.metric.value'\n","import { createServer, Server } from 'node:http'\n\nimport { compact } from '@xylabs/lodash'\nimport { AbstractWitness } from '@xyo-network/abstract-witness'\nimport { AnyConfigSchema, creatableModule } from '@xyo-network/module-model'\nimport { Payload, Schema } from '@xyo-network/payload-model'\nimport { WitnessConfig, WitnessParams } from '@xyo-network/witness-model'\nimport { collectDefaultMetrics, Registry } from 'prom-client'\n\nimport { PrometheusMetricValuePayload } from './Payload.ts'\nimport { PrometheusMetricValueSchema } from './Schema.ts'\n\nexport type PrometheusNodeWitnessConfigSchema = 'network.xyo.prometheus.node.witness.config'\nexport const PrometheusNodeWitnessConfigSchema: PrometheusNodeWitnessConfigSchema = 'network.xyo.prometheus.node.witness.config'\n\nexport type PrometheusNodeWitnessConfig = WitnessConfig<{\n port?: number\n schema: PrometheusNodeWitnessConfigSchema\n}>\n\nexport type PrometheusNodeWitnessParams = WitnessParams<AnyConfigSchema<PrometheusNodeWitnessConfig>>\n\ncreatableModule()\nexport class PrometheusNodeWitness<TParams extends PrometheusNodeWitnessParams = PrometheusNodeWitnessParams> extends AbstractWitness<TParams> {\n static override readonly configSchemas: Schema[] = [...super.configSchemas, PrometheusNodeWitnessConfigSchema]\n static override readonly defaultConfigSchema: Schema = PrometheusNodeWitnessConfigSchema\n protected _registry = new Registry()\n protected server?: Server\n\n get registry(): Registry {\n return this._registry\n }\n\n protected override async observeHandler(_payloads?: Partial<Payload>[]): Promise<Payload[]> {\n return await this.generateMetricValues()\n }\n\n protected override async startHandler() {\n collectDefaultMetrics({ register: this._registry })\n if (this.config.port) {\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n this.server = createServer(async (_request, response) => {\n response.writeHead(200)\n\n response.end(await this._registry.metrics())\n })\n this.server.listen(this.config.port)\n }\n return await super.startHandler()\n }\n\n protected override async stopHandler(): Promise<boolean> {\n this.server?.close()\n return await super.stopHandler()\n }\n\n private async generateMetricValues(): Promise<PrometheusMetricValuePayload[]> {\n return compact(\n (await this._registry.getMetricsAsJSON()).map((metric) => {\n const values = metric.values\n if (values) {\n return { aggregator: metric.aggregator, name: metric.name, schema: PrometheusMetricValueSchema, type: metric.type, values }\n }\n }),\n )\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;;ACAA,2BAAiC;AACjC,+BAA8C;;;ACAvC,IAAMA,8BAA2D;;;ACDxE,uBAAqC;AAErC,oBAAwB;AACxB,8BAAgC;AAChC,0BAAiD;AAGjD,yBAAgD;AAMzC,IAAMC,oCAAuE;IASpFC,qCAAAA;AACO,IAAMC,wBAAN,cAA+GC,wCAAAA;EAvBtH,OAuBsHA;;;EACpH,OAAyBC,gBAA0B;OAAI,MAAMA;IAAeJ;;EAC5E,OAAyBK,sBAA8BL;EAC7CM,YAAY,IAAIC,4BAAAA;EAChBC;EAEV,IAAIC,WAAqB;AACvB,WAAO,KAAKH;EACd;EAEA,MAAyBI,eAAeC,WAAoD;AAC1F,WAAO,MAAM,KAAKC,qBAAoB;EACxC;EAEA,MAAyBC,eAAe;AACtCC,kDAAsB;MAAEC,UAAU,KAAKT;IAAU,CAAA;AACjD,QAAI,KAAKU,OAAOC,MAAM;AAEpB,WAAKT,aAASU,+BAAa,OAAOC,UAAUC,aAAAA;AAC1CA,iBAASC,UAAU,GAAA;AAEnBD,iBAASE,IAAI,MAAM,KAAKhB,UAAUiB,QAAO,CAAA;MAC3C,CAAA;AACA,WAAKf,OAAOgB,OAAO,KAAKR,OAAOC,IAAI;IACrC;AACA,WAAO,MAAM,MAAMJ,aAAAA;EACrB;EAEA,MAAyBY,cAAgC;AACvD,SAAKjB,QAAQkB,MAAAA;AACb,WAAO,MAAM,MAAMD,YAAAA;EACrB;EAEA,MAAcb,uBAAgE;AAC5E,eAAOe,wBACJ,MAAM,KAAKrB,UAAUsB,iBAAgB,GAAIC,IAAI,CAACC,WAAAA;AAC7C,YAAMC,SAASD,OAAOC;AACtB,UAAIA,QAAQ;AACV,eAAO;UAAEC,YAAYF,OAAOE;UAAYC,MAAMH,OAAOG;UAAMC,QAAQC;UAA6BC,MAAMN,OAAOM;UAAML;QAAO;MAC5H;IACF,CAAA,CAAA;EAEJ;AACF;;;AF5DO,IAAMM,uBAAuB,iCAClCC,wDACE;EAAEC,UAAU;IAAE,CAACC,2BAAAA,GAA8B;EAAE;EAAGC,QAAQC;AAAiB,GAC3E;EACEC,SAAS,8BAAOC,WAAAA;AACd,UAAMC,SAAS,MAAMC,sBAAsBC,OAAOH,MAAAA;AAClD,WAAOC;EACT,GAHS;AAIX,CAAA,GARgC;","names":["PrometheusMetricValueSchema","PrometheusNodeWitnessConfigSchema","creatableModule","PrometheusNodeWitness","AbstractWitness","configSchemas","defaultConfigSchema","_registry","Registry","server","registry","observeHandler","_payloads","generateMetricValues","startHandler","collectDefaultMetrics","register","config","port","createServer","_request","response","writeHead","end","metrics","listen","stopHandler","close","compact","getMetricsAsJSON","map","metric","values","aggregator","name","schema","PrometheusMetricValueSchema","type","PrometheusNodePlugin","createPayloadSetWitnessPlugin","required","PrometheusMetricValueSchema","schema","PayloadSetSchema","witness","params","result","PrometheusNodeWitness","create"]}
|
package/dist/neutral/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export * from './Payload.
|
|
2
|
-
export { PrometheusNodePlugin as default, PrometheusNodePlugin } from './Plugin.
|
|
3
|
-
export * from './Schema.
|
|
4
|
-
export * from './Witness.
|
|
1
|
+
export * from './Payload.ts';
|
|
2
|
+
export { PrometheusNodePlugin as default, PrometheusNodePlugin } from './Plugin.ts';
|
|
3
|
+
export * from './Schema.ts';
|
|
4
|
+
export * from './Witness.ts';
|
|
5
5
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/neutral/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export * from './Payload.
|
|
2
|
-
export { PrometheusNodePlugin as default, PrometheusNodePlugin } from './Plugin.
|
|
3
|
-
export * from './Schema.
|
|
4
|
-
export * from './Witness.
|
|
1
|
+
export * from './Payload.ts';
|
|
2
|
+
export { PrometheusNodePlugin as default, PrometheusNodePlugin } from './Plugin.ts';
|
|
3
|
+
export * from './Schema.ts';
|
|
4
|
+
export * from './Witness.ts';
|
|
5
5
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/neutral/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export * from './Payload.
|
|
2
|
-
export { PrometheusNodePlugin as default, PrometheusNodePlugin } from './Plugin.
|
|
3
|
-
export * from './Schema.
|
|
4
|
-
export * from './Witness.
|
|
1
|
+
export * from './Payload.ts';
|
|
2
|
+
export { PrometheusNodePlugin as default, PrometheusNodePlugin } from './Plugin.ts';
|
|
3
|
+
export * from './Schema.ts';
|
|
4
|
+
export * from './Witness.ts';
|
|
5
5
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
+
|
|
1
4
|
// src/Plugin.ts
|
|
2
5
|
import { PayloadSetSchema } from "@xyo-network/payload-model";
|
|
3
6
|
import { createPayloadSetWitnessPlugin } from "@xyo-network/payloadset-plugin";
|
|
@@ -14,7 +17,13 @@ import { collectDefaultMetrics, Registry } from "prom-client";
|
|
|
14
17
|
var PrometheusNodeWitnessConfigSchema = "network.xyo.prometheus.node.witness.config";
|
|
15
18
|
creatableModule();
|
|
16
19
|
var PrometheusNodeWitness = class extends AbstractWitness {
|
|
17
|
-
static
|
|
20
|
+
static {
|
|
21
|
+
__name(this, "PrometheusNodeWitness");
|
|
22
|
+
}
|
|
23
|
+
static configSchemas = [
|
|
24
|
+
...super.configSchemas,
|
|
25
|
+
PrometheusNodeWitnessConfigSchema
|
|
26
|
+
];
|
|
18
27
|
static defaultConfigSchema = PrometheusNodeWitnessConfigSchema;
|
|
19
28
|
_registry = new Registry();
|
|
20
29
|
server;
|
|
@@ -25,7 +34,9 @@ var PrometheusNodeWitness = class extends AbstractWitness {
|
|
|
25
34
|
return await this.generateMetricValues();
|
|
26
35
|
}
|
|
27
36
|
async startHandler() {
|
|
28
|
-
collectDefaultMetrics({
|
|
37
|
+
collectDefaultMetrics({
|
|
38
|
+
register: this._registry
|
|
39
|
+
});
|
|
29
40
|
if (this.config.port) {
|
|
30
41
|
this.server = createServer(async (_request, response) => {
|
|
31
42
|
response.writeHead(200);
|
|
@@ -40,27 +51,33 @@ var PrometheusNodeWitness = class extends AbstractWitness {
|
|
|
40
51
|
return await super.stopHandler();
|
|
41
52
|
}
|
|
42
53
|
async generateMetricValues() {
|
|
43
|
-
return compact(
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
54
|
+
return compact((await this._registry.getMetricsAsJSON()).map((metric) => {
|
|
55
|
+
const values = metric.values;
|
|
56
|
+
if (values) {
|
|
57
|
+
return {
|
|
58
|
+
aggregator: metric.aggregator,
|
|
59
|
+
name: metric.name,
|
|
60
|
+
schema: PrometheusMetricValueSchema,
|
|
61
|
+
type: metric.type,
|
|
62
|
+
values
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
}));
|
|
51
66
|
}
|
|
52
67
|
};
|
|
53
68
|
|
|
54
69
|
// src/Plugin.ts
|
|
55
|
-
var PrometheusNodePlugin = () => createPayloadSetWitnessPlugin(
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
70
|
+
var PrometheusNodePlugin = /* @__PURE__ */ __name(() => createPayloadSetWitnessPlugin({
|
|
71
|
+
required: {
|
|
72
|
+
[PrometheusMetricValueSchema]: 1
|
|
73
|
+
},
|
|
74
|
+
schema: PayloadSetSchema
|
|
75
|
+
}, {
|
|
76
|
+
witness: /* @__PURE__ */ __name(async (params) => {
|
|
77
|
+
const result = await PrometheusNodeWitness.create(params);
|
|
78
|
+
return result;
|
|
79
|
+
}, "witness")
|
|
80
|
+
}), "PrometheusNodePlugin");
|
|
64
81
|
export {
|
|
65
82
|
PrometheusMetricValueSchema,
|
|
66
83
|
PrometheusNodePlugin,
|
|
@@ -68,4 +85,4 @@ export {
|
|
|
68
85
|
PrometheusNodeWitnessConfigSchema,
|
|
69
86
|
PrometheusNodePlugin as default
|
|
70
87
|
};
|
|
71
|
-
//# sourceMappingURL=index.
|
|
88
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/Plugin.ts","../../src/Schema.ts","../../src/Witness.ts"],"sourcesContent":["import { PayloadSetSchema } from '@xyo-network/payload-model'\nimport { createPayloadSetWitnessPlugin } from '@xyo-network/payloadset-plugin'\n\nimport { PrometheusMetricValueSchema } from './Schema.
|
|
1
|
+
{"version":3,"sources":["../../src/Plugin.ts","../../src/Schema.ts","../../src/Witness.ts"],"sourcesContent":["import { PayloadSetSchema } from '@xyo-network/payload-model'\nimport { createPayloadSetWitnessPlugin } from '@xyo-network/payloadset-plugin'\n\nimport { PrometheusMetricValueSchema } from './Schema.ts'\nimport { PrometheusNodeWitness } from './Witness.ts'\n\nexport const PrometheusNodePlugin = () =>\n createPayloadSetWitnessPlugin<PrometheusNodeWitness>(\n { required: { [PrometheusMetricValueSchema]: 1 }, schema: PayloadSetSchema },\n {\n witness: async (params) => {\n const result = await PrometheusNodeWitness.create(params)\n return result\n },\n },\n )\n","export type PrometheusMetricValueSchema = 'network.xyo.prometheus.metric.value'\nexport const PrometheusMetricValueSchema: PrometheusMetricValueSchema = 'network.xyo.prometheus.metric.value'\n","import { createServer, Server } from 'node:http'\n\nimport { compact } from '@xylabs/lodash'\nimport { AbstractWitness } from '@xyo-network/abstract-witness'\nimport { AnyConfigSchema, creatableModule } from '@xyo-network/module-model'\nimport { Payload, Schema } from '@xyo-network/payload-model'\nimport { WitnessConfig, WitnessParams } from '@xyo-network/witness-model'\nimport { collectDefaultMetrics, Registry } from 'prom-client'\n\nimport { PrometheusMetricValuePayload } from './Payload.ts'\nimport { PrometheusMetricValueSchema } from './Schema.ts'\n\nexport type PrometheusNodeWitnessConfigSchema = 'network.xyo.prometheus.node.witness.config'\nexport const PrometheusNodeWitnessConfigSchema: PrometheusNodeWitnessConfigSchema = 'network.xyo.prometheus.node.witness.config'\n\nexport type PrometheusNodeWitnessConfig = WitnessConfig<{\n port?: number\n schema: PrometheusNodeWitnessConfigSchema\n}>\n\nexport type PrometheusNodeWitnessParams = WitnessParams<AnyConfigSchema<PrometheusNodeWitnessConfig>>\n\ncreatableModule()\nexport class PrometheusNodeWitness<TParams extends PrometheusNodeWitnessParams = PrometheusNodeWitnessParams> extends AbstractWitness<TParams> {\n static override readonly configSchemas: Schema[] = [...super.configSchemas, PrometheusNodeWitnessConfigSchema]\n static override readonly defaultConfigSchema: Schema = PrometheusNodeWitnessConfigSchema\n protected _registry = new Registry()\n protected server?: Server\n\n get registry(): Registry {\n return this._registry\n }\n\n protected override async observeHandler(_payloads?: Partial<Payload>[]): Promise<Payload[]> {\n return await this.generateMetricValues()\n }\n\n protected override async startHandler() {\n collectDefaultMetrics({ register: this._registry })\n if (this.config.port) {\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n this.server = createServer(async (_request, response) => {\n response.writeHead(200)\n\n response.end(await this._registry.metrics())\n })\n this.server.listen(this.config.port)\n }\n return await super.startHandler()\n }\n\n protected override async stopHandler(): Promise<boolean> {\n this.server?.close()\n return await super.stopHandler()\n }\n\n private async generateMetricValues(): Promise<PrometheusMetricValuePayload[]> {\n return compact(\n (await this._registry.getMetricsAsJSON()).map((metric) => {\n const values = metric.values\n if (values) {\n return { aggregator: metric.aggregator, name: metric.name, schema: PrometheusMetricValueSchema, type: metric.type, values }\n }\n }),\n )\n }\n}\n"],"mappings":";;;;AAAA,SAASA,wBAAwB;AACjC,SAASC,qCAAqC;;;ACAvC,IAAMC,8BAA2D;;;ACDxE,SAASC,oBAA4B;AAErC,SAASC,eAAe;AACxB,SAASC,uBAAuB;AAChC,SAA0BC,uBAAuB;AAGjD,SAASC,uBAAuBC,gBAAgB;AAMzC,IAAMC,oCAAuE;AASpFC,gBAAAA;AACO,IAAMC,wBAAN,cAA+GC,gBAAAA;EAvBtH,OAuBsHA;;;EACpH,OAAyBC,gBAA0B;OAAI,MAAMA;IAAeJ;;EAC5E,OAAyBK,sBAA8BL;EAC7CM,YAAY,IAAIC,SAAAA;EAChBC;EAEV,IAAIC,WAAqB;AACvB,WAAO,KAAKH;EACd;EAEA,MAAyBI,eAAeC,WAAoD;AAC1F,WAAO,MAAM,KAAKC,qBAAoB;EACxC;EAEA,MAAyBC,eAAe;AACtCC,0BAAsB;MAAEC,UAAU,KAAKT;IAAU,CAAA;AACjD,QAAI,KAAKU,OAAOC,MAAM;AAEpB,WAAKT,SAASU,aAAa,OAAOC,UAAUC,aAAAA;AAC1CA,iBAASC,UAAU,GAAA;AAEnBD,iBAASE,IAAI,MAAM,KAAKhB,UAAUiB,QAAO,CAAA;MAC3C,CAAA;AACA,WAAKf,OAAOgB,OAAO,KAAKR,OAAOC,IAAI;IACrC;AACA,WAAO,MAAM,MAAMJ,aAAAA;EACrB;EAEA,MAAyBY,cAAgC;AACvD,SAAKjB,QAAQkB,MAAAA;AACb,WAAO,MAAM,MAAMD,YAAAA;EACrB;EAEA,MAAcb,uBAAgE;AAC5E,WAAOe,SACJ,MAAM,KAAKrB,UAAUsB,iBAAgB,GAAIC,IAAI,CAACC,WAAAA;AAC7C,YAAMC,SAASD,OAAOC;AACtB,UAAIA,QAAQ;AACV,eAAO;UAAEC,YAAYF,OAAOE;UAAYC,MAAMH,OAAOG;UAAMC,QAAQC;UAA6BC,MAAMN,OAAOM;UAAML;QAAO;MAC5H;IACF,CAAA,CAAA;EAEJ;AACF;;;AF5DO,IAAMM,uBAAuB,6BAClCC,8BACE;EAAEC,UAAU;IAAE,CAACC,2BAAAA,GAA8B;EAAE;EAAGC,QAAQC;AAAiB,GAC3E;EACEC,SAAS,8BAAOC,WAAAA;AACd,UAAMC,SAAS,MAAMC,sBAAsBC,OAAOH,MAAAA;AAClD,WAAOC;EACT,GAHS;AAIX,CAAA,GARgC;","names":["PayloadSetSchema","createPayloadSetWitnessPlugin","PrometheusMetricValueSchema","createServer","compact","AbstractWitness","creatableModule","collectDefaultMetrics","Registry","PrometheusNodeWitnessConfigSchema","creatableModule","PrometheusNodeWitness","AbstractWitness","configSchemas","defaultConfigSchema","_registry","Registry","server","registry","observeHandler","_payloads","generateMetricValues","startHandler","collectDefaultMetrics","register","config","port","createServer","_request","response","writeHead","end","metrics","listen","stopHandler","close","compact","getMetricsAsJSON","map","metric","values","aggregator","name","schema","PrometheusMetricValueSchema","type","PrometheusNodePlugin","createPayloadSetWitnessPlugin","required","PrometheusMetricValueSchema","schema","PayloadSetSchema","witness","params","result","PrometheusNodeWitness","create"]}
|
package/dist/node/Payload.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Payload } from '@xyo-network/payload-model';
|
|
2
2
|
import { Aggregator, MetricType } from 'prom-client';
|
|
3
|
-
import { PrometheusMetricValueSchema } from './Schema.
|
|
3
|
+
import { PrometheusMetricValueSchema } from './Schema.ts';
|
|
4
4
|
export type PrometheusMetricValuePayload = Payload<{
|
|
5
5
|
aggregator: Aggregator;
|
|
6
6
|
name: string;
|
package/dist/node/Payload.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Payload } from '@xyo-network/payload-model';
|
|
2
2
|
import { Aggregator, MetricType } from 'prom-client';
|
|
3
|
-
import { PrometheusMetricValueSchema } from './Schema.
|
|
3
|
+
import { PrometheusMetricValueSchema } from './Schema.ts';
|
|
4
4
|
export type PrometheusMetricValuePayload = Payload<{
|
|
5
5
|
aggregator: Aggregator;
|
|
6
6
|
name: string;
|
package/dist/node/Payload.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Payload } from '@xyo-network/payload-model';
|
|
2
2
|
import { Aggregator, MetricType } from 'prom-client';
|
|
3
|
-
import { PrometheusMetricValueSchema } from './Schema.
|
|
3
|
+
import { PrometheusMetricValueSchema } from './Schema.ts';
|
|
4
4
|
export type PrometheusMetricValuePayload = Payload<{
|
|
5
5
|
aggregator: Aggregator;
|
|
6
6
|
name: string;
|
package/dist/node/Plugin.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { PrometheusNodeWitness } from './Witness.
|
|
1
|
+
import { PrometheusNodeWitness } from './Witness.ts';
|
|
2
2
|
export declare const PrometheusNodePlugin: () => import("@xyo-network/payloadset-plugin").PayloadSetWitnessPlugin<PrometheusNodeWitness<import("@xylabs/object").BaseParamsFields & {
|
|
3
3
|
account?: import("@xyo-network/account-model").AccountInstance | "random";
|
|
4
4
|
addToResolvers?: boolean;
|
|
@@ -8,7 +8,7 @@ export declare const PrometheusNodePlugin: () => import("@xyo-network/payloadset
|
|
|
8
8
|
schema: "network.xyo.prometheus.node.witness.config";
|
|
9
9
|
} & {
|
|
10
10
|
port?: number;
|
|
11
|
-
schema: import("./Witness.
|
|
11
|
+
schema: import("./Witness.ts").PrometheusNodeWitnessConfigSchema;
|
|
12
12
|
}, "schema"> & {
|
|
13
13
|
schema: "network.xyo.prometheus.node.witness.config";
|
|
14
14
|
}, "schema"> & {
|
package/dist/node/Plugin.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { PrometheusNodeWitness } from './Witness.
|
|
1
|
+
import { PrometheusNodeWitness } from './Witness.ts';
|
|
2
2
|
export declare const PrometheusNodePlugin: () => import("@xyo-network/payloadset-plugin").PayloadSetWitnessPlugin<PrometheusNodeWitness<import("@xylabs/object").BaseParamsFields & {
|
|
3
3
|
account?: import("@xyo-network/account-model").AccountInstance | "random";
|
|
4
4
|
addToResolvers?: boolean;
|
|
@@ -8,7 +8,7 @@ export declare const PrometheusNodePlugin: () => import("@xyo-network/payloadset
|
|
|
8
8
|
schema: "network.xyo.prometheus.node.witness.config";
|
|
9
9
|
} & {
|
|
10
10
|
port?: number;
|
|
11
|
-
schema: import("./Witness.
|
|
11
|
+
schema: import("./Witness.ts").PrometheusNodeWitnessConfigSchema;
|
|
12
12
|
}, "schema"> & {
|
|
13
13
|
schema: "network.xyo.prometheus.node.witness.config";
|
|
14
14
|
}, "schema"> & {
|
package/dist/node/Plugin.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { PrometheusNodeWitness } from './Witness.
|
|
1
|
+
import { PrometheusNodeWitness } from './Witness.ts';
|
|
2
2
|
export declare const PrometheusNodePlugin: () => import("@xyo-network/payloadset-plugin").PayloadSetWitnessPlugin<PrometheusNodeWitness<import("@xylabs/object").BaseParamsFields & {
|
|
3
3
|
account?: import("@xyo-network/account-model").AccountInstance | "random";
|
|
4
4
|
addToResolvers?: boolean;
|
|
@@ -8,7 +8,7 @@ export declare const PrometheusNodePlugin: () => import("@xyo-network/payloadset
|
|
|
8
8
|
schema: "network.xyo.prometheus.node.witness.config";
|
|
9
9
|
} & {
|
|
10
10
|
port?: number;
|
|
11
|
-
schema: import("./Witness.
|
|
11
|
+
schema: import("./Witness.ts").PrometheusNodeWitnessConfigSchema;
|
|
12
12
|
}, "schema"> & {
|
|
13
13
|
schema: "network.xyo.prometheus.node.witness.config";
|
|
14
14
|
}, "schema"> & {
|
package/dist/node/index.cjs
CHANGED
|
@@ -2,7 +2,11 @@
|
|
|
2
2
|
var __defProp = Object.defineProperty;
|
|
3
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
5
6
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __reflectGet = Reflect.get;
|
|
8
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
9
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
6
10
|
var __export = (target, all) => {
|
|
7
11
|
for (var name in all)
|
|
8
12
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -16,6 +20,8 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
16
20
|
return to;
|
|
17
21
|
};
|
|
18
22
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
23
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
24
|
+
var __superGet = (cls, obj, key) => __reflectGet(__getProtoOf(cls), key, obj);
|
|
19
25
|
|
|
20
26
|
// src/index.ts
|
|
21
27
|
var src_exports = {};
|
|
@@ -43,9 +49,7 @@ var import_module_model = require("@xyo-network/module-model");
|
|
|
43
49
|
var import_prom_client = require("prom-client");
|
|
44
50
|
var PrometheusNodeWitnessConfigSchema = "network.xyo.prometheus.node.witness.config";
|
|
45
51
|
(0, import_module_model.creatableModule)();
|
|
46
|
-
var
|
|
47
|
-
static configSchemas = [...super.configSchemas, PrometheusNodeWitnessConfigSchema];
|
|
48
|
-
static defaultConfigSchema = PrometheusNodeWitnessConfigSchema;
|
|
52
|
+
var _PrometheusNodeWitness = class _PrometheusNodeWitness extends import_abstract_witness.AbstractWitness {
|
|
49
53
|
_registry = new import_prom_client.Registry();
|
|
50
54
|
server;
|
|
51
55
|
get registry() {
|
|
@@ -55,7 +59,9 @@ var PrometheusNodeWitness = class extends import_abstract_witness.AbstractWitnes
|
|
|
55
59
|
return await this.generateMetricValues();
|
|
56
60
|
}
|
|
57
61
|
async startHandler() {
|
|
58
|
-
(0, import_prom_client.collectDefaultMetrics)({
|
|
62
|
+
(0, import_prom_client.collectDefaultMetrics)({
|
|
63
|
+
register: this._registry
|
|
64
|
+
});
|
|
59
65
|
if (this.config.port) {
|
|
60
66
|
this.server = (0, import_node_http.createServer)(async (_request, response) => {
|
|
61
67
|
response.writeHead(200);
|
|
@@ -71,27 +77,40 @@ var PrometheusNodeWitness = class extends import_abstract_witness.AbstractWitnes
|
|
|
71
77
|
return await super.stopHandler();
|
|
72
78
|
}
|
|
73
79
|
async generateMetricValues() {
|
|
74
|
-
return (0, import_lodash.compact)(
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
80
|
+
return (0, import_lodash.compact)((await this._registry.getMetricsAsJSON()).map((metric) => {
|
|
81
|
+
const values = metric.values;
|
|
82
|
+
if (values) {
|
|
83
|
+
return {
|
|
84
|
+
aggregator: metric.aggregator,
|
|
85
|
+
name: metric.name,
|
|
86
|
+
schema: PrometheusMetricValueSchema,
|
|
87
|
+
type: metric.type,
|
|
88
|
+
values
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
}));
|
|
82
92
|
}
|
|
83
93
|
};
|
|
94
|
+
__name(_PrometheusNodeWitness, "PrometheusNodeWitness");
|
|
95
|
+
__publicField(_PrometheusNodeWitness, "configSchemas", [
|
|
96
|
+
...__superGet(_PrometheusNodeWitness, _PrometheusNodeWitness, "configSchemas"),
|
|
97
|
+
PrometheusNodeWitnessConfigSchema
|
|
98
|
+
]);
|
|
99
|
+
__publicField(_PrometheusNodeWitness, "defaultConfigSchema", PrometheusNodeWitnessConfigSchema);
|
|
100
|
+
var PrometheusNodeWitness = _PrometheusNodeWitness;
|
|
84
101
|
|
|
85
102
|
// src/Plugin.ts
|
|
86
|
-
var PrometheusNodePlugin = () => (0, import_payloadset_plugin.createPayloadSetWitnessPlugin)(
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
103
|
+
var PrometheusNodePlugin = /* @__PURE__ */ __name(() => (0, import_payloadset_plugin.createPayloadSetWitnessPlugin)({
|
|
104
|
+
required: {
|
|
105
|
+
[PrometheusMetricValueSchema]: 1
|
|
106
|
+
},
|
|
107
|
+
schema: import_payload_model.PayloadSetSchema
|
|
108
|
+
}, {
|
|
109
|
+
witness: /* @__PURE__ */ __name(async (params) => {
|
|
110
|
+
const result = await PrometheusNodeWitness.create(params);
|
|
111
|
+
return result;
|
|
112
|
+
}, "witness")
|
|
113
|
+
}), "PrometheusNodePlugin");
|
|
95
114
|
// Annotate the CommonJS export names for ESM import in node:
|
|
96
115
|
0 && (module.exports = {
|
|
97
116
|
PrometheusMetricValueSchema,
|
package/dist/node/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/index.ts","../../src/Plugin.ts","../../src/Schema.ts","../../src/Witness.ts"],"sourcesContent":["export * from './Payload.
|
|
1
|
+
{"version":3,"sources":["../../src/index.ts","../../src/Plugin.ts","../../src/Schema.ts","../../src/Witness.ts"],"sourcesContent":["export * from './Payload.ts'\n// eslint-disable-next-line import/no-default-export\nexport { PrometheusNodePlugin as default, PrometheusNodePlugin } from './Plugin.ts'\nexport * from './Schema.ts'\nexport * from './Witness.ts'\n","import { PayloadSetSchema } from '@xyo-network/payload-model'\nimport { createPayloadSetWitnessPlugin } from '@xyo-network/payloadset-plugin'\n\nimport { PrometheusMetricValueSchema } from './Schema.ts'\nimport { PrometheusNodeWitness } from './Witness.ts'\n\nexport const PrometheusNodePlugin = () =>\n createPayloadSetWitnessPlugin<PrometheusNodeWitness>(\n { required: { [PrometheusMetricValueSchema]: 1 }, schema: PayloadSetSchema },\n {\n witness: async (params) => {\n const result = await PrometheusNodeWitness.create(params)\n return result\n },\n },\n )\n","export type PrometheusMetricValueSchema = 'network.xyo.prometheus.metric.value'\nexport const PrometheusMetricValueSchema: PrometheusMetricValueSchema = 'network.xyo.prometheus.metric.value'\n","import { createServer, Server } from 'node:http'\n\nimport { compact } from '@xylabs/lodash'\nimport { AbstractWitness } from '@xyo-network/abstract-witness'\nimport { AnyConfigSchema, creatableModule } from '@xyo-network/module-model'\nimport { Payload, Schema } from '@xyo-network/payload-model'\nimport { WitnessConfig, WitnessParams } from '@xyo-network/witness-model'\nimport { collectDefaultMetrics, Registry } from 'prom-client'\n\nimport { PrometheusMetricValuePayload } from './Payload.ts'\nimport { PrometheusMetricValueSchema } from './Schema.ts'\n\nexport type PrometheusNodeWitnessConfigSchema = 'network.xyo.prometheus.node.witness.config'\nexport const PrometheusNodeWitnessConfigSchema: PrometheusNodeWitnessConfigSchema = 'network.xyo.prometheus.node.witness.config'\n\nexport type PrometheusNodeWitnessConfig = WitnessConfig<{\n port?: number\n schema: PrometheusNodeWitnessConfigSchema\n}>\n\nexport type PrometheusNodeWitnessParams = WitnessParams<AnyConfigSchema<PrometheusNodeWitnessConfig>>\n\ncreatableModule()\nexport class PrometheusNodeWitness<TParams extends PrometheusNodeWitnessParams = PrometheusNodeWitnessParams> extends AbstractWitness<TParams> {\n static override readonly configSchemas: Schema[] = [...super.configSchemas, PrometheusNodeWitnessConfigSchema]\n static override readonly defaultConfigSchema: Schema = PrometheusNodeWitnessConfigSchema\n protected _registry = new Registry()\n protected server?: Server\n\n get registry(): Registry {\n return this._registry\n }\n\n protected override async observeHandler(_payloads?: Partial<Payload>[]): Promise<Payload[]> {\n return await this.generateMetricValues()\n }\n\n protected override async startHandler() {\n collectDefaultMetrics({ register: this._registry })\n if (this.config.port) {\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n this.server = createServer(async (_request, response) => {\n response.writeHead(200)\n\n response.end(await this._registry.metrics())\n })\n this.server.listen(this.config.port)\n }\n return await super.startHandler()\n }\n\n protected override async stopHandler(): Promise<boolean> {\n this.server?.close()\n return await super.stopHandler()\n }\n\n private async generateMetricValues(): Promise<PrometheusMetricValuePayload[]> {\n return compact(\n (await this._registry.getMetricsAsJSON()).map((metric) => {\n const values = metric.values\n if (values) {\n return { aggregator: metric.aggregator, name: metric.name, schema: PrometheusMetricValueSchema, type: metric.type, values }\n }\n }),\n )\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;;ACAA,2BAAiC;AACjC,+BAA8C;;;ACAvC,IAAMA,8BAA2D;;;ACDxE,uBAAqC;AAErC,oBAAwB;AACxB,8BAAgC;AAChC,0BAAiD;AAGjD,yBAAgD;AAMzC,IAAMC,oCAAuE;IASpFC,qCAAAA;AACO,IAAMC,yBAAN,MAAMA,+BAAyGC,wCAAAA;EAG1GC,YAAY,IAAIC,4BAAAA;EAChBC;EAEV,IAAIC,WAAqB;AACvB,WAAO,KAAKH;EACd;EAEA,MAAyBI,eAAeC,WAAoD;AAC1F,WAAO,MAAM,KAAKC,qBAAoB;EACxC;EAEA,MAAyBC,eAAe;AACtCC,kDAAsB;MAAEC,UAAU,KAAKT;IAAU,CAAA;AACjD,QAAI,KAAKU,OAAOC,MAAM;AAEpB,WAAKT,aAASU,+BAAa,OAAOC,UAAUC,aAAAA;AAC1CA,iBAASC,UAAU,GAAA;AAEnBD,iBAASE,IAAI,MAAM,KAAKhB,UAAUiB,QAAO,CAAA;MAC3C,CAAA;AACA,WAAKf,OAAOgB,OAAO,KAAKR,OAAOC,IAAI;IACrC;AACA,WAAO,MAAM,MAAMJ,aAAAA;EACrB;EAEA,MAAyBY,cAAgC;AAnD3D;AAoDI,eAAKjB,WAAL,mBAAakB;AACb,WAAO,MAAM,MAAMD,YAAAA;EACrB;EAEA,MAAcb,uBAAgE;AAC5E,eAAOe,wBACJ,MAAM,KAAKrB,UAAUsB,iBAAgB,GAAIC,IAAI,CAACC,WAAAA;AAC7C,YAAMC,SAASD,OAAOC;AACtB,UAAIA,QAAQ;AACV,eAAO;UAAEC,YAAYF,OAAOE;UAAYC,MAAMH,OAAOG;UAAMC,QAAQC;UAA6BC,MAAMN,OAAOM;UAAML;QAAO;MAC5H;IACF,CAAA,CAAA;EAEJ;AACF;AA3CsH1B;AACpH,cADWD,wBACciC,iBAA0B;KAAI,2DAAMA;EAAenC;;AAC5E,cAFWE,wBAEckC,uBAA8BpC;AAFlD,IAAME,wBAAN;;;AFjBA,IAAMmC,uBAAuB,iCAClCC,wDACE;EAAEC,UAAU;IAAE,CAACC,2BAAAA,GAA8B;EAAE;EAAGC,QAAQC;AAAiB,GAC3E;EACEC,SAAS,8BAAOC,WAAAA;AACd,UAAMC,SAAS,MAAMC,sBAAsBC,OAAOH,MAAAA;AAClD,WAAOC;EACT,GAHS;AAIX,CAAA,GARgC;","names":["PrometheusMetricValueSchema","PrometheusNodeWitnessConfigSchema","creatableModule","PrometheusNodeWitness","AbstractWitness","_registry","Registry","server","registry","observeHandler","_payloads","generateMetricValues","startHandler","collectDefaultMetrics","register","config","port","createServer","_request","response","writeHead","end","metrics","listen","stopHandler","close","compact","getMetricsAsJSON","map","metric","values","aggregator","name","schema","PrometheusMetricValueSchema","type","configSchemas","defaultConfigSchema","PrometheusNodePlugin","createPayloadSetWitnessPlugin","required","PrometheusMetricValueSchema","schema","PayloadSetSchema","witness","params","result","PrometheusNodeWitness","create"]}
|
package/dist/node/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export * from './Payload.
|
|
2
|
-
export { PrometheusNodePlugin as default, PrometheusNodePlugin } from './Plugin.
|
|
3
|
-
export * from './Schema.
|
|
4
|
-
export * from './Witness.
|
|
1
|
+
export * from './Payload.ts';
|
|
2
|
+
export { PrometheusNodePlugin as default, PrometheusNodePlugin } from './Plugin.ts';
|
|
3
|
+
export * from './Schema.ts';
|
|
4
|
+
export * from './Witness.ts';
|
|
5
5
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/node/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export * from './Payload.
|
|
2
|
-
export { PrometheusNodePlugin as default, PrometheusNodePlugin } from './Plugin.
|
|
3
|
-
export * from './Schema.
|
|
4
|
-
export * from './Witness.
|
|
1
|
+
export * from './Payload.ts';
|
|
2
|
+
export { PrometheusNodePlugin as default, PrometheusNodePlugin } from './Plugin.ts';
|
|
3
|
+
export * from './Schema.ts';
|
|
4
|
+
export * from './Witness.ts';
|
|
5
5
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/node/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export * from './Payload.
|
|
2
|
-
export { PrometheusNodePlugin as default, PrometheusNodePlugin } from './Plugin.
|
|
3
|
-
export * from './Schema.
|
|
4
|
-
export * from './Witness.
|
|
1
|
+
export * from './Payload.ts';
|
|
2
|
+
export { PrometheusNodePlugin as default, PrometheusNodePlugin } from './Plugin.ts';
|
|
3
|
+
export * from './Schema.ts';
|
|
4
|
+
export * from './Witness.ts';
|
|
5
5
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
3
|
+
var __reflectGet = Reflect.get;
|
|
4
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
5
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
6
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
7
|
+
var __superGet = (cls, obj, key) => __reflectGet(__getProtoOf(cls), key, obj);
|
|
8
|
+
|
|
9
|
+
// src/Plugin.ts
|
|
10
|
+
import { PayloadSetSchema } from "@xyo-network/payload-model";
|
|
11
|
+
import { createPayloadSetWitnessPlugin } from "@xyo-network/payloadset-plugin";
|
|
12
|
+
|
|
13
|
+
// src/Schema.ts
|
|
14
|
+
var PrometheusMetricValueSchema = "network.xyo.prometheus.metric.value";
|
|
15
|
+
|
|
16
|
+
// src/Witness.ts
|
|
17
|
+
import { createServer } from "node:http";
|
|
18
|
+
import { compact } from "@xylabs/lodash";
|
|
19
|
+
import { AbstractWitness } from "@xyo-network/abstract-witness";
|
|
20
|
+
import { creatableModule } from "@xyo-network/module-model";
|
|
21
|
+
import { collectDefaultMetrics, Registry } from "prom-client";
|
|
22
|
+
var PrometheusNodeWitnessConfigSchema = "network.xyo.prometheus.node.witness.config";
|
|
23
|
+
creatableModule();
|
|
24
|
+
var _PrometheusNodeWitness = class _PrometheusNodeWitness extends AbstractWitness {
|
|
25
|
+
_registry = new Registry();
|
|
26
|
+
server;
|
|
27
|
+
get registry() {
|
|
28
|
+
return this._registry;
|
|
29
|
+
}
|
|
30
|
+
async observeHandler(_payloads) {
|
|
31
|
+
return await this.generateMetricValues();
|
|
32
|
+
}
|
|
33
|
+
async startHandler() {
|
|
34
|
+
collectDefaultMetrics({
|
|
35
|
+
register: this._registry
|
|
36
|
+
});
|
|
37
|
+
if (this.config.port) {
|
|
38
|
+
this.server = createServer(async (_request, response) => {
|
|
39
|
+
response.writeHead(200);
|
|
40
|
+
response.end(await this._registry.metrics());
|
|
41
|
+
});
|
|
42
|
+
this.server.listen(this.config.port);
|
|
43
|
+
}
|
|
44
|
+
return await super.startHandler();
|
|
45
|
+
}
|
|
46
|
+
async stopHandler() {
|
|
47
|
+
var _a;
|
|
48
|
+
(_a = this.server) == null ? void 0 : _a.close();
|
|
49
|
+
return await super.stopHandler();
|
|
50
|
+
}
|
|
51
|
+
async generateMetricValues() {
|
|
52
|
+
return compact((await this._registry.getMetricsAsJSON()).map((metric) => {
|
|
53
|
+
const values = metric.values;
|
|
54
|
+
if (values) {
|
|
55
|
+
return {
|
|
56
|
+
aggregator: metric.aggregator,
|
|
57
|
+
name: metric.name,
|
|
58
|
+
schema: PrometheusMetricValueSchema,
|
|
59
|
+
type: metric.type,
|
|
60
|
+
values
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
}));
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
__name(_PrometheusNodeWitness, "PrometheusNodeWitness");
|
|
67
|
+
__publicField(_PrometheusNodeWitness, "configSchemas", [
|
|
68
|
+
...__superGet(_PrometheusNodeWitness, _PrometheusNodeWitness, "configSchemas"),
|
|
69
|
+
PrometheusNodeWitnessConfigSchema
|
|
70
|
+
]);
|
|
71
|
+
__publicField(_PrometheusNodeWitness, "defaultConfigSchema", PrometheusNodeWitnessConfigSchema);
|
|
72
|
+
var PrometheusNodeWitness = _PrometheusNodeWitness;
|
|
73
|
+
|
|
74
|
+
// src/Plugin.ts
|
|
75
|
+
var PrometheusNodePlugin = /* @__PURE__ */ __name(() => createPayloadSetWitnessPlugin({
|
|
76
|
+
required: {
|
|
77
|
+
[PrometheusMetricValueSchema]: 1
|
|
78
|
+
},
|
|
79
|
+
schema: PayloadSetSchema
|
|
80
|
+
}, {
|
|
81
|
+
witness: /* @__PURE__ */ __name(async (params) => {
|
|
82
|
+
const result = await PrometheusNodeWitness.create(params);
|
|
83
|
+
return result;
|
|
84
|
+
}, "witness")
|
|
85
|
+
}), "PrometheusNodePlugin");
|
|
86
|
+
export {
|
|
87
|
+
PrometheusMetricValueSchema,
|
|
88
|
+
PrometheusNodePlugin,
|
|
89
|
+
PrometheusNodeWitness,
|
|
90
|
+
PrometheusNodeWitnessConfigSchema,
|
|
91
|
+
PrometheusNodePlugin as default
|
|
92
|
+
};
|
|
93
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/Plugin.ts","../../src/Schema.ts","../../src/Witness.ts"],"sourcesContent":["import { PayloadSetSchema } from '@xyo-network/payload-model'\nimport { createPayloadSetWitnessPlugin } from '@xyo-network/payloadset-plugin'\n\nimport { PrometheusMetricValueSchema } from './Schema.
|
|
1
|
+
{"version":3,"sources":["../../src/Plugin.ts","../../src/Schema.ts","../../src/Witness.ts"],"sourcesContent":["import { PayloadSetSchema } from '@xyo-network/payload-model'\nimport { createPayloadSetWitnessPlugin } from '@xyo-network/payloadset-plugin'\n\nimport { PrometheusMetricValueSchema } from './Schema.ts'\nimport { PrometheusNodeWitness } from './Witness.ts'\n\nexport const PrometheusNodePlugin = () =>\n createPayloadSetWitnessPlugin<PrometheusNodeWitness>(\n { required: { [PrometheusMetricValueSchema]: 1 }, schema: PayloadSetSchema },\n {\n witness: async (params) => {\n const result = await PrometheusNodeWitness.create(params)\n return result\n },\n },\n )\n","export type PrometheusMetricValueSchema = 'network.xyo.prometheus.metric.value'\nexport const PrometheusMetricValueSchema: PrometheusMetricValueSchema = 'network.xyo.prometheus.metric.value'\n","import { createServer, Server } from 'node:http'\n\nimport { compact } from '@xylabs/lodash'\nimport { AbstractWitness } from '@xyo-network/abstract-witness'\nimport { AnyConfigSchema, creatableModule } from '@xyo-network/module-model'\nimport { Payload, Schema } from '@xyo-network/payload-model'\nimport { WitnessConfig, WitnessParams } from '@xyo-network/witness-model'\nimport { collectDefaultMetrics, Registry } from 'prom-client'\n\nimport { PrometheusMetricValuePayload } from './Payload.ts'\nimport { PrometheusMetricValueSchema } from './Schema.ts'\n\nexport type PrometheusNodeWitnessConfigSchema = 'network.xyo.prometheus.node.witness.config'\nexport const PrometheusNodeWitnessConfigSchema: PrometheusNodeWitnessConfigSchema = 'network.xyo.prometheus.node.witness.config'\n\nexport type PrometheusNodeWitnessConfig = WitnessConfig<{\n port?: number\n schema: PrometheusNodeWitnessConfigSchema\n}>\n\nexport type PrometheusNodeWitnessParams = WitnessParams<AnyConfigSchema<PrometheusNodeWitnessConfig>>\n\ncreatableModule()\nexport class PrometheusNodeWitness<TParams extends PrometheusNodeWitnessParams = PrometheusNodeWitnessParams> extends AbstractWitness<TParams> {\n static override readonly configSchemas: Schema[] = [...super.configSchemas, PrometheusNodeWitnessConfigSchema]\n static override readonly defaultConfigSchema: Schema = PrometheusNodeWitnessConfigSchema\n protected _registry = new Registry()\n protected server?: Server\n\n get registry(): Registry {\n return this._registry\n }\n\n protected override async observeHandler(_payloads?: Partial<Payload>[]): Promise<Payload[]> {\n return await this.generateMetricValues()\n }\n\n protected override async startHandler() {\n collectDefaultMetrics({ register: this._registry })\n if (this.config.port) {\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n this.server = createServer(async (_request, response) => {\n response.writeHead(200)\n\n response.end(await this._registry.metrics())\n })\n this.server.listen(this.config.port)\n }\n return await super.startHandler()\n }\n\n protected override async stopHandler(): Promise<boolean> {\n this.server?.close()\n return await super.stopHandler()\n }\n\n private async generateMetricValues(): Promise<PrometheusMetricValuePayload[]> {\n return compact(\n (await this._registry.getMetricsAsJSON()).map((metric) => {\n const values = metric.values\n if (values) {\n return { aggregator: metric.aggregator, name: metric.name, schema: PrometheusMetricValueSchema, type: metric.type, values }\n }\n }),\n )\n }\n}\n"],"mappings":";;;;;;;;;AAAA,SAASA,wBAAwB;AACjC,SAASC,qCAAqC;;;ACAvC,IAAMC,8BAA2D;;;ACDxE,SAASC,oBAA4B;AAErC,SAASC,eAAe;AACxB,SAASC,uBAAuB;AAChC,SAA0BC,uBAAuB;AAGjD,SAASC,uBAAuBC,gBAAgB;AAMzC,IAAMC,oCAAuE;AASpFC,gBAAAA;AACO,IAAMC,yBAAN,MAAMA,+BAAyGC,gBAAAA;EAG1GC,YAAY,IAAIC,SAAAA;EAChBC;EAEV,IAAIC,WAAqB;AACvB,WAAO,KAAKH;EACd;EAEA,MAAyBI,eAAeC,WAAoD;AAC1F,WAAO,MAAM,KAAKC,qBAAoB;EACxC;EAEA,MAAyBC,eAAe;AACtCC,0BAAsB;MAAEC,UAAU,KAAKT;IAAU,CAAA;AACjD,QAAI,KAAKU,OAAOC,MAAM;AAEpB,WAAKT,SAASU,aAAa,OAAOC,UAAUC,aAAAA;AAC1CA,iBAASC,UAAU,GAAA;AAEnBD,iBAASE,IAAI,MAAM,KAAKhB,UAAUiB,QAAO,CAAA;MAC3C,CAAA;AACA,WAAKf,OAAOgB,OAAO,KAAKR,OAAOC,IAAI;IACrC;AACA,WAAO,MAAM,MAAMJ,aAAAA;EACrB;EAEA,MAAyBY,cAAgC;AAnD3D;AAoDI,eAAKjB,WAAL,mBAAakB;AACb,WAAO,MAAM,MAAMD,YAAAA;EACrB;EAEA,MAAcb,uBAAgE;AAC5E,WAAOe,SACJ,MAAM,KAAKrB,UAAUsB,iBAAgB,GAAIC,IAAI,CAACC,WAAAA;AAC7C,YAAMC,SAASD,OAAOC;AACtB,UAAIA,QAAQ;AACV,eAAO;UAAEC,YAAYF,OAAOE;UAAYC,MAAMH,OAAOG;UAAMC,QAAQC;UAA6BC,MAAMN,OAAOM;UAAML;QAAO;MAC5H;IACF,CAAA,CAAA;EAEJ;AACF;AA3CsH1B;AACpH,cADWD,wBACciC,iBAA0B;KAAI,2DAAMA;EAAenC;;AAC5E,cAFWE,wBAEckC,uBAA8BpC;AAFlD,IAAME,wBAAN;;;AFjBA,IAAMmC,uBAAuB,6BAClCC,8BACE;EAAEC,UAAU;IAAE,CAACC,2BAAAA,GAA8B;EAAE;EAAGC,QAAQC;AAAiB,GAC3E;EACEC,SAAS,8BAAOC,WAAAA;AACd,UAAMC,SAAS,MAAMC,sBAAsBC,OAAOH,MAAAA;AAClD,WAAOC;EACT,GAHS;AAIX,CAAA,GARgC;","names":["PayloadSetSchema","createPayloadSetWitnessPlugin","PrometheusMetricValueSchema","createServer","compact","AbstractWitness","creatableModule","collectDefaultMetrics","Registry","PrometheusNodeWitnessConfigSchema","creatableModule","PrometheusNodeWitness","AbstractWitness","_registry","Registry","server","registry","observeHandler","_payloads","generateMetricValues","startHandler","collectDefaultMetrics","register","config","port","createServer","_request","response","writeHead","end","metrics","listen","stopHandler","close","compact","getMetricsAsJSON","map","metric","values","aggregator","name","schema","PrometheusMetricValueSchema","type","configSchemas","defaultConfigSchema","PrometheusNodePlugin","createPayloadSetWitnessPlugin","required","PrometheusMetricValueSchema","schema","PayloadSetSchema","witness","params","result","PrometheusNodeWitness","create"]}
|
package/package.json
CHANGED
|
@@ -10,19 +10,19 @@
|
|
|
10
10
|
"url": "https://github.com/XYOracleNetwork/plugins/issues"
|
|
11
11
|
},
|
|
12
12
|
"dependencies": {
|
|
13
|
-
"@xylabs/lodash": "^3.6.
|
|
14
|
-
"@xyo-network/abstract-witness": "^2.
|
|
15
|
-
"@xyo-network/module-model": "^2.
|
|
16
|
-
"@xyo-network/payload-model": "^2.
|
|
17
|
-
"@xyo-network/payloadset-plugin": "^2.
|
|
18
|
-
"@xyo-network/witness-model": "^2.
|
|
13
|
+
"@xylabs/lodash": "^3.6.8",
|
|
14
|
+
"@xyo-network/abstract-witness": "^2.111.2",
|
|
15
|
+
"@xyo-network/module-model": "^2.111.2",
|
|
16
|
+
"@xyo-network/payload-model": "^2.111.2",
|
|
17
|
+
"@xyo-network/payloadset-plugin": "^2.111.2",
|
|
18
|
+
"@xyo-network/witness-model": "^2.111.2",
|
|
19
19
|
"prom-client": "^15.1.3"
|
|
20
20
|
},
|
|
21
21
|
"devDependencies": {
|
|
22
|
-
"@xylabs/ts-scripts-yarn3": "^3.
|
|
23
|
-
"@xylabs/tsconfig": "^3.
|
|
24
|
-
"@xyo-network/payload-wrapper": "^2.
|
|
25
|
-
"typescript": "^5.5.
|
|
22
|
+
"@xylabs/ts-scripts-yarn3": "^3.15.13",
|
|
23
|
+
"@xylabs/tsconfig": "^3.15.13",
|
|
24
|
+
"@xyo-network/payload-wrapper": "^2.111.2",
|
|
25
|
+
"typescript": "^5.5.4"
|
|
26
26
|
},
|
|
27
27
|
"description": "Typescript/Javascript Plugins for XYO Platform",
|
|
28
28
|
"exports": {
|
|
@@ -34,14 +34,14 @@
|
|
|
34
34
|
},
|
|
35
35
|
"import": {
|
|
36
36
|
"types": "./dist/node/index.d.mts",
|
|
37
|
-
"default": "./dist/node/index.
|
|
37
|
+
"default": "./dist/node/index.mjs"
|
|
38
38
|
}
|
|
39
39
|
}
|
|
40
40
|
},
|
|
41
41
|
"./package.json": "./package.json"
|
|
42
42
|
},
|
|
43
43
|
"main": "dist/node/index.cjs",
|
|
44
|
-
"module": "dist/node/index.
|
|
44
|
+
"module": "dist/node/index.mjs",
|
|
45
45
|
"types": "dist/node/index.d.ts",
|
|
46
46
|
"homepage": "https://xyo.network",
|
|
47
47
|
"license": "LGPL-3.0-only",
|
|
@@ -53,6 +53,6 @@
|
|
|
53
53
|
"url": "https://github.com/XYOracleNetwork/plugins.git"
|
|
54
54
|
},
|
|
55
55
|
"sideEffects": false,
|
|
56
|
-
"version": "2.99.
|
|
56
|
+
"version": "2.99.5",
|
|
57
57
|
"type": "module"
|
|
58
58
|
}
|
package/src/Payload.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Payload } from '@xyo-network/payload-model'
|
|
2
2
|
import { Aggregator, MetricType } from 'prom-client'
|
|
3
3
|
|
|
4
|
-
import { PrometheusMetricValueSchema } from './Schema.
|
|
4
|
+
import { PrometheusMetricValueSchema } from './Schema.ts'
|
|
5
5
|
|
|
6
6
|
export type PrometheusMetricValuePayload = Payload<
|
|
7
7
|
{
|
package/src/Plugin.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { PayloadSetSchema } from '@xyo-network/payload-model'
|
|
2
2
|
import { createPayloadSetWitnessPlugin } from '@xyo-network/payloadset-plugin'
|
|
3
3
|
|
|
4
|
-
import { PrometheusMetricValueSchema } from './Schema.
|
|
5
|
-
import { PrometheusNodeWitness } from './Witness.
|
|
4
|
+
import { PrometheusMetricValueSchema } from './Schema.ts'
|
|
5
|
+
import { PrometheusNodeWitness } from './Witness.ts'
|
|
6
6
|
|
|
7
7
|
export const PrometheusNodePlugin = () =>
|
|
8
8
|
createPayloadSetWitnessPlugin<PrometheusNodeWitness>(
|
package/src/Witness.ts
CHANGED
|
@@ -7,8 +7,8 @@ import { Payload, Schema } from '@xyo-network/payload-model'
|
|
|
7
7
|
import { WitnessConfig, WitnessParams } from '@xyo-network/witness-model'
|
|
8
8
|
import { collectDefaultMetrics, Registry } from 'prom-client'
|
|
9
9
|
|
|
10
|
-
import { PrometheusMetricValuePayload } from './Payload.
|
|
11
|
-
import { PrometheusMetricValueSchema } from './Schema.
|
|
10
|
+
import { PrometheusMetricValuePayload } from './Payload.ts'
|
|
11
|
+
import { PrometheusMetricValueSchema } from './Schema.ts'
|
|
12
12
|
|
|
13
13
|
export type PrometheusNodeWitnessConfigSchema = 'network.xyo.prometheus.node.witness.config'
|
|
14
14
|
export const PrometheusNodeWitnessConfigSchema: PrometheusNodeWitnessConfigSchema = 'network.xyo.prometheus.node.witness.config'
|
package/src/index.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export * from './Payload.
|
|
1
|
+
export * from './Payload.ts'
|
|
2
2
|
// eslint-disable-next-line import/no-default-export
|
|
3
|
-
export { PrometheusNodePlugin as default, PrometheusNodePlugin } from './Plugin.
|
|
4
|
-
export * from './Schema.
|
|
5
|
-
export * from './Witness.
|
|
3
|
+
export { PrometheusNodePlugin as default, PrometheusNodePlugin } from './Plugin.ts'
|
|
4
|
+
export * from './Schema.ts'
|
|
5
|
+
export * from './Witness.ts'
|
package/dist/node/index.js
DELETED
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
// src/Plugin.ts
|
|
2
|
-
import { PayloadSetSchema } from "@xyo-network/payload-model";
|
|
3
|
-
import { createPayloadSetWitnessPlugin } from "@xyo-network/payloadset-plugin";
|
|
4
|
-
|
|
5
|
-
// src/Schema.ts
|
|
6
|
-
var PrometheusMetricValueSchema = "network.xyo.prometheus.metric.value";
|
|
7
|
-
|
|
8
|
-
// src/Witness.ts
|
|
9
|
-
import { createServer } from "node:http";
|
|
10
|
-
import { compact } from "@xylabs/lodash";
|
|
11
|
-
import { AbstractWitness } from "@xyo-network/abstract-witness";
|
|
12
|
-
import { creatableModule } from "@xyo-network/module-model";
|
|
13
|
-
import { collectDefaultMetrics, Registry } from "prom-client";
|
|
14
|
-
var PrometheusNodeWitnessConfigSchema = "network.xyo.prometheus.node.witness.config";
|
|
15
|
-
creatableModule();
|
|
16
|
-
var PrometheusNodeWitness = class extends AbstractWitness {
|
|
17
|
-
static configSchemas = [...super.configSchemas, PrometheusNodeWitnessConfigSchema];
|
|
18
|
-
static defaultConfigSchema = PrometheusNodeWitnessConfigSchema;
|
|
19
|
-
_registry = new Registry();
|
|
20
|
-
server;
|
|
21
|
-
get registry() {
|
|
22
|
-
return this._registry;
|
|
23
|
-
}
|
|
24
|
-
async observeHandler(_payloads) {
|
|
25
|
-
return await this.generateMetricValues();
|
|
26
|
-
}
|
|
27
|
-
async startHandler() {
|
|
28
|
-
collectDefaultMetrics({ register: this._registry });
|
|
29
|
-
if (this.config.port) {
|
|
30
|
-
this.server = createServer(async (_request, response) => {
|
|
31
|
-
response.writeHead(200);
|
|
32
|
-
response.end(await this._registry.metrics());
|
|
33
|
-
});
|
|
34
|
-
this.server.listen(this.config.port);
|
|
35
|
-
}
|
|
36
|
-
return await super.startHandler();
|
|
37
|
-
}
|
|
38
|
-
async stopHandler() {
|
|
39
|
-
var _a;
|
|
40
|
-
(_a = this.server) == null ? void 0 : _a.close();
|
|
41
|
-
return await super.stopHandler();
|
|
42
|
-
}
|
|
43
|
-
async generateMetricValues() {
|
|
44
|
-
return compact(
|
|
45
|
-
(await this._registry.getMetricsAsJSON()).map((metric) => {
|
|
46
|
-
const values = metric.values;
|
|
47
|
-
if (values) {
|
|
48
|
-
return { aggregator: metric.aggregator, name: metric.name, schema: PrometheusMetricValueSchema, type: metric.type, values };
|
|
49
|
-
}
|
|
50
|
-
})
|
|
51
|
-
);
|
|
52
|
-
}
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
// src/Plugin.ts
|
|
56
|
-
var PrometheusNodePlugin = () => createPayloadSetWitnessPlugin(
|
|
57
|
-
{ required: { [PrometheusMetricValueSchema]: 1 }, schema: PayloadSetSchema },
|
|
58
|
-
{
|
|
59
|
-
witness: async (params) => {
|
|
60
|
-
const result = await PrometheusNodeWitness.create(params);
|
|
61
|
-
return result;
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
);
|
|
65
|
-
export {
|
|
66
|
-
PrometheusMetricValueSchema,
|
|
67
|
-
PrometheusNodePlugin,
|
|
68
|
-
PrometheusNodeWitness,
|
|
69
|
-
PrometheusNodeWitnessConfigSchema,
|
|
70
|
-
PrometheusNodePlugin as default
|
|
71
|
-
};
|
|
72
|
-
//# sourceMappingURL=index.js.map
|