hcloud-pricing-exporter/fetcher/floatingip.go

36 lines
932 B
Go
Raw Normal View History

2021-03-05 18:47:23 +00:00
package fetcher
import (
"github.com/hetznercloud/hcloud-go/hcloud"
)
var _ Fetcher = &floatingIP{}
2021-03-05 18:53:37 +00:00
// NewFloatingIP creates a new fetcher that will collect pricing information on floating IPs.
2021-03-05 19:28:17 +00:00
func NewFloatingIP(pricing *PriceProvider) Fetcher {
return &floatingIP{newBase(pricing, "floatingip", "location", "type")}
2021-03-05 18:47:23 +00:00
}
type floatingIP struct {
*baseFetcher
}
func (floatingIP floatingIP) Run(client *hcloud.Client) error {
floatingIPs, _, err := client.FloatingIP.List(ctx, hcloud.FloatingIPListOpts{})
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)
floatingIP.hourly.WithLabelValues(f.Name, location.Name, string(f.Type)).Set(hourlyPrice)
floatingIP.monthly.WithLabelValues(f.Name, location.Name, string(f.Type)).Set(monthlyPrice)
2021-03-05 18:47:23 +00:00
}
return nil
}