hcloud-pricing-exporter/fetcher/floatingip.go
Jan Gräfen 954c98f013
feat: Add type label for IPs (#41)
* feat: Add type label for IPs
* Fix tests
2022-12-29 15:58:04 +01:00

35 lines
932 B
Go

package fetcher
import (
"github.com/hetznercloud/hcloud-go/hcloud"
)
var _ Fetcher = &floatingIP{}
// NewFloatingIP creates a new fetcher that will collect pricing information on floating IPs.
func NewFloatingIP(pricing *PriceProvider) Fetcher {
return &floatingIP{newBase(pricing, "floatingip", "location", "type")}
}
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
monthlyPrice := floatingIP.pricing.FloatingIP(f.Type, location.Name)
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)
}
return nil
}