Add posts stats
This commit is contained in:
parent
52d90ca4c1
commit
5770fc2a18
|
@ -65,6 +65,10 @@ 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(
|
||||||
|
metricPrefix+"posts",
|
||||||
|
"Number of posts.",
|
||||||
|
[]string{"direction", "type"}, nil)
|
||||||
usersPending = prometheus.NewDesc(
|
usersPending = prometheus.NewDesc(
|
||||||
metricPrefix+"users_pending",
|
metricPrefix+"users_pending",
|
||||||
"Number of pending users.",
|
"Number of pending users.",
|
||||||
|
@ -113,6 +117,7 @@ func (c *friendicaCollector) Describe(ch chan<- *prometheus.Desc) {
|
||||||
ch <- usersActiveMonth
|
ch <- usersActiveMonth
|
||||||
ch <- usersActiveHalfYear
|
ch <- usersActiveHalfYear
|
||||||
ch <- usersPending
|
ch <- usersPending
|
||||||
|
ch <- posts
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *friendicaCollector) Collect(ch chan<- prometheus.Metric) {
|
func (c *friendicaCollector) Collect(ch chan<- prometheus.Metric) {
|
||||||
|
@ -165,6 +170,10 @@ func readMetrics(ch chan<- prometheus.Metric, status *serverinfo.ServerInfo) err
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if err := collectPosts(ch, status); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -361,3 +370,49 @@ func collectLastExecutions(ch chan<- prometheus.Metric, status *serverinfo.Serve
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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,
|
||||||
|
value: float64(status.Posts.Inbound.Posts),
|
||||||
|
direction: "inbound",
|
||||||
|
postType: "posts",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
desc: posts,
|
||||||
|
value: float64(status.Posts.Inbound.Comments),
|
||||||
|
direction: "inbound",
|
||||||
|
postType: "comments",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
desc: posts,
|
||||||
|
value: float64(status.Posts.Outbound.Posts),
|
||||||
|
direction: "outbound",
|
||||||
|
postType: "posts",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
desc: posts,
|
||||||
|
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)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("error creating metric for %s: %w", m.desc, err)
|
||||||
|
}
|
||||||
|
ch <- metric
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
|
@ -5,6 +5,7 @@ type ServerInfo struct {
|
||||||
Cron Cron `json:"cron"`
|
Cron Cron `json:"cron"`
|
||||||
Worker Worker `json:"worker"`
|
Worker Worker `json:"worker"`
|
||||||
Users Users `json:"users"`
|
Users Users `json:"users"`
|
||||||
|
Posts Posts `json:"posts"`
|
||||||
Packets Packets `json:"packets"`
|
Packets Packets `json:"packets"`
|
||||||
Reports Reports `json:"reports"`
|
Reports Reports `json:"reports"`
|
||||||
Update Update `json:"update"`
|
Update Update `json:"update"`
|
||||||
|
@ -45,7 +46,7 @@ type Worker struct {
|
||||||
LastExecution DateTimeTimestamp `json:"lastExecution"`
|
LastExecution DateTimeTimestamp `json:"lastExecution"`
|
||||||
JPM JPM `json:"jpm"`
|
JPM JPM `json:"jpm"`
|
||||||
Active WorkerCount `json:"active"`
|
Active WorkerCount `json:"active"`
|
||||||
Defferd []int64 `json:"defferd"`
|
Deferred []int64 `json:"deferrd"`
|
||||||
Total WorkerCount `json:"total"`
|
Total WorkerCount `json:"total"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue