Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

General update #42

Merged
merged 6 commits into from
Feb 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ ENDPOINT=":9388"
METRICS="/metrics"

go run github.com/DazWilkin/linode-exporter \
--linode_token=${LINODE_TOKEN} \
--endpoint=${ENDPOINT} \
--path=${METRICS}
```
Expand All @@ -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`
Expand All @@ -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
Expand All @@ -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`

Expand Down Expand Up @@ -144,4 +143,4 @@ go install github.com/sigstore/cosign/cmd/cosign@latest

<hr/>
<br/>
<a href="https://www.buymeacoffee.com/dazwilkin" target="_blank"><img src="https://cdn.buymeacoffee.com/buttons/default-orange.png" alt="Buy Me A Coffee" height="41" width="174"></a>
<a href="https://www.buymeacoffee.com/dazwilkin" target="_blank"><img src="https://cdn.buymeacoffee.com/buttons/default-orange.png" alt="Buy Me A Coffee" height="41" width="174"></a>
32 changes: 15 additions & 17 deletions collector/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
),
}
}

Expand All @@ -56,21 +56,19 @@ 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")
}

// 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
ch <- c.Uninvoiced
log.Println("[AccountCollector:Describe] Completes")
}
4 changes: 2 additions & 2 deletions collector/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand Down
3 changes: 1 addition & 2 deletions collector/ticket.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package collector

import (
"context"
"fmt"
"log"

"github.com/linode/linodego"
Expand Down Expand Up @@ -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()}...,
)
}
Expand Down
2 changes: 0 additions & 2 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
3 changes: 2 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"log"
"net/http"
"os"
"time"

"github.com/DazWilkin/linode-exporter/collector"
Expand All @@ -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")
Expand Down