Add posts inbound/outbound stats

This commit is contained in:
Philipp Holzer 2024-11-15 13:47:34 +01:00
parent 5770fc2a18
commit e699b52c5d
Signed by: nupplaPhil
GPG key ID: 24A7501396EB5432

View file

@ -65,10 +65,14 @@ var (
metricPrefix+"users_active_half_year", metricPrefix+"users_active_half_year",
"Number of active users of the last half year.", "Number of active users of the last half year.",
nil, nil) nil, nil)
posts = prometheus.NewDesc( postsInbound = prometheus.NewDesc(
metricPrefix+"posts", metricPrefix+"posts_inbound",
"Number of posts.", "Number of posts inbound.",
[]string{"direction", "type"}, nil) []string{"type"}, nil)
postsOutbound = prometheus.NewDesc(
metricPrefix+"posts_outbound",
"Number of posts outbound.",
[]string{"type"}, nil)
usersPending = prometheus.NewDesc( usersPending = prometheus.NewDesc(
metricPrefix+"users_pending", metricPrefix+"users_pending",
"Number of pending users.", "Number of pending users.",
@ -117,7 +121,8 @@ func (c *friendicaCollector) Describe(ch chan<- *prometheus.Desc) {
ch <- usersActiveMonth ch <- usersActiveMonth
ch <- usersActiveHalfYear ch <- usersActiveHalfYear
ch <- usersPending ch <- usersPending
ch <- posts ch <- postsInbound
ch <- postsOutbound
} }
func (c *friendicaCollector) Collect(ch chan<- prometheus.Metric) { func (c *friendicaCollector) Collect(ch chan<- prometheus.Metric) {
@ -374,40 +379,35 @@ func collectLastExecutions(ch chan<- prometheus.Metric, status *serverinfo.Serve
type postMetric struct { type postMetric struct {
desc *prometheus.Desc desc *prometheus.Desc
value float64 value float64
direction string
postType string postType string
} }
func collectPosts(ch chan<- prometheus.Metric, status *serverinfo.ServerInfo) error { func collectPosts(ch chan<- prometheus.Metric, status *serverinfo.ServerInfo) error {
metrics := []postMetric{ metrics := []postMetric{
{ {
desc: posts, desc: postsInbound,
value: float64(status.Posts.Inbound.Posts), value: float64(status.Posts.Inbound.Posts),
direction: "inbound",
postType: "posts", postType: "posts",
}, },
{ {
desc: posts, desc: postsInbound,
value: float64(status.Posts.Inbound.Comments), value: float64(status.Posts.Inbound.Comments),
direction: "inbound",
postType: "comments", postType: "comments",
}, },
{ {
desc: posts, desc: postsOutbound,
value: float64(status.Posts.Outbound.Posts), value: float64(status.Posts.Outbound.Posts),
direction: "outbound",
postType: "posts", postType: "posts",
}, },
{ {
desc: posts, desc: postsOutbound,
value: float64(status.Posts.Outbound.Comments), value: float64(status.Posts.Outbound.Comments),
direction: "outbound",
postType: "comments", postType: "comments",
}, },
} }
for _, m := range metrics { 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 { if err != nil {
return fmt.Errorf("error creating metric for %s: %w", m.desc, err) return fmt.Errorf("error creating metric for %s: %w", m.desc, err)
} }