2021-03-05 18:47:23 +00:00
|
|
|
package fetcher
|
|
|
|
|
|
|
|
import (
|
2024-01-17 16:49:34 +00:00
|
|
|
"github.com/hetznercloud/hcloud-go/v2/hcloud"
|
2021-03-05 18:47:23 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var _ Fetcher = &floatingIP{}
|
|
|
|
|
2021-03-05 18:53:37 +00:00
|
|
|
// NewFloatingIP creates a new fetcher that will collect pricing information on floating IPs.
|
2023-01-25 19:24:33 +00:00
|
|
|
func NewFloatingIP(pricing *PriceProvider, additionalLabels ...string) Fetcher {
|
|
|
|
return &floatingIP{newBase(pricing, "floatingip", []string{"location", "type"}, additionalLabels...)}
|
2021-03-05 18:47:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type floatingIP struct {
|
|
|
|
*baseFetcher
|
|
|
|
}
|
|
|
|
|
|
|
|
func (floatingIP floatingIP) Run(client *hcloud.Client) error {
|
2024-01-17 19:19:21 +00:00
|
|
|
floatingIPs, err := client.FloatingIP.All(ctx)
|
2021-03-05 18:47:23 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, f := range floatingIPs {
|
|
|
|
location := f.HomeLocation
|
|
|
|
|
2021-08-24 10:16:03 +00:00
|
|
|
monthlyPrice := floatingIP.pricing.FloatingIP(f.Type, location.Name)
|
2021-03-05 18:47:23 +00:00
|
|
|
hourlyPrice := pricingPerHour(monthlyPrice)
|
|
|
|
|
2023-01-25 19:24:33 +00:00
|
|
|
labels := append([]string{
|
|
|
|
f.Name,
|
|
|
|
location.Name,
|
|
|
|
string(f.Type),
|
|
|
|
},
|
|
|
|
parseAdditionalLabels(floatingIP.additionalLabels, f.Labels)...,
|
|
|
|
)
|
|
|
|
|
|
|
|
floatingIP.hourly.WithLabelValues(labels...).Set(hourlyPrice)
|
|
|
|
floatingIP.monthly.WithLabelValues(labels...).Set(monthlyPrice)
|
2021-03-05 18:47:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|