diff --git a/client.go b/client.go index 66a767b..40c5da8 100644 --- a/client.go +++ b/client.go @@ -321,3 +321,25 @@ func (cc *ConohaClient) DatabaseInfo(databaseID string) (*Database, error) { return &uResp.Database, nil } + +//JSON受取用 +type BillingPaymentSummaryResponce struct { + PaymentSummary PaymentSummary `json:"payment_summary"` +} + +type PaymentSummary struct { + Deposit int `json:"total_deposit_amount"` +} + +//入金サマリーの取得 +func (cc *ConohaClient) BillingPaymentSummary() (*PaymentSummary, error) { + resp, _, err := cc.get(cc.accountEndpoint + "/payment-summary") + if err != nil { + return nil, err + } + var uResp BillingPaymentSummaryResponce + if err := json.Unmarshal(resp, &uResp); err != nil { + return nil, err + } + return &uResp.PaymentSummary, nil +} diff --git a/exporter.go b/exporter.go index 8e94912..eb99f86 100644 --- a/exporter.go +++ b/exporter.go @@ -38,6 +38,7 @@ func NewConohaCollector(client *ConohaClient) (*ConohaCollector, error) { prometheus.NewDesc("database_usage", "Usage of Database (GB)", []string{"database"}, nil), prometheus.NewDesc("database_quota", "Database Quota (GB)", []string{"service"}, nil), prometheus.NewDesc("database_total_usage", "Total Database Usage (GB)", []string{"service"}, nil), + prometheus.NewDesc("total_deposit_amount", "Total Deposit Amount", []string{}, nil), }, []prometheus.Metric{}, databases, @@ -93,6 +94,12 @@ func (cc *ConohaCollector) AutoUpdate() { metrics = append(metrics, prometheus.MustNewConstMetric(cc.describes[7], prometheus.GaugeValue, float64(quota.TotalUsage), serviceID)) } + deposit, err := cc.BillingPaymentSummary() + if err != nil { + log.Fatal(err) + } + metrics = append(metrics, prometheus.MustNewConstMetric(cc.describes[8], prometheus.GaugeValue, float64(deposit.Deposit))) + // メトリクスデータ更新 cc.Lock() cc.metrics = metrics