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

feat(metrics): dedicated server subscription expiration timestamp #15

Merged
merged 1 commit into from
Dec 30, 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
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