-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
23 changed files
with
1,467 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,14 @@ | ||
# TOML Document for Cosmos-Validator Exporter(Pometheus & Grafana) | ||
# TOML Document for Terra-Validator Exporter(Pometheus & Grafana) | ||
|
||
title = "Cosmos-Validator Exporter TOML" | ||
network = "cosmos" | ||
title = "TOML Document" | ||
|
||
# RPC-Server | ||
[rpc] | ||
address = "localhost:26657" | ||
[Servers] | ||
[Servers.addr] | ||
rpc = "localhost:26657" | ||
rest = "localhost:1317" | ||
|
||
# Rest-server | ||
[rest_server] | ||
address = "localhost:1317" | ||
[Validator] | ||
operatorAddr = "cosmosvaloper14l0fp639yudfl46zauvv8rkzjgd4u0zk2aseys" | ||
|
||
[validator_info] | ||
operatorAddress = "cosmosvaloper14l0fp639yudfl46zauvv8rkzjgd4u0zk2aseys" | ||
|
||
[option] | ||
exporterListenPort = "26661" | ||
outputPrint = true | ||
[Options] | ||
listenPort = "26661" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package config | ||
|
||
import ( | ||
"log" | ||
// "time" | ||
|
||
"github.com/BurntSushi/toml" | ||
rpc "github.com/node-a-team/cosmos-validator_exporter/getData/rpc" | ||
rest "github.com/node-a-team/cosmos-validator_exporter/getData/rest" | ||
// "github.com/spf13/viper" | ||
) | ||
|
||
const ( | ||
) | ||
|
||
var ( | ||
ConfigPath string | ||
Config configType | ||
) | ||
|
||
|
||
type configType struct { | ||
|
||
Title string `json:"title"` | ||
|
||
Servers struct { | ||
Addr struct { | ||
RPC string `json:"rpc"` | ||
REST string `json:"rest"` | ||
} | ||
} | ||
|
||
Validator struct { | ||
OperatorAddr string `json:"operatorAddr"` | ||
} | ||
|
||
Options struct { | ||
ListenPort string `json:"listenPort"` | ||
} | ||
} | ||
|
||
|
||
func Init() { | ||
|
||
Config = readConfig() | ||
|
||
rpc.Addr = Config.Servers.Addr.RPC | ||
rest.Addr = Config.Servers.Addr.REST | ||
|
||
rest.OperAddr = Config.Validator.OperatorAddr | ||
|
||
} | ||
|
||
func readConfig() configType { | ||
|
||
var config configType | ||
|
||
// path := viper.GetString(ConfigPath)+"/config.toml" | ||
|
||
// if _, err := toml.DecodeFile(path, &config); err != nil{ | ||
if _, err := toml.DecodeFile(ConfigPath +"/config.toml", &config); err != nil{ | ||
|
||
log.Fatal("Config file is missing: ", config) | ||
} | ||
|
||
return config | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,161 @@ | ||
package exporter | ||
|
||
import ( | ||
"fmt" | ||
"time" | ||
"go.uber.org/zap" | ||
|
||
rpc "github.com/node-a-team/cosmos-validator_exporter/getData/rpc" | ||
rest "github.com/node-a-team/cosmos-validator_exporter/getData/rest" | ||
metric "github.com/node-a-team/cosmos-validator_exporter/exporter/metric" | ||
utils "github.com/node-a-team/cosmos-validator_exporter/utils" | ||
|
||
"github.com/prometheus/client_golang/prometheus" | ||
) | ||
|
||
var ( | ||
previousBlockHeight int64 | ||
|
||
) | ||
|
||
func Start(log *zap.Logger) { | ||
|
||
gaugesNamespaceList := metric.GaugesNamespaceList | ||
|
||
var gauges []prometheus.Gauge = make([]prometheus.Gauge, len(gaugesNamespaceList)) | ||
var gaugesDenom []prometheus.Gauge = make([]prometheus.Gauge, len(metric.DenomList)*3) // wallet, rewards, commission | ||
|
||
|
||
// nomal guages | ||
for i := 0; i < len(gaugesNamespaceList); i++ { | ||
gauges[i] = metric.NewGauge("exporter", gaugesNamespaceList[i], "") | ||
prometheus.MustRegister(gauges[i]) | ||
} | ||
|
||
|
||
// denom gagues | ||
count := 0 | ||
for i := 0; i < len(metric.DenomList)*3; i += 3 { | ||
gaugesDenom[i] = metric.NewGauge("exporter_balances", metric.DenomList[count], "") | ||
gaugesDenom[i+1] = metric.NewGauge("exporter_commission", metric.DenomList[count], "") | ||
gaugesDenom[i+2] = metric.NewGauge("exporter_rewards", metric.DenomList[count], "") | ||
prometheus.MustRegister(gaugesDenom[i]) | ||
prometheus.MustRegister(gaugesDenom[i+1]) | ||
prometheus.MustRegister(gaugesDenom[i+2]) | ||
|
||
count++ | ||
} | ||
|
||
|
||
// labels | ||
labels := []string{"chainId", "moniker", "operatorAddress", "accountAddress", "consHexAddress"} | ||
gaugesForLabel := metric.NewCounterVec("exporter", "labels", "", labels) | ||
|
||
prometheus.MustRegister(gaugesForLabel) | ||
|
||
|
||
for { | ||
func() { | ||
defer func() { | ||
|
||
if r := recover(); r != nil { | ||
//Error Log | ||
} | ||
|
||
time.Sleep(500 * time.Millisecond) | ||
|
||
}() | ||
|
||
|
||
currentBlockHeight := rpc.BlockHeight() | ||
|
||
if previousBlockHeight != currentBlockHeight { | ||
|
||
log.Info("RPC-Server", zap.Bool("Success", true), zap.String("err", "nil"), zap.String("Get Data", "Block Height: " +fmt.Sprint(currentBlockHeight))) | ||
|
||
|
||
restData, consHexAddr := rest.GetData(currentBlockHeight, log) | ||
rpcData := rpc.GetData(currentBlockHeight, consHexAddr, log) | ||
|
||
metric.SetMetric(currentBlockHeight, restData, rpcData, log) | ||
|
||
metricData := metric.GetMetric() | ||
denomList := metric.GetDenomList() | ||
|
||
count := 0 | ||
for i := 0; i < len(denomList); i++ { | ||
|
||
for _, value := range metricData.Validator.Account.Balances { | ||
if value.Denom == denomList[i] { | ||
gaugesDenom[count].Set(utils.StringToFloat64(value.Amount)) | ||
count++ | ||
} | ||
} | ||
for _, value := range metricData.Validator.Account.Commission { | ||
if value.Denom == denomList[i] { | ||
gaugesDenom[count].Set(utils.StringToFloat64(value.Amount)) | ||
count++ | ||
} | ||
} | ||
for _, value := range metricData.Validator.Account.Rewards { | ||
if value.Denom == denomList[i] { | ||
gaugesDenom[count].Set(utils.StringToFloat64(value.Amount)) | ||
count++ | ||
} | ||
} | ||
} | ||
|
||
|
||
gaugesValue := [...]float64{ | ||
float64(metricData.Network.BlockHeight), | ||
|
||
metricData.Network.Staking.NotBondedTokens, | ||
metricData.Network.Staking.BondedTokens, | ||
metricData.Network.Staking.TotalSupply, | ||
metricData.Network.Staking.BondedRatio, | ||
|
||
metricData.Network.Gov.TotalProposalCount, | ||
metricData.Network.Gov.VotingProposalCount, | ||
|
||
metricData.Validator.VotingPower, | ||
metricData.Validator.MinSelfDelegation, | ||
metricData.Validator.JailStatus, | ||
|
||
metricData.Validator.Proposer.Ranking, | ||
metricData.Validator.Proposer.Status, | ||
|
||
metricData.Validator.Delegation.Shares, | ||
metricData.Validator.Delegation.Ratio, | ||
metricData.Validator.Delegation.DelegatorCount, | ||
metricData.Validator.Delegation.Self, | ||
|
||
metricData.Validator.Commission.Rate, | ||
metricData.Validator.Commission.MaxRate, | ||
metricData.Validator.Commission.MaxChangeRate, | ||
metricData.Validator.Commit.VoteType, | ||
metricData.Validator.Commit.PrecommitStatus, | ||
|
||
metricData.Network.Minting.Inflation, | ||
metricData.Network.Minting.ActualInflation, | ||
} | ||
|
||
for i := 0; i < len(gaugesNamespaceList); i++ { | ||
gauges[i].Set(gaugesValue[i]) | ||
} | ||
|
||
|
||
gaugesForLabel.WithLabelValues(metricData.Network.ChainID, | ||
metricData.Validator.Moniker, | ||
metricData.Validator.Address.Operator, | ||
metricData.Validator.Address.Account, | ||
metricData.Validator.Address.ConsensusHex, | ||
).Add(0) | ||
|
||
} | ||
|
||
previousBlockHeight = currentBlockHeight | ||
}() | ||
} | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package metric | ||
|
||
import ( | ||
|
||
"fmt" | ||
// "encoding/hex" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
|
||
// "github.com/node-a-team/terra-validator_exporter/getData" | ||
// cfg "github.com/node-a-team/terra-validator_exporter/config" | ||
// utils "github.com/node-a-team/terra-validator_exporter/utils" | ||
) | ||
|
||
var ( | ||
|
||
) | ||
|
||
func GetAccAddrFromOperAddr(operAddr string) string { | ||
|
||
// Get HexAddress | ||
hexAddr, err := sdk.ValAddressFromBech32(operAddr) | ||
if err != nil { | ||
// Error | ||
} | ||
|
||
accAddr, err := sdk.AccAddressFromHex(fmt.Sprint(hexAddr)) | ||
if err != nil { | ||
// Error | ||
} | ||
|
||
return accAddr.String() | ||
} |
Oops, something went wrong.