add account balance metric
This commit is contained in:
parent
3850678993
commit
04bb2b9232
|
@ -30,7 +30,7 @@ const (
|
|||
var (
|
||||
// lables
|
||||
commonAccountLabels = []string{"account"}
|
||||
commonHotspotLabels = append([]string{"hotspot"}, commonAccountLabels...)
|
||||
commonHotspotLabels = append(commonAccountLabels, "hotspot", "hotspot_name")
|
||||
|
||||
// exporter metrics
|
||||
|
||||
|
@ -138,7 +138,7 @@ var (
|
|||
accountActivity = metricInfo{
|
||||
prometheus.NewDesc(
|
||||
prometheus.BuildFQName(namespace, "account", "activity_total"),
|
||||
"The total of time an activity occurred in an account.",
|
||||
"The total number of time an activity occurred in an account.",
|
||||
append(commonAccountLabels, "type"), nil,
|
||||
),
|
||||
prometheus.CounterValue,
|
||||
|
@ -259,7 +259,16 @@ func (e *Exporter) collectStatsMetrics(ch chan<- prometheus.Metric) {
|
|||
|
||||
// collectStatsMetrics collect metrics in the account group from the helium api
|
||||
func (e *Exporter) collectAccountMetrics(ch chan<- prometheus.Metric, account string) {
|
||||
fmt.Println(account)
|
||||
accountForAddress, err := heliumapi.GetAccountForAddress(account)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
ch <- prometheus.MustNewConstMetric(
|
||||
accountBalanceHnt.Desc, accountBalanceHnt.Type, float64(accountForAddress.Data.Balance),
|
||||
account,
|
||||
)
|
||||
}
|
||||
|
||||
// NewExporter returns an initialized Exporter
|
||||
|
|
|
@ -0,0 +1,38 @@
|
|||
package heliumapi
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type Account struct {
|
||||
Data struct {
|
||||
Address string `json:"address"`
|
||||
Balance int `json:"balance"`
|
||||
Block int `json:"block"`
|
||||
DCBalance int `json:"dc_balance"`
|
||||
DCNonce int `json:"dc_nonce"`
|
||||
SECBalance int `json:"sec_balance"`
|
||||
SECNonce int `json:"sec_nonce"`
|
||||
SpeculativeNonce int `json:"speculative_nonce"`
|
||||
} `json:"data"`
|
||||
}
|
||||
|
||||
func GetAccountForAddress(account string) (*Account, error) {
|
||||
path := "/v1/accounts/" + account
|
||||
|
||||
// query the api
|
||||
respBody, err := getHeliumApi(path, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// unmarshal the response
|
||||
respobject := Account{}
|
||||
err = json.Unmarshal(respBody, &respobject)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to unmarshal response from path %v: %v", path, err)
|
||||
}
|
||||
|
||||
return &respobject, nil
|
||||
}
|
Reference in New Issue