From a0105de40785c5ee451f512f571cc9ad17ec748b Mon Sep 17 00:00:00 2001 From: hijiki51 Date: Tue, 22 Jun 2021 12:13:51 +0900 Subject: [PATCH] =?UTF-8?q?=E6=AE=8B=E9=AB=98=E3=81=AB=E5=AF=BE=E3=81=99?= =?UTF-8?q?=E3=82=8B=E3=83=A1=E3=83=88=E3=83=AA=E3=82=AF=E3=82=B9=E3=82=92?= =?UTF-8?q?=E8=BF=BD=E5=8A=A0=20(#3)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client.go | 22 ++++++++++++++++++++++ exporter.go | 7 +++++++ 2 files changed, 29 insertions(+) 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