diff --git a/README.md b/README.md index b427b40..0a5c279 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,6 @@ ENDPOINT=":9388" METRICS="/metrics" go run github.com/DazWilkin/linode-exporter \ ---linode_token=${LINODE_TOKEN} \ --endpoint=${ENDPOINT} \ --path=${METRICS} ``` @@ -42,9 +41,9 @@ PORT=9388 docker run \ --interactive \ --tty \ +-e LINODE_TOKEN=${LINODE_TOKEN} \ --publish=${PORT}:${PORT} \ -ghcr.io/dazwilkin/linode-exporter:8a9d5c965b8c8474dd59c166c66dbe9f78f0fde2 \ - --linode_token=${LINODE_TOKEN} +ghcr.io/dazwilkin/linode-exporter:b4e6fabbbd64132b4f08a164cfc42365ae859d50 ``` The exporter's metrics endpoint will be available on `http://localhost:${PORT}/metrics` @@ -53,7 +52,7 @@ The exporter's metrics endpoint will be available on `http://localhost:${PORT}/m **NB** AlertManager integration is a work-in-progress -The following +The following ```bash LINODE_TOKEN=[[LINODE-API-TOKEN]] docker-compose --file=${PWD}/docker-compose.yaml up @@ -70,7 +69,7 @@ The following endpoints are exposed: + Linode-Exporter metrics: `http://localhost:9388/metrics` + Prometheus UI: `http://localhost:9090` + AlertManager UI: `http://localhost:9093` -+ cAdvisor UI: `http://localhost:8085` ++ cAdvisor UI: `http://localhost:8085` **NB** cAdvisor is mapped to `:8085` rather than it's default port `:8080` @@ -144,4 +143,4 @@ go install github.com/sigstore/cosign/cmd/cosign@latest

