@gravito/monitor 1.0.0-beta.1 → 1.0.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/README.md +1 -1
- package/dist/index.cjs +47 -19
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +47 -19
- package/package.json +11 -6
package/README.md
CHANGED
|
@@ -23,7 +23,7 @@ bun add @opentelemetry/sdk-node @opentelemetry/exporter-trace-otlp-http
|
|
|
23
23
|
## Quick Start
|
|
24
24
|
|
|
25
25
|
```typescript
|
|
26
|
-
import { PlanetCore } from 'gravito
|
|
26
|
+
import { PlanetCore } from '@gravito/core'
|
|
27
27
|
import { MonitorOrbit } from '@gravito/monitor'
|
|
28
28
|
|
|
29
29
|
const core = new PlanetCore()
|
package/dist/index.cjs
CHANGED
|
@@ -341,7 +341,7 @@ var MetricsController = class {
|
|
|
341
341
|
/**
|
|
342
342
|
* GET /metrics - Prometheus metrics endpoint
|
|
343
343
|
*/
|
|
344
|
-
async metrics(
|
|
344
|
+
async metrics(_c) {
|
|
345
345
|
const prometheusFormat = this.registry.toPrometheus();
|
|
346
346
|
return new Response(prometheusFormat, {
|
|
347
347
|
status: 200,
|
|
@@ -393,15 +393,21 @@ var Counter = class {
|
|
|
393
393
|
this.values.clear();
|
|
394
394
|
}
|
|
395
395
|
labelsToKey(labels) {
|
|
396
|
-
if (this.labelNames.length === 0)
|
|
396
|
+
if (this.labelNames.length === 0) {
|
|
397
|
+
return "__default__";
|
|
398
|
+
}
|
|
397
399
|
return this.labelNames.map((name) => `${name}=${labels[name] ?? ""}`).join(",");
|
|
398
400
|
}
|
|
399
401
|
keyToLabels(key) {
|
|
400
|
-
if (key === "__default__")
|
|
402
|
+
if (key === "__default__") {
|
|
403
|
+
return {};
|
|
404
|
+
}
|
|
401
405
|
const labels = {};
|
|
402
406
|
for (const part of key.split(",")) {
|
|
403
407
|
const [name, value] = part.split("=");
|
|
404
|
-
if (name)
|
|
408
|
+
if (name) {
|
|
409
|
+
labels[name] = value ?? "";
|
|
410
|
+
}
|
|
405
411
|
}
|
|
406
412
|
return labels;
|
|
407
413
|
}
|
|
@@ -448,15 +454,21 @@ var Gauge = class {
|
|
|
448
454
|
return result;
|
|
449
455
|
}
|
|
450
456
|
labelsToKey(labels) {
|
|
451
|
-
if (this.labelNames.length === 0)
|
|
457
|
+
if (this.labelNames.length === 0) {
|
|
458
|
+
return "__default__";
|
|
459
|
+
}
|
|
452
460
|
return this.labelNames.map((name) => `${name}=${labels[name] ?? ""}`).join(",");
|
|
453
461
|
}
|
|
454
462
|
keyToLabels(key) {
|
|
455
|
-
if (key === "__default__")
|
|
463
|
+
if (key === "__default__") {
|
|
464
|
+
return {};
|
|
465
|
+
}
|
|
456
466
|
const labels = {};
|
|
457
467
|
for (const part of key.split(",")) {
|
|
458
468
|
const [name, value] = part.split("=");
|
|
459
|
-
if (name)
|
|
469
|
+
if (name) {
|
|
470
|
+
labels[name] = value ?? "";
|
|
471
|
+
}
|
|
460
472
|
}
|
|
461
473
|
return labels;
|
|
462
474
|
}
|
|
@@ -511,7 +523,9 @@ var Histogram = class {
|
|
|
511
523
|
};
|
|
512
524
|
}
|
|
513
525
|
labelsToKey(labels) {
|
|
514
|
-
if (this.labelNames.length === 0)
|
|
526
|
+
if (this.labelNames.length === 0) {
|
|
527
|
+
return "__default__";
|
|
528
|
+
}
|
|
515
529
|
return this.labelNames.map((name) => `${name}=${labels[name] ?? ""}`).join(",");
|
|
516
530
|
}
|
|
517
531
|
};
|
|
@@ -597,13 +611,15 @@ var MetricsRegistry = class {
|
|
|
597
611
|
* Update default metrics with current values
|
|
598
612
|
*/
|
|
599
613
|
updateDefaultMetrics() {
|
|
600
|
-
if (!this.collectDefaultMetrics)
|
|
614
|
+
if (!this.collectDefaultMetrics) {
|
|
615
|
+
return;
|
|
616
|
+
}
|
|
601
617
|
const uptime = (Date.now() - this.startTime) / 1e3;
|
|
602
|
-
this.gauges.get(this.prefix
|
|
618
|
+
this.gauges.get(`${this.prefix}process_uptime_seconds`)?.set(uptime);
|
|
603
619
|
const memory = process.memoryUsage();
|
|
604
|
-
this.gauges.get(this.prefix
|
|
605
|
-
this.gauges.get(this.prefix
|
|
606
|
-
this.gauges.get(this.prefix
|
|
620
|
+
this.gauges.get(`${this.prefix}nodejs_heap_size_used_bytes`)?.set(memory.heapUsed);
|
|
621
|
+
this.gauges.get(`${this.prefix}nodejs_heap_size_total_bytes`)?.set(memory.heapTotal);
|
|
622
|
+
this.gauges.get(`${this.prefix}nodejs_external_memory_bytes`)?.set(memory.external);
|
|
607
623
|
}
|
|
608
624
|
/**
|
|
609
625
|
* Export metrics in Prometheus format
|
|
@@ -654,15 +670,21 @@ var MetricsRegistry = class {
|
|
|
654
670
|
}
|
|
655
671
|
formatLabels(labels) {
|
|
656
672
|
const entries = Object.entries(labels);
|
|
657
|
-
if (entries.length === 0)
|
|
673
|
+
if (entries.length === 0) {
|
|
674
|
+
return "";
|
|
675
|
+
}
|
|
658
676
|
return `{${entries.map(([k, v]) => `${k}="${v}"`).join(",")}}`;
|
|
659
677
|
}
|
|
660
678
|
keyToLabels(key) {
|
|
661
|
-
if (key === "__default__")
|
|
679
|
+
if (key === "__default__") {
|
|
680
|
+
return {};
|
|
681
|
+
}
|
|
662
682
|
const labels = {};
|
|
663
683
|
for (const part of key.split(",")) {
|
|
664
684
|
const [name, value] = part.split("=");
|
|
665
|
-
if (name)
|
|
685
|
+
if (name) {
|
|
686
|
+
labels[name] = value ?? "";
|
|
687
|
+
}
|
|
666
688
|
}
|
|
667
689
|
return labels;
|
|
668
690
|
}
|
|
@@ -727,7 +749,9 @@ var TracingManager = class {
|
|
|
727
749
|
* Initialize OpenTelemetry SDK if available
|
|
728
750
|
*/
|
|
729
751
|
async initialize() {
|
|
730
|
-
if (this.isInitialized)
|
|
752
|
+
if (this.isInitialized) {
|
|
753
|
+
return;
|
|
754
|
+
}
|
|
731
755
|
try {
|
|
732
756
|
const [
|
|
733
757
|
{ NodeSDK },
|
|
@@ -823,9 +847,13 @@ var TracingManager = class {
|
|
|
823
847
|
*/
|
|
824
848
|
extractContext(headers) {
|
|
825
849
|
const traceparent = headers.get("traceparent");
|
|
826
|
-
if (!traceparent)
|
|
850
|
+
if (!traceparent) {
|
|
851
|
+
return null;
|
|
852
|
+
}
|
|
827
853
|
const parts = traceparent.split("-");
|
|
828
|
-
if (parts.length !== 4)
|
|
854
|
+
if (parts.length !== 4) {
|
|
855
|
+
return null;
|
|
856
|
+
}
|
|
829
857
|
return {
|
|
830
858
|
traceId: parts[1] ?? "",
|
|
831
859
|
spanId: parts[2] ?? "",
|
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { GravitoContext, GravitoOrbit, PlanetCore } from 'gravito
|
|
1
|
+
import { GravitoContext, GravitoOrbit, PlanetCore } from '@gravito/core';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* @gravito/monitor - Configuration Types
|
|
@@ -364,7 +364,7 @@ declare class MetricsController {
|
|
|
364
364
|
/**
|
|
365
365
|
* GET /metrics - Prometheus metrics endpoint
|
|
366
366
|
*/
|
|
367
|
-
metrics(
|
|
367
|
+
metrics(_c: GravitoContext): Promise<Response>;
|
|
368
368
|
}
|
|
369
369
|
|
|
370
370
|
/**
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { GravitoContext, GravitoOrbit, PlanetCore } from 'gravito
|
|
1
|
+
import { GravitoContext, GravitoOrbit, PlanetCore } from '@gravito/core';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* @gravito/monitor - Configuration Types
|
|
@@ -364,7 +364,7 @@ declare class MetricsController {
|
|
|
364
364
|
/**
|
|
365
365
|
* GET /metrics - Prometheus metrics endpoint
|
|
366
366
|
*/
|
|
367
|
-
metrics(
|
|
367
|
+
metrics(_c: GravitoContext): Promise<Response>;
|
|
368
368
|
}
|
|
369
369
|
|
|
370
370
|
/**
|
package/dist/index.js
CHANGED
|
@@ -289,7 +289,7 @@ var MetricsController = class {
|
|
|
289
289
|
/**
|
|
290
290
|
* GET /metrics - Prometheus metrics endpoint
|
|
291
291
|
*/
|
|
292
|
-
async metrics(
|
|
292
|
+
async metrics(_c) {
|
|
293
293
|
const prometheusFormat = this.registry.toPrometheus();
|
|
294
294
|
return new Response(prometheusFormat, {
|
|
295
295
|
status: 200,
|
|
@@ -341,15 +341,21 @@ var Counter = class {
|
|
|
341
341
|
this.values.clear();
|
|
342
342
|
}
|
|
343
343
|
labelsToKey(labels) {
|
|
344
|
-
if (this.labelNames.length === 0)
|
|
344
|
+
if (this.labelNames.length === 0) {
|
|
345
|
+
return "__default__";
|
|
346
|
+
}
|
|
345
347
|
return this.labelNames.map((name) => `${name}=${labels[name] ?? ""}`).join(",");
|
|
346
348
|
}
|
|
347
349
|
keyToLabels(key) {
|
|
348
|
-
if (key === "__default__")
|
|
350
|
+
if (key === "__default__") {
|
|
351
|
+
return {};
|
|
352
|
+
}
|
|
349
353
|
const labels = {};
|
|
350
354
|
for (const part of key.split(",")) {
|
|
351
355
|
const [name, value] = part.split("=");
|
|
352
|
-
if (name)
|
|
356
|
+
if (name) {
|
|
357
|
+
labels[name] = value ?? "";
|
|
358
|
+
}
|
|
353
359
|
}
|
|
354
360
|
return labels;
|
|
355
361
|
}
|
|
@@ -396,15 +402,21 @@ var Gauge = class {
|
|
|
396
402
|
return result;
|
|
397
403
|
}
|
|
398
404
|
labelsToKey(labels) {
|
|
399
|
-
if (this.labelNames.length === 0)
|
|
405
|
+
if (this.labelNames.length === 0) {
|
|
406
|
+
return "__default__";
|
|
407
|
+
}
|
|
400
408
|
return this.labelNames.map((name) => `${name}=${labels[name] ?? ""}`).join(",");
|
|
401
409
|
}
|
|
402
410
|
keyToLabels(key) {
|
|
403
|
-
if (key === "__default__")
|
|
411
|
+
if (key === "__default__") {
|
|
412
|
+
return {};
|
|
413
|
+
}
|
|
404
414
|
const labels = {};
|
|
405
415
|
for (const part of key.split(",")) {
|
|
406
416
|
const [name, value] = part.split("=");
|
|
407
|
-
if (name)
|
|
417
|
+
if (name) {
|
|
418
|
+
labels[name] = value ?? "";
|
|
419
|
+
}
|
|
408
420
|
}
|
|
409
421
|
return labels;
|
|
410
422
|
}
|
|
@@ -459,7 +471,9 @@ var Histogram = class {
|
|
|
459
471
|
};
|
|
460
472
|
}
|
|
461
473
|
labelsToKey(labels) {
|
|
462
|
-
if (this.labelNames.length === 0)
|
|
474
|
+
if (this.labelNames.length === 0) {
|
|
475
|
+
return "__default__";
|
|
476
|
+
}
|
|
463
477
|
return this.labelNames.map((name) => `${name}=${labels[name] ?? ""}`).join(",");
|
|
464
478
|
}
|
|
465
479
|
};
|
|
@@ -545,13 +559,15 @@ var MetricsRegistry = class {
|
|
|
545
559
|
* Update default metrics with current values
|
|
546
560
|
*/
|
|
547
561
|
updateDefaultMetrics() {
|
|
548
|
-
if (!this.collectDefaultMetrics)
|
|
562
|
+
if (!this.collectDefaultMetrics) {
|
|
563
|
+
return;
|
|
564
|
+
}
|
|
549
565
|
const uptime = (Date.now() - this.startTime) / 1e3;
|
|
550
|
-
this.gauges.get(this.prefix
|
|
566
|
+
this.gauges.get(`${this.prefix}process_uptime_seconds`)?.set(uptime);
|
|
551
567
|
const memory = process.memoryUsage();
|
|
552
|
-
this.gauges.get(this.prefix
|
|
553
|
-
this.gauges.get(this.prefix
|
|
554
|
-
this.gauges.get(this.prefix
|
|
568
|
+
this.gauges.get(`${this.prefix}nodejs_heap_size_used_bytes`)?.set(memory.heapUsed);
|
|
569
|
+
this.gauges.get(`${this.prefix}nodejs_heap_size_total_bytes`)?.set(memory.heapTotal);
|
|
570
|
+
this.gauges.get(`${this.prefix}nodejs_external_memory_bytes`)?.set(memory.external);
|
|
555
571
|
}
|
|
556
572
|
/**
|
|
557
573
|
* Export metrics in Prometheus format
|
|
@@ -602,15 +618,21 @@ var MetricsRegistry = class {
|
|
|
602
618
|
}
|
|
603
619
|
formatLabels(labels) {
|
|
604
620
|
const entries = Object.entries(labels);
|
|
605
|
-
if (entries.length === 0)
|
|
621
|
+
if (entries.length === 0) {
|
|
622
|
+
return "";
|
|
623
|
+
}
|
|
606
624
|
return `{${entries.map(([k, v]) => `${k}="${v}"`).join(",")}}`;
|
|
607
625
|
}
|
|
608
626
|
keyToLabels(key) {
|
|
609
|
-
if (key === "__default__")
|
|
627
|
+
if (key === "__default__") {
|
|
628
|
+
return {};
|
|
629
|
+
}
|
|
610
630
|
const labels = {};
|
|
611
631
|
for (const part of key.split(",")) {
|
|
612
632
|
const [name, value] = part.split("=");
|
|
613
|
-
if (name)
|
|
633
|
+
if (name) {
|
|
634
|
+
labels[name] = value ?? "";
|
|
635
|
+
}
|
|
614
636
|
}
|
|
615
637
|
return labels;
|
|
616
638
|
}
|
|
@@ -675,7 +697,9 @@ var TracingManager = class {
|
|
|
675
697
|
* Initialize OpenTelemetry SDK if available
|
|
676
698
|
*/
|
|
677
699
|
async initialize() {
|
|
678
|
-
if (this.isInitialized)
|
|
700
|
+
if (this.isInitialized) {
|
|
701
|
+
return;
|
|
702
|
+
}
|
|
679
703
|
try {
|
|
680
704
|
const [
|
|
681
705
|
{ NodeSDK },
|
|
@@ -771,9 +795,13 @@ var TracingManager = class {
|
|
|
771
795
|
*/
|
|
772
796
|
extractContext(headers) {
|
|
773
797
|
const traceparent = headers.get("traceparent");
|
|
774
|
-
if (!traceparent)
|
|
798
|
+
if (!traceparent) {
|
|
799
|
+
return null;
|
|
800
|
+
}
|
|
775
801
|
const parts = traceparent.split("-");
|
|
776
|
-
if (parts.length !== 4)
|
|
802
|
+
if (parts.length !== 4) {
|
|
803
|
+
return null;
|
|
804
|
+
}
|
|
777
805
|
return {
|
|
778
806
|
traceId: parts[1] ?? "",
|
|
779
807
|
spanId: parts[2] ?? "",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gravito/monitor",
|
|
3
|
-
"version": "1.0.0
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"description": "Observability module for Gravito - Health checks, Metrics, and Tracing",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -24,12 +24,14 @@
|
|
|
24
24
|
],
|
|
25
25
|
"scripts": {
|
|
26
26
|
"build": "bun run build.ts",
|
|
27
|
-
"typecheck": "tsc --noEmit",
|
|
28
|
-
"test": "bun test"
|
|
27
|
+
"typecheck": "bun tsc -p tsconfig.json --noEmit --skipLibCheck",
|
|
28
|
+
"test": "bun test",
|
|
29
|
+
"test:coverage": "bun test --coverage --coverage-threshold=80",
|
|
30
|
+
"test:ci": "bun test --coverage --coverage-threshold=80"
|
|
29
31
|
},
|
|
30
32
|
"peerDependencies": {
|
|
31
|
-
"gravito
|
|
32
|
-
"@gravito/photon": "
|
|
33
|
+
"@gravito/core": "workspace:*",
|
|
34
|
+
"@gravito/photon": "workspace:*"
|
|
33
35
|
},
|
|
34
36
|
"devDependencies": {
|
|
35
37
|
"@types/bun": "latest",
|
|
@@ -38,7 +40,7 @@
|
|
|
38
40
|
"@opentelemetry/exporter-trace-otlp-http": "^0.57.0",
|
|
39
41
|
"@opentelemetry/resources": "^1.29.0",
|
|
40
42
|
"@opentelemetry/semantic-conventions": "^1.28.0",
|
|
41
|
-
"gravito
|
|
43
|
+
"@gravito/core": "workspace:*",
|
|
42
44
|
"tsup": "^8.2.4",
|
|
43
45
|
"typescript": "^5.9.3"
|
|
44
46
|
},
|
|
@@ -64,5 +66,8 @@
|
|
|
64
66
|
"type": "git",
|
|
65
67
|
"url": "https://github.com/gravito-framework/gravito.git",
|
|
66
68
|
"directory": "packages/monitor"
|
|
69
|
+
},
|
|
70
|
+
"publishConfig": {
|
|
71
|
+
"access": "public"
|
|
67
72
|
}
|
|
68
73
|
}
|