Skip to content

Commit

Permalink
add object_storage_total_usage
Browse files Browse the repository at this point in the history
  • Loading branch information
sapphi-red committed Feb 28, 2021
1 parent 9890cda commit 7ff4e19
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
15 changes: 11 additions & 4 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,9 @@ type Container struct {
}

type ObjectStorageUsage struct {
containers []Container
quota float64
containers []Container
quota float64
total_usage float64
}

// オブジェクトストレージの使用容量を取得
Expand All @@ -221,9 +222,15 @@ func (cc *ConohaClient) ObjectStorageUsage() (*ObjectStorageUsage, error) {
return nil, err
}

total_usage, err := strconv.ParseFloat(headers.Get("X-Account-Bytes-Used"), 64)
if err != nil {
return nil, err
}

return &ObjectStorageUsage{
containers: uResp,
quota: quota,
containers: uResp,
quota: quota,
total_usage: total_usage,
}, nil
}

Expand Down
12 changes: 7 additions & 5 deletions exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ func NewConohaCollector(client *ConohaClient) (*ConohaCollector, error) {
// 4番目のnilには、固定ラベルをprometheus.Labelsで渡せる
prometheus.NewDesc("object_storage_requests", "Requests to Object Storage", []string{"method"}, nil),
prometheus.NewDesc("object_storage_quota", "Object Storage Quota", []string{}, nil),
prometheus.NewDesc("object_storage_total_usage", "Total Object Storage Usage", []string{}, nil),
prometheus.NewDesc("object_storage_usage", "Usage of Object Storage", []string{"container"}, nil),
prometheus.NewDesc("object_storage_count", "Object Counts of Object Storage", []string{"container"}, nil),
prometheus.NewDesc("database_usage", "Usage of Database (GB)", []string{"database"}, nil),
Expand Down Expand Up @@ -62,10 +63,11 @@ func (cc *ConohaCollector) AutoUpdate() {
log.Fatal(err)
}
metrics = append(metrics, prometheus.MustNewConstMetric(cc.describes[1], prometheus.GaugeValue, usage.quota))
metrics = append(metrics, prometheus.MustNewConstMetric(cc.describes[2], prometheus.GaugeValue, usage.total_usage))

for _, container := range usage.containers {
metrics = append(metrics, prometheus.MustNewConstMetric(cc.describes[2], prometheus.GaugeValue, float64(container.Bytes), container.Name))
metrics = append(metrics, prometheus.MustNewConstMetric(cc.describes[3], prometheus.GaugeValue, float64(container.Count), container.Name))
metrics = append(metrics, prometheus.MustNewConstMetric(cc.describes[3], prometheus.GaugeValue, float64(container.Bytes), container.Name))
metrics = append(metrics, prometheus.MustNewConstMetric(cc.describes[4], prometheus.GaugeValue, float64(container.Count), container.Name))
}

serviceIDs := make(map[string]bool)
Expand All @@ -76,7 +78,7 @@ func (cc *ConohaCollector) AutoUpdate() {
if err != nil {
log.Fatal(err)
}
metrics = append(metrics, prometheus.MustNewConstMetric(cc.describes[4], prometheus.GaugeValue, info.DbSize, db.DbName))
metrics = append(metrics, prometheus.MustNewConstMetric(cc.describes[5], prometheus.GaugeValue, info.DbSize, db.DbName))

serviceIDs[db.ServiceID] = true
}
Expand All @@ -87,8 +89,8 @@ func (cc *ConohaCollector) AutoUpdate() {
if err != nil {
log.Fatal(err)
}
metrics = append(metrics, prometheus.MustNewConstMetric(cc.describes[5], prometheus.GaugeValue, float64(quota.Quota), serviceID))
metrics = append(metrics, prometheus.MustNewConstMetric(cc.describes[6], prometheus.GaugeValue, float64(quota.TotalUsage), serviceID))
metrics = append(metrics, prometheus.MustNewConstMetric(cc.describes[6], prometheus.GaugeValue, float64(quota.Quota), serviceID))
metrics = append(metrics, prometheus.MustNewConstMetric(cc.describes[7], prometheus.GaugeValue, float64(quota.TotalUsage), serviceID))
}

// メトリクスデータ更新
Expand Down

0 comments on commit 7ff4e19

Please sign in to comment.