-
Notifications
You must be signed in to change notification settings - Fork 0
/
process.go
82 lines (67 loc) · 1.95 KB
/
process.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package main
import (
"log"
"strconv"
"github.com/bidease/scomportal"
)
func getBaremetalHostsTotal(api *scomportal.API) {
if equipment, err := api.GetBaremetalEquipment(); err == nil {
baremetalHostsTotal.Set(float64(equipment.Data.Equipment.Hosts))
} else {
log.Println(err)
}
}
func getBaremetalBalance(api *scomportal.API) {
balances, err := api.GetBaremetalBalance()
if err != nil {
log.Fatalln(err)
}
balance, _ := strconv.ParseFloat(balances.Data.Balance, 64)
baremetalBalance.Set(balance)
estimatedBalance, _ := strconv.ParseFloat(balances.Data.EstimatedBalance, 64)
baremetalEstimatedBalance.Set(estimatedBalance)
}
func getHostMetrics(api *scomportal.API) {
hosts, err := api.GetBaremetalHosts()
if err != nil {
log.Fatalln(err)
}
for _, host := range hosts.Data {
hostDetail, err := api.GetBaremetalHost(host.ID)
if err != nil {
log.Println(err)
continue
}
if hostDetail.Data.HasDRAC {
switch hostDetail.Data.TemporaryDracAccess {
case "enabled":
baremetalHostDRACEnabled.WithLabelValues(host.Title).Set(1)
case "disabled":
baremetalHostDRACEnabled.WithLabelValues(host.Title).Set(0)
}
}
if hostDetail.Data.OSReinstallation {
baremetalHostOSReinstallation.WithLabelValues(host.Title).Set(1)
} else {
baremetalHostOSReinstallation.WithLabelValues(host.Title).Set(0)
}
traffic, err := api.GetBaremetalHostTraffic(host.ID)
if err != nil {
log.Println(err)
continue
}
usageTraffic, _ := strconv.ParseFloat(traffic.Data.Commit.UsageQuantity, 64)
baremetalHostUsageTraffic.WithLabelValues(host.Title).Set(usageTraffic)
baremetalHostBillingPeriodTraffic.WithLabelValues(host.Title).Set(traffic.Data.Commit.CommitValueForBillingPeriod)
services, err := api.GetServices(host.ID)
if err != nil {
log.Println(err)
continue
}
var price float64
for _, v := range services.Data {
price = price + v.Price
}
baremetalHostPrice.WithLabelValues(host.Title).Set(price)
}
}