Skip to content

Commit

Permalink
残高に対するメトリクスを追加 (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
hijiki51 authored Jun 22, 2021
1 parent 45b9c23 commit a0105de
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
22 changes: 22 additions & 0 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
7 changes: 7 additions & 0 deletions exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit a0105de

Please sign in to comment.