Skip to content

Commit a3fa150

Browse files
committed
improve error handling
1 parent f57f4d8 commit a3fa150

File tree

1 file changed

+25
-21
lines changed

1 file changed

+25
-21
lines changed

exporter.go

+25-21
Original file line numberDiff line numberDiff line change
@@ -52,23 +52,24 @@ func (cc *ConohaCollector) AutoUpdate() {
5252
// オブジェクトストレージへのリクエスト数を取得
5353
requests, err := cc.ObjectStorageRequests()
5454
if err != nil {
55-
log.Fatal(err)
55+
log.Printf("ObjectStorageRequests error: %v\n", err)
56+
} else {
57+
metrics = append(metrics, prometheus.MustNewConstMetric(cc.describes[0], prometheus.GaugeValue, requests["get"], "get"))
58+
metrics = append(metrics, prometheus.MustNewConstMetric(cc.describes[0], prometheus.GaugeValue, requests["put"], "put"))
59+
metrics = append(metrics, prometheus.MustNewConstMetric(cc.describes[0], prometheus.GaugeValue, requests["delete"], "delete"))
5660
}
57-
metrics = append(metrics, prometheus.MustNewConstMetric(cc.describes[0], prometheus.GaugeValue, requests["get"], "get"))
58-
metrics = append(metrics, prometheus.MustNewConstMetric(cc.describes[0], prometheus.GaugeValue, requests["put"], "put"))
59-
metrics = append(metrics, prometheus.MustNewConstMetric(cc.describes[0], prometheus.GaugeValue, requests["delete"], "delete"))
6061

6162
// オブジェクトストレージ使用容量を取得
6263
usage, err := cc.ObjectStorageUsage()
6364
if err != nil {
64-
log.Fatal(err)
65-
}
66-
metrics = append(metrics, prometheus.MustNewConstMetric(cc.describes[1], prometheus.GaugeValue, usage.quota))
67-
metrics = append(metrics, prometheus.MustNewConstMetric(cc.describes[2], prometheus.GaugeValue, usage.totalUsage))
68-
69-
for _, container := range usage.containers {
70-
metrics = append(metrics, prometheus.MustNewConstMetric(cc.describes[3], prometheus.GaugeValue, float64(container.Bytes), container.Name))
71-
metrics = append(metrics, prometheus.MustNewConstMetric(cc.describes[4], prometheus.GaugeValue, float64(container.Count), container.Name))
65+
log.Printf("ObjectStorageUsage error: %v\n", err)
66+
} else {
67+
metrics = append(metrics, prometheus.MustNewConstMetric(cc.describes[1], prometheus.GaugeValue, usage.quota))
68+
metrics = append(metrics, prometheus.MustNewConstMetric(cc.describes[2], prometheus.GaugeValue, usage.totalUsage))
69+
for _, container := range usage.containers {
70+
metrics = append(metrics, prometheus.MustNewConstMetric(cc.describes[3], prometheus.GaugeValue, float64(container.Bytes), container.Name))
71+
metrics = append(metrics, prometheus.MustNewConstMetric(cc.describes[4], prometheus.GaugeValue, float64(container.Count), container.Name))
72+
}
7273
}
7374

7475
serviceIDs := make(map[string]bool)
@@ -77,28 +78,31 @@ func (cc *ConohaCollector) AutoUpdate() {
7778
// データベース使用状況を取得
7879
info, err := cc.DatabaseInfo(db.DatabaseID)
7980
if err != nil {
80-
log.Fatal(err)
81-
}
82-
metrics = append(metrics, prometheus.MustNewConstMetric(cc.describes[5], prometheus.GaugeValue, info.DbSize, db.DbName))
81+
log.Printf("DatabaseInfo(%s) error: %v\n", db.DatabaseID, err)
82+
} else {
83+
metrics = append(metrics, prometheus.MustNewConstMetric(cc.describes[5], prometheus.GaugeValue, info.DbSize, db.DbName))
8384

84-
serviceIDs[db.ServiceID] = true
85+
serviceIDs[db.ServiceID] = true
86+
}
8587
}
8688

8789
for serviceID := range serviceIDs {
8890
// データベース上限値/合計使用量取得
8991
quota, err := cc.DatabaseQuota(serviceID)
9092
if err != nil {
91-
log.Fatal(err)
93+
log.Printf("DatabaseQuota(%s) error: %v\n", serviceID, err)
94+
} else {
95+
metrics = append(metrics, prometheus.MustNewConstMetric(cc.describes[6], prometheus.GaugeValue, float64(quota.Quota), serviceID))
96+
metrics = append(metrics, prometheus.MustNewConstMetric(cc.describes[7], prometheus.GaugeValue, float64(quota.TotalUsage), serviceID))
9297
}
93-
metrics = append(metrics, prometheus.MustNewConstMetric(cc.describes[6], prometheus.GaugeValue, float64(quota.Quota), serviceID))
94-
metrics = append(metrics, prometheus.MustNewConstMetric(cc.describes[7], prometheus.GaugeValue, float64(quota.TotalUsage), serviceID))
9598
}
9699

97100
deposit, err := cc.BillingPaymentSummary()
98101
if err != nil {
99-
log.Fatal(err)
102+
log.Printf("BillingPaymentSumarry error: %v\n", err)
103+
} else {
104+
metrics = append(metrics, prometheus.MustNewConstMetric(cc.describes[8], prometheus.GaugeValue, float64(deposit.Deposit)))
100105
}
101-
metrics = append(metrics, prometheus.MustNewConstMetric(cc.describes[8], prometheus.GaugeValue, float64(deposit.Deposit)))
102106

103107
// メトリクスデータ更新
104108
cc.Lock()

0 commit comments

Comments
 (0)