From e699b52c5deccde2c80d4371ccae43b5b0d86589 Mon Sep 17 00:00:00 2001 From: Philipp Date: Fri, 15 Nov 2024 13:47:34 +0100 Subject: [PATCH] Add posts inbound/outbound stats --- internal/metrics/collector.go | 52 +++++++++++++++++------------------ 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/internal/metrics/collector.go b/internal/metrics/collector.go index 87d37ca..5e23ff8 100644 --- a/internal/metrics/collector.go +++ b/internal/metrics/collector.go @@ -65,10 +65,14 @@ var ( metricPrefix+"users_active_half_year", "Number of active users of the last half year.", nil, nil) - posts = prometheus.NewDesc( - metricPrefix+"posts", - "Number of posts.", - []string{"direction", "type"}, nil) + postsInbound = prometheus.NewDesc( + metricPrefix+"posts_inbound", + "Number of posts inbound.", + []string{"type"}, nil) + postsOutbound = prometheus.NewDesc( + metricPrefix+"posts_outbound", + "Number of posts outbound.", + []string{"type"}, nil) usersPending = prometheus.NewDesc( metricPrefix+"users_pending", "Number of pending users.", @@ -117,7 +121,8 @@ func (c *friendicaCollector) Describe(ch chan<- *prometheus.Desc) { ch <- usersActiveMonth ch <- usersActiveHalfYear ch <- usersPending - ch <- posts + ch <- postsInbound + ch <- postsOutbound } func (c *friendicaCollector) Collect(ch chan<- prometheus.Metric) { @@ -372,42 +377,37 @@ func collectLastExecutions(ch chan<- prometheus.Metric, status *serverinfo.Serve } type postMetric struct { - desc *prometheus.Desc - value float64 - direction string - postType string + desc *prometheus.Desc + value float64 + postType string } func collectPosts(ch chan<- prometheus.Metric, status *serverinfo.ServerInfo) error { metrics := []postMetric{ { - desc: posts, - value: float64(status.Posts.Inbound.Posts), - direction: "inbound", - postType: "posts", + desc: postsInbound, + value: float64(status.Posts.Inbound.Posts), + postType: "posts", }, { - desc: posts, - value: float64(status.Posts.Inbound.Comments), - direction: "inbound", - postType: "comments", + desc: postsInbound, + value: float64(status.Posts.Inbound.Comments), + postType: "comments", }, { - desc: posts, - value: float64(status.Posts.Outbound.Posts), - direction: "outbound", - postType: "posts", + desc: postsOutbound, + value: float64(status.Posts.Outbound.Posts), + postType: "posts", }, { - desc: posts, - value: float64(status.Posts.Outbound.Comments), - direction: "outbound", - postType: "comments", + desc: postsOutbound, + value: float64(status.Posts.Outbound.Comments), + postType: "comments", }, } for _, m := range metrics { - metric, err := prometheus.NewConstMetric(m.desc, prometheus.GaugeValue, m.value, m.direction, m.postType) + metric, err := prometheus.NewConstMetric(m.desc, prometheus.GaugeValue, m.value, m.postType) if err != nil { return fmt.Errorf("error creating metric for %s: %w", m.desc, err) }