-Buy Me A Coffee \ No newline at end of file +Buy Me A Coffee diff --git a/collector/account.go b/collector/account.go index 01c3319..37dbf22 100644 --- a/collector/account.go +++ b/collector/account.go @@ -12,8 +12,8 @@ import ( type AccountCollector struct { client linodego.Client - Balance *prometheus.Desc - // Uninvoiced *prometheus.Desc + Balance *prometheus.Desc + Uninvoiced *prometheus.Desc } // NewAccountCollector creates an AccountCollector @@ -30,12 +30,12 @@ func NewAccountCollector(client linodego.Client) *AccountCollector { labelKeys, nil, ), - // Uninvoiced: prometheus.NewDesc( - // prometheus.BuildFQName(namespace, subsystem, "uninvoiced"), - // "Uninvoiced balance of account", - // labelKeys, - // nil, - // ), + Uninvoiced: prometheus.NewDesc( + prometheus.BuildFQName(namespace, subsystem, "uninvoiced"), + "Uninvoiced balance of account", + labelKeys, + nil, + ), } } @@ -56,14 +56,12 @@ func (c *AccountCollector) Collect(ch chan<- prometheus.Metric) { 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}..., - // ) + ch <- prometheus.MustNewConstMetric( + c.Uninvoiced, + prometheus.GaugeValue, + float64(account.BalanceUninvoiced), + []string{account.Company, account.Email}..., + ) log.Println("[AccountCollector:Collect] Completes") } @@ -71,6 +69,6 @@ func (c *AccountCollector) Collect(ch chan<- prometheus.Metric) { func (c *AccountCollector) Describe(ch chan<- *prometheus.Desc) { log.Println("[AccountCollector:Describe] Entered") ch <- c.Balance - // ch <- c.Uninvoiced + ch <- c.Uninvoiced log.Println("[AccountCollector:Describe] Completes") } diff --git a/collector/kubernetes.go b/collector/kubernetes.go index 908c1fd..1b879b3 100644 --- a/collector/kubernetes.go +++ b/collector/kubernetes.go @@ -71,7 +71,7 @@ func (c *KubernetesCollector) Collect(ch chan<- prometheus.Metric) { // Label Values strconv.Itoa(k.ID), k.Label, k.Region, k.K8sVersion, ) - pools, err := c.client.ListLKEClusterPools(ctx, k.ID, nil) + pools, err := c.client.ListLKENodePools(ctx, k.ID, nil) if err != nil { log.Println(err) return @@ -80,7 +80,7 @@ func (c *KubernetesCollector) Collect(ch chan<- prometheus.Metric) { for _, pool := range pools { wg.Add(1) - go func(p linodego.LKEClusterPool) { + go func(p linodego.LKENodePool) { defer wg.Done() ch <- prometheus.MustNewConstMetric( c.Pool, diff --git a/collector/ticket.go b/collector/ticket.go index 50d70a1..0f6f5c7 100644 --- a/collector/ticket.go +++ b/collector/ticket.go @@ -2,7 +2,6 @@ package collector import ( "context" - "fmt" "log" "github.com/linode/linodego" @@ -54,7 +53,7 @@ func (c *TicketCollector) Collect(ch chan<- prometheus.Metric) { prometheus.GaugeValue, count, // linodego.TicketStatus needs a String() method ;-) - []string{fmt.Sprintf("%s", status)}..., + []string{string(status)}..., //[]string{status.String()}..., ) } diff --git a/docker-compose.yaml b/docker-compose.yaml index 770866b..445c7cb 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -48,8 +48,6 @@ services: linode-exporter: image: ghcr.io/dazwilkin/linode-exporter:${TAG} container_name: linode-exporter - command: - - --linode_token=${LINODE_TOKEN} expose: - "9388" # Linode Exporter port registered on Prometheus Wiki ports: diff --git a/go.mod b/go.mod index f7a677c..32ece21 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/DazWilkin/linode-exporter go 1.21.0 require ( - github.com/linode/linodego v1.28.0 + github.com/linode/linodego v1.29.0 github.com/prometheus/client_golang v1.18.0 golang.org/x/oauth2 v0.17.0 ) diff --git a/go.sum b/go.sum index 50222dd..a7202eb 100644 --- a/go.sum +++ b/go.sum @@ -13,8 +13,8 @@ github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiu github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= -github.com/linode/linodego v1.28.0 h1:lzxxJebsYg5cCWRNDLyL2StW3sfMyAwf/FYfxFjFrlk= -github.com/linode/linodego v1.28.0/go.mod h1:5oAsx+uinHtVo6U77nXXXtox7MWzUW6aEkTOKXxA9uo= +github.com/linode/linodego v1.29.0 h1:gDSQWAbKMAQX8db9FDCXHhodQPrJmLcmthjx6m+PyV4= +github.com/linode/linodego v1.29.0/go.mod h1:3k6WvCM10gillgYcnoLqIL23ST27BD9HhMsCJWb3Bpk= github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0 h1:jWpvCLoY8Z/e3VKvlsiIGKtc+UG6U5vzxaoagmhXfyg= github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0/go.mod h1:QUyp042oQthUoa9bqDv0ER0wrtXnBruoNd7aNjkbP+k= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= diff --git a/main.go b/main.go index d3b61f0..7a45a85 100644 --- a/main.go +++ b/main.go @@ -5,6 +5,7 @@ import ( "fmt" "log" "net/http" + "os" "time" "github.com/DazWilkin/linode-exporter/collector" @@ -28,7 +29,7 @@ var ( OSVersion string ) var ( - token = flag.String("linode_token", "", "Linode API Token") + token = flag.String("linode_token", os.Getenv("LINODE_TOKEN"), "Linode API Token") debug = flag.Bool("debug", false, "Enable Linode REST API debugging") endpoint = flag.String("endpoint", ":9388", "The endpoint of the HTTP server") metricsPath = flag.String("path", "/metrics", "The path on which Prometheus metrics will be served")