summaryrefslogtreecommitdiff
path: root/internal/metrics/generator.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/metrics/generator.go')
-rw-r--r--internal/metrics/generator.go85
1 files changed, 85 insertions, 0 deletions
diff --git a/internal/metrics/generator.go b/internal/metrics/generator.go
new file mode 100644
index 0000000..c85906a
--- /dev/null
+++ b/internal/metrics/generator.go
@@ -0,0 +1,85 @@
+package metrics
+
+import (
+ "math/rand"
+
+ "github.com/prometheus/client_golang/prometheus"
+)
+
+const (
+ minTemperature = 15.0
+ maxTemperature = 35.0
+ maxConnections = 100
+ maxRequests = 10
+)
+
+var (
+ jobTypes = []string{"email", "report", "backup"}
+ statuses = []string{"success", "failed"}
+)
+
+// Collectors holds Prometheus metric collectors for realtime mode
+type Collectors struct {
+ RequestsTotal prometheus.Counter
+ ActiveConnections prometheus.Gauge
+ TemperatureCelsius prometheus.Gauge
+ RequestDuration prometheus.Histogram
+ JobsProcessed *prometheus.CounterVec
+}
+
+// NewCollectors creates new Prometheus metric collectors for testing.
+// All metrics are prefixed with "epimetheus_test_" to clearly indicate
+// they are generated by the prometheus-pusher test/demo functionality.
+func NewCollectors() Collectors {
+ return Collectors{
+ RequestsTotal: prometheus.NewCounter(
+ prometheus.CounterOpts{
+ Name: "epimetheus_test_requests_total",
+ Help: "Total number of requests processed (test metric)",
+ },
+ ),
+ ActiveConnections: prometheus.NewGauge(
+ prometheus.GaugeOpts{
+ Name: "epimetheus_test_active_connections",
+ Help: "Number of currently active connections (test metric)",
+ },
+ ),
+ TemperatureCelsius: prometheus.NewGauge(
+ prometheus.GaugeOpts{
+ Name: "epimetheus_test_temperature_celsius",
+ Help: "Current temperature in Celsius (test metric)",
+ },
+ ),
+ RequestDuration: prometheus.NewHistogram(
+ prometheus.HistogramOpts{
+ Name: "epimetheus_test_request_duration_seconds",
+ Help: "Histogram of request duration in seconds (test metric)",
+ Buckets: prometheus.DefBuckets,
+ },
+ ),
+ JobsProcessed: prometheus.NewCounterVec(
+ prometheus.CounterOpts{
+ Name: "epimetheus_test_jobs_processed_total",
+ Help: "Total number of jobs processed by type (test metric)",
+ },
+ []string{"job_type", "status"},
+ ),
+ }
+}
+
+// Simulate generates random metric values for the collectors
+func (c Collectors) Simulate() {
+ c.RequestsTotal.Add(float64(rand.Intn(maxRequests) + 1))
+ c.ActiveConnections.Set(float64(rand.Intn(maxConnections)))
+ c.TemperatureCelsius.Set(minTemperature + rand.Float64()*(maxTemperature-minTemperature))
+
+ for i := 0; i < rand.Intn(5)+1; i++ {
+ duration := rand.Float64() * 2
+ c.RequestDuration.Observe(duration)
+ }
+
+ for _, jobType := range jobTypes {
+ status := statuses[rand.Intn(len(statuses))]
+ c.JobsProcessed.WithLabelValues(jobType, status).Add(float64(rand.Intn(5)))
+ }
+}