mirror of
https://github.com/jangraefen/hcloud-pricing-exporter
synced 2024-11-12 23:07:08 +00:00
954c98f013
* feat: Add type label for IPs * Fix tests
35 lines
932 B
Go
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
|
|
}
|