hcloud-pricing-exporter/fetcher/floatingip.go

39 lines
770 B
Go
Raw Normal View History

2021-03-05 18:47:23 +00:00
package fetcher
import (
"github.com/hetznercloud/hcloud-go/hcloud"
)
const (
floatingIPPrice = float64(1.19)
)
var _ Fetcher = &floatingIP{}
func NewFloatingIP() Fetcher {
return &floatingIP{new("floatingip", "location")}
}
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 := floatingIPPrice
hourlyPrice := pricingPerHour(monthlyPrice)
floatingIP.hourly.WithLabelValues(f.Name, location.Name).Set(hourlyPrice)
floatingIP.monthly.WithLabelValues(f.Name, location.Name).Set(monthlyPrice)
}
return nil
}