mirror of
https://github.com/jangraefen/hcloud-pricing-exporter
synced 2024-11-10 05:54:15 +00:00
39 lines
770 B
Go
39 lines
770 B
Go
|
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
|
||
|
}
|