@xyo-network/prometheus-node-plugin 5.3.1 → 5.3.3
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/node/index.mjs +1 -1
- package/dist/node/index.mjs.map +1 -1
- package/package.json +26 -19
- package/src/Payload.ts +0 -14
- package/src/Plugin.ts +0 -16
- package/src/Schema.ts +0 -4
- package/src/Witness.ts +0 -71
- package/src/index.ts +0 -4
package/dist/node/index.mjs
CHANGED
|
@@ -8,7 +8,7 @@ var PrometheusMetricValueSchema = asSchema("network.xyo.prometheus.metric.value"
|
|
|
8
8
|
|
|
9
9
|
// src/Witness.ts
|
|
10
10
|
import { createServer } from "http";
|
|
11
|
-
import { exists } from "@xylabs/
|
|
11
|
+
import { exists } from "@xylabs/sdk-js";
|
|
12
12
|
import { AbstractWitness } from "@xyo-network/abstract-witness";
|
|
13
13
|
import { creatableModule } from "@xyo-network/module-model";
|
|
14
14
|
import {
|
package/dist/node/index.mjs.map
CHANGED
|
@@ -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.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","import { asSchema } from '@xyo-network/payload-model'\n\nexport type PrometheusMetricValueSchema = typeof PrometheusMetricValueSchema\nexport const PrometheusMetricValueSchema = asSchema('network.xyo.prometheus.metric.value', true)\n","import type { Server } from 'node:http'\nimport { createServer } from 'node:http'\n\nimport { exists } from '@xylabs/
|
|
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","import { asSchema } from '@xyo-network/payload-model'\n\nexport type PrometheusMetricValueSchema = typeof PrometheusMetricValueSchema\nexport const PrometheusMetricValueSchema = asSchema('network.xyo.prometheus.metric.value', true)\n","import type { Server } from 'node:http'\nimport { createServer } from 'node:http'\n\nimport { exists } from '@xylabs/sdk-js'\nimport { AbstractWitness } from '@xyo-network/abstract-witness'\nimport type { AnyConfigSchema } from '@xyo-network/module-model'\nimport { creatableModule } from '@xyo-network/module-model'\nimport {\n asSchema, type Payload, type Schema,\n} from '@xyo-network/payload-model'\nimport type { WitnessConfig, WitnessParams } from '@xyo-network/witness-model'\nimport { collectDefaultMetrics, Registry } from 'prom-client'\n\nimport type { PrometheusMetricValuePayload } from './Payload.ts'\nimport { PrometheusMetricValueSchema } from './Schema.ts'\n\nexport type PrometheusNodeWitnessConfigSchema = typeof PrometheusNodeWitnessConfigSchema\nexport const PrometheusNodeWitnessConfigSchema = asSchema('network.xyo.prometheus.node.witness.config', true)\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<void> {\n this.server?.close()\n await super.stopHandler()\n }\n\n private async generateMetricValues(): Promise<PrometheusMetricValuePayload[]> {\n return (await this._registry.getMetricsAsJSON()).map((metric) => {\n const values = metric.values\n if (values) {\n return {\n aggregator: metric.aggregator, name: metric.name, schema: PrometheusMetricValueSchema, type: metric.type, values,\n }\n }\n }).filter(exists)\n }\n}\n"],"mappings":";AAAA,SAAS,wBAAwB;AACjC,SAAS,qCAAqC;;;ACD9C,SAAS,gBAAgB;AAGlB,IAAM,8BAA8B,SAAS,uCAAuC,IAAI;;;ACF/F,SAAS,oBAAoB;AAE7B,SAAS,cAAc;AACvB,SAAS,uBAAuB;AAEhC,SAAS,uBAAuB;AAChC;AAAA,EACE,YAAAA;AAAA,OACK;AAEP,SAAS,uBAAuB,gBAAgB;AAMzC,IAAM,oCAAoCC,UAAS,8CAA8C,IAAI;AAS5G,gBAAgB;AACT,IAAM,wBAAN,cAA+G,gBAAyB;AAAA,EAC7I,OAAyB,gBAA0B,CAAC,GAAG,MAAM,eAAe,iCAAiC;AAAA,EAC7G,OAAyB,sBAA8B;AAAA,EAC7C,YAAY,IAAI,SAAS;AAAA,EACzB;AAAA,EAEV,IAAI,WAAqB;AACvB,WAAO,KAAK;AAAA,EACd;AAAA,EAEA,MAAyB,eAAe,WAAoD;AAC1F,WAAO,MAAM,KAAK,qBAAqB;AAAA,EACzC;AAAA,EAEA,MAAyB,eAAe;AACtC,0BAAsB,EAAE,UAAU,KAAK,UAAU,CAAC;AAClD,QAAI,KAAK,OAAO,MAAM;AAEpB,WAAK,SAAS,aAAa,OAAO,UAAU,aAAa;AACvD,iBAAS,UAAU,GAAG;AAEtB,iBAAS,IAAI,MAAM,KAAK,UAAU,QAAQ,CAAC;AAAA,MAC7C,CAAC;AACD,WAAK,OAAO,OAAO,KAAK,OAAO,IAAI;AAAA,IACrC;AACA,WAAO,MAAM,MAAM,aAAa;AAAA,EAClC;AAAA,EAEA,MAAyB,cAA6B;AACpD,SAAK,QAAQ,MAAM;AACnB,UAAM,MAAM,YAAY;AAAA,EAC1B;AAAA,EAEA,MAAc,uBAAgE;AAC5E,YAAQ,MAAM,KAAK,UAAU,iBAAiB,GAAG,IAAI,CAAC,WAAW;AAC/D,YAAM,SAAS,OAAO;AACtB,UAAI,QAAQ;AACV,eAAO;AAAA,UACL,YAAY,OAAO;AAAA,UAAY,MAAM,OAAO;AAAA,UAAM,QAAQ;AAAA,UAA6B,MAAM,OAAO;AAAA,UAAM;AAAA,QAC5G;AAAA,MACF;AAAA,IACF,CAAC,EAAE,OAAO,MAAM;AAAA,EAClB;AACF;;;AFhEO,IAAM,uBAAuB,MAClC;AAAA,EACE,EAAE,UAAU,EAAE,CAAC,2BAA2B,GAAG,EAAE,GAAG,QAAQ,iBAAiB;AAAA,EAC3E;AAAA,IACE,SAAS,OAAO,WAAW;AACzB,YAAM,SAAS,MAAM,sBAAsB,OAAO,MAAM;AACxD,aAAO;AAAA,IACT;AAAA,EACF;AACF;","names":["asSchema","asSchema"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xyo-network/prometheus-node-plugin",
|
|
3
|
-
"version": "5.3.
|
|
3
|
+
"version": "5.3.3",
|
|
4
4
|
"description": "Typescript/Javascript Plugins for XYO Platform",
|
|
5
5
|
"homepage": "https://xyo.network",
|
|
6
6
|
"bugs": {
|
|
@@ -30,27 +30,34 @@
|
|
|
30
30
|
"types": "dist/node/index.d.ts",
|
|
31
31
|
"files": [
|
|
32
32
|
"dist",
|
|
33
|
-
"
|
|
34
|
-
"!**/*.bench.*",
|
|
35
|
-
"!**/*.spec.*",
|
|
36
|
-
"!**/*.test.*"
|
|
33
|
+
"README.md"
|
|
37
34
|
],
|
|
38
|
-
"dependencies": {
|
|
39
|
-
"@xylabs/exists": "~5.0.64",
|
|
40
|
-
"@xyo-network/abstract-witness": "~5.3.2",
|
|
41
|
-
"@xyo-network/module-model": "~5.3.2",
|
|
42
|
-
"@xyo-network/payload-model": "~5.3.2",
|
|
43
|
-
"@xyo-network/payloadset-plugin": "~5.3.2",
|
|
44
|
-
"@xyo-network/witness-model": "~5.3.2",
|
|
45
|
-
"prom-client": "~15.1.3"
|
|
46
|
-
},
|
|
47
35
|
"devDependencies": {
|
|
48
|
-
"@xylabs/
|
|
49
|
-
"@xylabs/
|
|
50
|
-
"@xylabs/
|
|
51
|
-
"@
|
|
36
|
+
"@xylabs/sdk-js": "^5.0.90",
|
|
37
|
+
"@xylabs/ts-scripts-common": "~7.5.10",
|
|
38
|
+
"@xylabs/ts-scripts-yarn3": "~7.5.10",
|
|
39
|
+
"@xylabs/tsconfig": "~7.5.10",
|
|
40
|
+
"@xylabs/vitest-extended": "~5.0.90",
|
|
41
|
+
"@xyo-network/abstract-witness": "~5.3.5",
|
|
42
|
+
"@xyo-network/module-model": "~5.3.5",
|
|
43
|
+
"@xyo-network/payload-model": "~5.3.5",
|
|
44
|
+
"@xyo-network/payloadset-plugin": "~5.3.5",
|
|
45
|
+
"@xyo-network/sdk-js": "~5.3.5",
|
|
46
|
+
"@xyo-network/witness-model": "~5.3.5",
|
|
47
|
+
"prom-client": "~15.1.3",
|
|
52
48
|
"typescript": "~5.9.3",
|
|
53
|
-
"vitest": "~4.
|
|
49
|
+
"vitest": "~4.1.2",
|
|
50
|
+
"zod": "^4.3.6"
|
|
51
|
+
},
|
|
52
|
+
"peerDependencies": {
|
|
53
|
+
"@xylabs/sdk-js": "^5",
|
|
54
|
+
"@xyo-network/abstract-witness": "^5",
|
|
55
|
+
"@xyo-network/module-model": "^5",
|
|
56
|
+
"@xyo-network/payload-model": "^5",
|
|
57
|
+
"@xyo-network/payloadset-plugin": "^5",
|
|
58
|
+
"@xyo-network/witness-model": "^5",
|
|
59
|
+
"prom-client": "^15",
|
|
60
|
+
"zod": "^4"
|
|
54
61
|
},
|
|
55
62
|
"publishConfig": {
|
|
56
63
|
"access": "public"
|
package/src/Payload.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import type { Payload } from '@xyo-network/payload-model'
|
|
2
|
-
import type { Aggregator, MetricType } from 'prom-client'
|
|
3
|
-
|
|
4
|
-
import type { PrometheusMetricValueSchema } from './Schema.ts'
|
|
5
|
-
|
|
6
|
-
export type PrometheusMetricValuePayload = Payload<
|
|
7
|
-
{
|
|
8
|
-
aggregator: Aggregator
|
|
9
|
-
name: string
|
|
10
|
-
type: MetricType
|
|
11
|
-
values: (number | string | object)[]
|
|
12
|
-
},
|
|
13
|
-
PrometheusMetricValueSchema
|
|
14
|
-
>
|
package/src/Plugin.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { PayloadSetSchema } from '@xyo-network/payload-model'
|
|
2
|
-
import { createPayloadSetWitnessPlugin } from '@xyo-network/payloadset-plugin'
|
|
3
|
-
|
|
4
|
-
import { PrometheusMetricValueSchema } from './Schema.ts'
|
|
5
|
-
import { PrometheusNodeWitness } from './Witness.ts'
|
|
6
|
-
|
|
7
|
-
export const PrometheusNodePlugin = () =>
|
|
8
|
-
createPayloadSetWitnessPlugin<PrometheusNodeWitness>(
|
|
9
|
-
{ required: { [PrometheusMetricValueSchema]: 1 }, schema: PayloadSetSchema },
|
|
10
|
-
{
|
|
11
|
-
witness: async (params) => {
|
|
12
|
-
const result = await PrometheusNodeWitness.create(params)
|
|
13
|
-
return result
|
|
14
|
-
},
|
|
15
|
-
},
|
|
16
|
-
)
|
package/src/Schema.ts
DELETED
package/src/Witness.ts
DELETED
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
import type { Server } from 'node:http'
|
|
2
|
-
import { createServer } from 'node:http'
|
|
3
|
-
|
|
4
|
-
import { exists } from '@xylabs/exists'
|
|
5
|
-
import { AbstractWitness } from '@xyo-network/abstract-witness'
|
|
6
|
-
import type { AnyConfigSchema } from '@xyo-network/module-model'
|
|
7
|
-
import { creatableModule } from '@xyo-network/module-model'
|
|
8
|
-
import {
|
|
9
|
-
asSchema, type Payload, type Schema,
|
|
10
|
-
} from '@xyo-network/payload-model'
|
|
11
|
-
import type { WitnessConfig, WitnessParams } from '@xyo-network/witness-model'
|
|
12
|
-
import { collectDefaultMetrics, Registry } from 'prom-client'
|
|
13
|
-
|
|
14
|
-
import type { PrometheusMetricValuePayload } from './Payload.ts'
|
|
15
|
-
import { PrometheusMetricValueSchema } from './Schema.ts'
|
|
16
|
-
|
|
17
|
-
export type PrometheusNodeWitnessConfigSchema = typeof PrometheusNodeWitnessConfigSchema
|
|
18
|
-
export const PrometheusNodeWitnessConfigSchema = asSchema('network.xyo.prometheus.node.witness.config', true)
|
|
19
|
-
|
|
20
|
-
export type PrometheusNodeWitnessConfig = WitnessConfig<{
|
|
21
|
-
port?: number
|
|
22
|
-
schema: PrometheusNodeWitnessConfigSchema
|
|
23
|
-
}>
|
|
24
|
-
|
|
25
|
-
export type PrometheusNodeWitnessParams = WitnessParams<AnyConfigSchema<PrometheusNodeWitnessConfig>>
|
|
26
|
-
|
|
27
|
-
creatableModule()
|
|
28
|
-
export class PrometheusNodeWitness<TParams extends PrometheusNodeWitnessParams = PrometheusNodeWitnessParams> extends AbstractWitness<TParams> {
|
|
29
|
-
static override readonly configSchemas: Schema[] = [...super.configSchemas, PrometheusNodeWitnessConfigSchema]
|
|
30
|
-
static override readonly defaultConfigSchema: Schema = PrometheusNodeWitnessConfigSchema
|
|
31
|
-
protected _registry = new Registry()
|
|
32
|
-
protected server?: Server
|
|
33
|
-
|
|
34
|
-
get registry(): Registry {
|
|
35
|
-
return this._registry
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
protected override async observeHandler(_payloads?: Partial<Payload>[]): Promise<Payload[]> {
|
|
39
|
-
return await this.generateMetricValues()
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
protected override async startHandler() {
|
|
43
|
-
collectDefaultMetrics({ register: this._registry })
|
|
44
|
-
if (this.config.port) {
|
|
45
|
-
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
|
46
|
-
this.server = createServer(async (_request, response) => {
|
|
47
|
-
response.writeHead(200)
|
|
48
|
-
|
|
49
|
-
response.end(await this._registry.metrics())
|
|
50
|
-
})
|
|
51
|
-
this.server.listen(this.config.port)
|
|
52
|
-
}
|
|
53
|
-
return await super.startHandler()
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
protected override async stopHandler(): Promise<void> {
|
|
57
|
-
this.server?.close()
|
|
58
|
-
await super.stopHandler()
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
private async generateMetricValues(): Promise<PrometheusMetricValuePayload[]> {
|
|
62
|
-
return (await this._registry.getMetricsAsJSON()).map((metric) => {
|
|
63
|
-
const values = metric.values
|
|
64
|
-
if (values) {
|
|
65
|
-
return {
|
|
66
|
-
aggregator: metric.aggregator, name: metric.name, schema: PrometheusMetricValueSchema, type: metric.type, values,
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
}).filter(exists)
|
|
70
|
-
}
|
|
71
|
-
}
|
package/src/index.ts
DELETED