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",
"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) {
@ -374,40 +379,35 @@ func collectLastExecutions(ch chan<- prometheus.Metric, status *serverinfo.Serve
type postMetric struct {
desc *prometheus.Desc
value float64
direction string
postType string
}
func collectPosts(ch chan<- prometheus.Metric, status *serverinfo.ServerInfo) error {
metrics := []postMetric{
{
desc: posts,
desc: postsInbound,
value: float64(status.Posts.Inbound.Posts),
direction: "inbound",
postType: "posts",
},
{
desc: posts,
desc: postsInbound,
value: float64(status.Posts.Inbound.Comments),
direction: "inbound",
postType: "comments",
},
{
desc: posts,
desc: postsOutbound,
value: float64(status.Posts.Outbound.Posts),
direction: "outbound",
postType: "posts",
},
{
desc: posts,
desc: postsOutbound,
value: float64(status.Posts.Outbound.Comments),
direction: "outbound",
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)
}