-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmetrics.go
More file actions
86 lines (76 loc) · 2.2 KB
/
metrics.go
File metadata and controls
86 lines (76 loc) · 2.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package jsmachine
import (
"github.com/prometheus/client_golang/prometheus"
)
const (
namespace = "js"
)
// initMetrics initializes Prometheus metrics
func (p *Plugin) initMetrics() {
// Counter: Total number of JavaScript executions
p.executionsTotal = prometheus.NewCounterVec(
prometheus.CounterOpts{
Namespace: namespace,
Name: "executions_total",
Help: "Total number of JavaScript executions",
},
[]string{"status"}, // success, error, timeout
)
// Histogram: Execution duration in seconds
p.executionDuration = prometheus.NewHistogramVec(
prometheus.HistogramOpts{
Namespace: namespace,
Name: "execution_duration_seconds",
Help: "JavaScript execution duration in seconds",
Buckets: []float64{.001, .005, .01, .025, .05, .1, .25, .5, 1, 2.5, 5, 10, 30},
},
[]string{"status"},
)
// Gauge: Number of VMs in the pool
p.poolSizeGauge = prometheus.NewGauge(
prometheus.GaugeOpts{
Namespace: namespace,
Name: "pool_size",
Help: "Number of JavaScript VMs in the pool",
},
)
// Gauge: Number of available (idle) VMs
p.poolAvailable = prometheus.NewGauge(
prometheus.GaugeOpts{
Namespace: namespace,
Name: "pool_available",
Help: "Number of available JavaScript VMs in the pool",
},
)
// Gauge: Number of active executions
p.activeExecutions = prometheus.NewGauge(
prometheus.GaugeOpts{
Namespace: namespace,
Name: "active_executions",
Help: "Number of currently active JavaScript executions",
},
)
// Histogram: Code size in bytes
p.codeSize = prometheus.NewHistogram(
prometheus.HistogramOpts{
Namespace: namespace,
Name: "code_size_bytes",
Help: "Size of JavaScript code in bytes",
Buckets: []float64{100, 500, 1000, 5000, 10000, 50000, 100000, 500000},
},
)
// Set initial pool size gauge
p.poolSizeGauge.Set(float64(p.cfg.PoolSize))
p.poolAvailable.Set(float64(p.cfg.PoolSize))
}
// MetricsCollector returns prometheus collectors for the metrics plugin
func (p *Plugin) MetricsCollector() []prometheus.Collector {
return []prometheus.Collector{
p.executionsTotal,
p.executionDuration,
p.poolSizeGauge,
p.poolAvailable,
p.activeExecutions,
p.codeSize,
}
}