Skip to content

Commit

Permalink
Merge pull request #19 from ekeih/feature-server-pricing-vat
Browse files Browse the repository at this point in the history
Export net and gross values for hcloud_server_price_* metrics
  • Loading branch information
tboerger authored Mar 12, 2019
2 parents 92b266c + 7fd6ad5 commit 2e03569
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 8 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## [1.0.0] - 2019-03-12

### Added

* Added a `vat` label (`gross` or `net`) to the `hcloud_server_price` metric. Depending on the setup this can be a breaking change and it may be necessary to adjust some dashboards and alerting rules.

## [0.2.0] - 2019-03-11

### Added
Expand Down
36 changes: 28 additions & 8 deletions pkg/exporter/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ func NewServerCollector(logger log.Logger, client *hcloud.Client, failures *prom
failures.WithLabelValues("server").Add(0)

labels := []string{"id", "name", "datacenter"}
pricingLabels := append(labels, "vat")
return &ServerCollector{
client: client,
logger: log.With(logger, "collector", "server"),
Expand Down Expand Up @@ -101,13 +102,13 @@ func NewServerCollector(logger log.Logger, client *hcloud.Client, failures *prom
PriceHourly: prometheus.NewDesc(
"hcloud_server_price_hourly",
"Price of the server billed hourly in €",
labels,
pricingLabels,
nil,
),
PriceMonthly: prometheus.NewDesc(
"hcloud_server_price_monthly",
"Price of the server billed monthly in €",
labels,
pricingLabels,
nil,
),
}
Expand Down Expand Up @@ -235,24 +236,43 @@ func (c *ServerCollector) Collect(ch chan<- prometheus.Metric) {
labels...,
)

labelsNet := append(labels, "net")
labelsGross := append(labels, "gross")

for _, pricing := range server.ServerType.Pricings {
if server.Datacenter.Location.Name == pricing.Location.Name {
hourly, _ := strconv.ParseFloat(pricing.Hourly.Net, 64)
hourlyNet, _ := strconv.ParseFloat(pricing.Hourly.Net, 64)
hourlyGross, _ := strconv.ParseFloat(pricing.Hourly.Gross, 64)

ch <- prometheus.MustNewConstMetric(
c.PriceHourly,
prometheus.GaugeValue,
hourly,
labels...,
hourlyNet,
labelsNet...,
)

monthly, _ := strconv.ParseFloat(pricing.Monthly.Net, 64)
ch <- prometheus.MustNewConstMetric(
c.PriceHourly,
prometheus.GaugeValue,
hourlyGross,
labelsGross...,
)

monthlyNet, _ := strconv.ParseFloat(pricing.Monthly.Net, 64)
monthlyGross, _ := strconv.ParseFloat(pricing.Monthly.Gross, 64)

ch <- prometheus.MustNewConstMetric(
c.PriceMonthly,
prometheus.GaugeValue,
monthlyNet,
labelsNet...,
)

ch <- prometheus.MustNewConstMetric(
c.PriceMonthly,
prometheus.GaugeValue,
monthly,
labels...,
monthlyGross,
labelsGross...,
)
}
}
Expand Down

0 comments on commit 2e03569

Please sign in to comment.