From 037dc40970815f4da392427963b1d502481b917b Mon Sep 17 00:00:00 2001 From: Antonio Si Date: Wed, 29 Mar 2023 18:02:19 -0700 Subject: [PATCH 1/3] Add default Golang metrics Signed-off-by: Antonio Si --- metrics/metrics.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/metrics/metrics.go b/metrics/metrics.go index edb2a96f9d..f6a0c629aa 100644 --- a/metrics/metrics.go +++ b/metrics/metrics.go @@ -2,6 +2,7 @@ package metrics import ( "context" + "github.com/prometheus/client_golang/prometheus/collectors" "net/http" "github.com/prometheus/client_golang/prometheus" @@ -167,8 +168,9 @@ func (m *Metrics) ActionDuration(sensorName, triggerName string, num float64) { func (m *Metrics) Run(ctx context.Context, addr string) { log := logging.FromContext(ctx) metricsRegistry := prometheus.NewRegistry() - metricsRegistry.MustRegister(m) + metricsRegistry.MustRegister(collectors.NewGoCollector(), m) http.Handle("/metrics", promhttp.HandlerFor(metricsRegistry, promhttp.HandlerOpts{})) + log.Info("starting metrics server") if err := http.ListenAndServe(addr, nil); err != nil { log.Fatalw("failed to start metrics server", zap.Error(err)) From 331b873aa368535f52e6cada2a407485428b602f Mon Sep 17 00:00:00 2001 From: Antonio Si Date: Wed, 29 Mar 2023 20:32:52 -0700 Subject: [PATCH 2/3] Add Golang metrics into the metrics repository Signed-off-by: Antonio Si --- metrics/metrics.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/metrics/metrics.go b/metrics/metrics.go index f6a0c629aa..fcaf51fd1d 100644 --- a/metrics/metrics.go +++ b/metrics/metrics.go @@ -170,7 +170,7 @@ func (m *Metrics) Run(ctx context.Context, addr string) { metricsRegistry := prometheus.NewRegistry() metricsRegistry.MustRegister(collectors.NewGoCollector(), m) http.Handle("/metrics", promhttp.HandlerFor(metricsRegistry, promhttp.HandlerOpts{})) - + log.Info("starting metrics server") if err := http.ListenAndServe(addr, nil); err != nil { log.Fatalw("failed to start metrics server", zap.Error(err)) From e76c6472d1e1a799b772a2674ea7a34d24a19548 Mon Sep 17 00:00:00 2001 From: Antonio Si Date: Thu, 30 Mar 2023 15:23:23 -0700 Subject: [PATCH 3/3] Add Golang metrics into the metrics repository Signed-off-by: Antonio Si --- metrics/metrics.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/metrics/metrics.go b/metrics/metrics.go index fcaf51fd1d..1b24e29959 100644 --- a/metrics/metrics.go +++ b/metrics/metrics.go @@ -2,9 +2,10 @@ package metrics import ( "context" - "github.com/prometheus/client_golang/prometheus/collectors" "net/http" + "github.com/prometheus/client_golang/prometheus/collectors" + "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus/promhttp" "go.uber.org/zap"