-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathuser.go
More file actions
47 lines (35 loc) · 968 Bytes
/
Copy pathuser.go
File metadata and controls
47 lines (35 loc) · 968 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 userClient interface {
ListUsers(context.Context, client.ListUsersOptions) ([]client.User, *client.Response, error)
}
type userCollector struct {
cl userClient
countDesc *prometheus.Desc
}
func newUserCollector(cl userClient) *userCollector {
return &userCollector{
cl: cl,
countDesc: prometheus.NewDesc("paperless_users",
"Number of users.",
nil, nil),
}
}
func (c *userCollector) describe(ch chan<- *prometheus.Desc) {
ch <- c.countDesc
}
func (c *userCollector) collect(ctx context.Context, ch chan<- prometheus.Metric) error {
_, response, err := c.cl.ListUsers(ctx, client.ListUsersOptions{})
if err != nil {
return err
}
if response.ItemCount != client.ItemCountUnknown {
ch <- prometheus.MustNewConstMetric(c.countDesc, prometheus.GaugeValue,
float64(response.ItemCount))
}
return nil
}