-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathgroup.go
More file actions
47 lines (35 loc) · 989 Bytes
/
group.go
File metadata and controls
47 lines (35 loc) · 989 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package main
import (
"context"
"github.com/hansmi/paperhooks/pkg/client"
"github.com/prometheus/client_golang/prometheus"
)
type groupClient interface {
ListGroups(context.Context, client.ListGroupsOptions) ([]client.Group, *client.Response, error)
}
type groupCollector struct {
cl groupClient
countDesc *prometheus.Desc
}
func newGroupCollector(cl groupClient) *groupCollector {
return &groupCollector{
cl: cl,
countDesc: prometheus.NewDesc("paperless_groups",
"Number of user groups.",
nil, nil),
}
}
func (c *groupCollector) describe(ch chan<- *prometheus.Desc) {
ch <- c.countDesc
}
func (c *groupCollector) collect(ctx context.Context, ch chan<- prometheus.Metric) error {
_, response, err := c.cl.ListGroups(ctx, client.ListGroupsOptions{})
if err != nil {
return err
}
if response.ItemCount != client.ItemCountUnknown {
ch <- prometheus.MustNewConstMetric(c.countDesc, prometheus.GaugeValue,
float64(response.ItemCount))
}
return nil
}