Skip to content

Commit

Permalink
feat(metrics): dedicated server subscription expiration timestamp (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
maxime1907 authored Dec 30, 2024
1 parent ac00a6d commit 4c32a10
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
2 changes: 2 additions & 0 deletions pkg/network/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,15 @@ func pingHandler(w http.ResponseWriter, req *http.Request) {
func initializeMetrics() {
prometheus.MustRegister(cloudProjectInstanceBilling)
prometheus.MustRegister(dedicatedServerSubscription)
prometheus.MustRegister(dedicatedServerSubscriptionExpirationTimestamp)
}

func updateMetrics(ovhClient *ovh.Client) {
cloudProjectInstanceBilling.Reset()
updateCloudProviderInstanceBilling(ovhClient)

dedicatedServerSubscription.Reset()
dedicatedServerSubscriptionExpirationTimestamp.Reset()
updateDedicatedServersSubscription(ovhClient)
}

Expand Down
15 changes: 15 additions & 0 deletions pkg/network/serve_dedicated_server_subscription.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,20 @@ var dedicatedServerSubscription = prometheus.NewGaugeVec(
[]string{"server_id", "status", "creation", "expiration", "engaged_up_to", "renewal_type", "renew_automatic", "renew_period", "renew_manual_payment", "renew_forced", "renew_delete_at_expiration"},
)

var dedicatedServerSubscriptionExpirationTimestamp = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Name: "ovh_exporter_dedicated_server_subscription_expiration_timestamp",
Help: "Tracks the subscription expiration for OVH dedicated servers.",
},
[]string{"server_id"},
)

func setDedicatedServerSubscriptionExpirationTimestamp(server models.Server, amount float64) {
dedicatedServerSubscriptionExpirationTimestamp.With(prometheus.Labels{
"server_id": server.ID,
}).Set(amount)
}

func setDedicatedServerSubscription(server models.Server, serviceinfos models.ServiceInfo, amount float64) {
renewAutomatic := false
if serviceinfos.Renew != nil {
Expand Down Expand Up @@ -74,6 +88,7 @@ func updateDedicatedServerSubscription(ovhClient *ovh.Client, server models.Serv
}

setDedicatedServerSubscription(server, serviceInfos, 1)
setDedicatedServerSubscriptionExpirationTimestamp(server, float64(serviceInfos.Expiration.Unix()))
}

func updateDedicatedServersSubscription(ovhClient *ovh.Client) {
Expand Down

0 comments on commit 4c32a10

Please sign in to comment.