Skip to content

Commit

Permalink
Added Credentials
Browse files Browse the repository at this point in the history
  • Loading branch information
DazWilkin committed Jun 24, 2023
1 parent d7593cc commit 7f5888a
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 0 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ All metric names are prefix `koyeb_`
|Name|Type|Description|
|----|----|-----------|
|`apps_up`|Gauge|1 if the App is up, 0 otherwise|
|`credentials_up`|Gauge|1 if the Credential is up, 0 otherwise|
|`deployments_up`|Gauge|1 if the Deployment is up, 0 otherwise|
|`domains_up`|Gauge|1 if the Domain is up, 0 otherwise|
|`exporter_build_info`|Counter|A metric with a constant '1' value labeled by OS version, Go version, and the Git commit of the exporter|
Expand All @@ -46,6 +47,13 @@ groups:
severity: page
annotations:
summary: "Koyeb Apps ({{ $value }}) up (name: {{ $labels.name }})"
- alert: koyeb_credentials_up
expr: min_over_time(koyeb_credentials_up{}[15m]) > 0
for: 3h
labels:
severity: page
annotations:
summary: "Koyeb Credentials ({{ $value }}) up (name: {{ $labels.name }})"
- alert: koyeb_deployments_up
expr: min_over_time(koyeb_deployments_up{}[15m]) > 0
for: 3h
Expand Down
76 changes: 76 additions & 0 deletions collector/credentials.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package collector

import (
"context"
"log"

"github.com/koyeb/koyeb-api-client-go/api/v1/koyeb"
"github.com/prometheus/client_golang/prometheus"
)

// Ensure that DeploymentCollector implements Prometheus' Collector interface
var _ prometheus.Collector = (*CredentialsCollector)(nil)

// CredentialsCollector collects Koyeb Credentials metrics
type CredentialsCollector struct {
Token string

Up *prometheus.Desc
}

// NewCredentialsCollector is a function that creates a new CredentialsCollector
func NewCredentialsCollector(token string) *CredentialsCollector {
subsystem := "credentials"
return &CredentialsCollector{
Token: token,

Up: prometheus.NewDesc(
prometheus.BuildFQName(namespace, subsystem, "up"),
"1 if the Credentials is up, 0 otherwise",
[]string{
"id",
"organization_id",
"user_id",
"name",
},
nil,
),
}
}

// Collect implements Prometheus' Collector interface and is used to collect metrics
func (c *CredentialsCollector) Collect(ch chan<- prometheus.Metric) {
cfg := koyeb.NewConfiguration()
client := koyeb.NewAPIClient(cfg)

ctx := context.Background()
ctx = context.WithValue(ctx, koyeb.ContextAccessToken, c.Token)

rqst := client.CredentialsApi.ListCredentials(ctx)
resp, _, err := rqst.Execute()
if err != nil {
msg := "unable to list Credentials"
log.Printf(msg, err)
return
}

for _, credential := range resp.Credentials {
ch <- prometheus.MustNewConstMetric(
c.Up,
prometheus.GaugeValue,
1.0,
[]string{
credential.GetId(),
credential.GetOrganizationId(),
credential.GetUserId(),
credential.GetName(),
}...,
)
}

}

// Describe implements Prometheus' Collector interface and is used to describe metrics
func (c *CredentialsCollector) Describe(ch chan<- *prometheus.Desc) {
ch <- c.Up
}
1 change: 1 addition & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ func main() {
registry.MustRegister(collector.NewExporterCollector(OSVersion, GoVersion, GitCommit, StartTime))

registry.MustRegister(collector.NewAppsCollector(token))
registry.MustRegister(collector.NewCredentialsCollector(token))
registry.MustRegister(collector.NewDeploymentsCollector(token))
registry.MustRegister(collector.NewDomainsCollector(token))
registry.MustRegister(collector.NewInstancesCollector(token))
Expand Down

0 comments on commit 7f5888a

Please sign in to comment.