/
account.go
75 lines (65 loc) · 1.99 KB
/
account.go
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package collector
import (
"context"
"log"
"github.com/linode/linodego"
"github.com/prometheus/client_golang/prometheus"
)
// AccountCollector represents a Linode Account
type AccountCollector struct {
client linodego.Client
Balance *prometheus.Desc
// Uninvoiced *prometheus.Desc
}
// NewAccountCollector creates an AccountCollector
func NewAccountCollector(client linodego.Client) *AccountCollector {
log.Println("[NewAccountCollector] Entered")
subsystem := "account"
labelKeys := []string{"company", "email"}
return &AccountCollector{
client: client,
Balance: prometheus.NewDesc(
prometheus.BuildFQName(namespace, subsystem, "balance"),
"Balance of account",
labelKeys,
nil,
),
// Uninvoiced: prometheus.NewDesc(
// prometheus.BuildFQName(namespace, subsystem, "uninvoiced"),
// "Uninvoiced balance of account",
// labelKeys,
// nil,
// ),
}
}
// Collect implements Collector interface and is called by Prometheus to collect metrics
func (c *AccountCollector) Collect(ch chan<- prometheus.Metric) {
log.Println("[AccountCollector:Collect] Entered")
ctx := context.Background()
account, err := c.client.GetAccount(ctx)
if err != nil {
log.Println(err)
}
ch <- prometheus.MustNewConstMetric(
c.Balance,
prometheus.GaugeValue,
float64(account.Balance),
[]string{account.Company, account.Email}...,
)
//TODO(dazwilkin) UnvoicedBalance is not yet implemented by the SDK
// https://github.com/linode/linodego/issues/108
// ch <- prometheus.MustNewConstMetric(
// c.Uninvoiced,
// prometheus.GaugeValue,
// float64(account.BalanceUninvoiced),
// []string{account.Company, account.Email}...,
// )
log.Println("[AccountCollector:Collect] Completes")
}
// Describe implements Collector interface and is called by Prometheus to describe metrics
func (c *AccountCollector) Describe(ch chan<- *prometheus.Desc) {
log.Println("[AccountCollector:Describe] Entered")
ch <- c.Balance
// ch <- c.Uninvoiced
log.Println("[AccountCollector:Describe] Completes")
}