mirror of
https://github.com/jangraefen/hcloud-pricing-exporter
synced 2024-11-10 05:54:15 +00:00
fca0b5f77b
* added additional tags flag * move additional labels to base fetcher * find label function instead of jump label * bugfix to labels not correctly set when -additional-labels flag not present * check for more than 0, instead of 1
43 lines
1.1 KiB
Go
43 lines
1.1 KiB
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, additionalLabels ...string) Fetcher {
|
|
return &floatingIP{newBase(pricing, "floatingip", []string{"location", "type"}, additionalLabels...)}
|
|
}
|
|
|
|
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)
|
|
|
|
labels := append([]string{
|
|
f.Name,
|
|
location.Name,
|
|
string(f.Type),
|
|
},
|
|
parseAdditionalLabels(floatingIP.additionalLabels, f.Labels)...,
|
|
)
|
|
|
|
floatingIP.hourly.WithLabelValues(labels...).Set(hourlyPrice)
|
|
floatingIP.monthly.WithLabelValues(labels...).Set(monthlyPrice)
|
|
}
|
|
|
|
return nil
|
|
}
|