-
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
13 changed files
with
265 additions
and
13 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
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
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,67 @@ | ||
package commit | ||
|
||
import ( | ||
t "github.com/node-a-team/cosmos-validator_exporter/types" | ||
|
||
"encoding/json" | ||
"fmt" | ||
// "os/exec" | ||
) | ||
|
||
func CommitStatus(blockHeight int) t.CommitStatus { | ||
|
||
var commitStatus t.CommitStatus | ||
|
||
var blockHeightInt64 int64 = int64(blockHeight) | ||
|
||
info, _ := t.Client.Commit(&blockHeightInt64) | ||
result, _ := json.Marshal(info) | ||
|
||
|
||
// cmd := "curl -s -XGET " + t.RpcServer + "/commit?height=" + fmt.Sprint(blockHeight) + " -H \"accept:application/json\"" | ||
// out, _ := exec.Command("/bin/bash", "-c", cmd).Output() | ||
// json.Unmarshal(out, &commitStatus) | ||
|
||
json.Unmarshal(result, &commitStatus) | ||
fmt.Println(commitStatus) | ||
|
||
return commitStatus | ||
|
||
} | ||
|
||
func ValidatorPrecommitStatus(commitStatus t.CommitStatus, consHexAddr string) int { | ||
|
||
// validatorCommitStatus(0: false, 1 : true) | ||
validatorCommitStatus := 0 | ||
|
||
precommitData := commitStatus.Result.Signed_header.Commit.Precommits | ||
|
||
for _, value := range precommitData { | ||
|
||
if value.Validator_address == consHexAddr { | ||
validatorCommitStatus = 1 | ||
} | ||
} | ||
|
||
return validatorCommitStatus | ||
} | ||
|
||
func PrecommitRate(commitStatus t.CommitStatus) float64 { | ||
|
||
// validatorCommitStatus(0: false, 1 : true) | ||
precommitRate := 0.0 | ||
|
||
precommitData := commitStatus.Result.Signed_header.Commit.Precommits | ||
totalCount, precommitCount := len(precommitData), len(precommitData) | ||
|
||
for _, value := range precommitData { | ||
|
||
if value.Validator_address == "" { | ||
precommitCount-- | ||
} | ||
} | ||
|
||
precommitRate = float64(precommitCount) / float64(totalCount) | ||
|
||
return precommitRate | ||
} |
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
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,65 @@ | ||
package config | ||
|
||
import ( | ||
|
||
t "github.com/node-a-team/cosmos-validator_exporter/types" | ||
|
||
"fmt" | ||
"time" | ||
"os" | ||
"log" | ||
|
||
"github.com/BurntSushi/toml" | ||
) | ||
|
||
|
||
func Init() { | ||
|
||
var config = readConfig() | ||
|
||
fmt.Printf("\033[7m##### %s #####\033[0m\n", config.Title) | ||
|
||
t.RpcServer = config.Rpc.Address | ||
t.RestServer = config.Rest_server.Address | ||
|
||
t.OperatorAddr = config.Validator_info.OperatorAddress | ||
t.ExporterListenPort = config.Option.ExporterListenPort | ||
t.OutputPrint = config.Option.OutputPrint | ||
t.Bech32MainPrefix = config.Network | ||
|
||
fmt.Println("\n[ Your Info ]") | ||
fmt.Println("- Network:", config.Network) | ||
fmt.Println("- RPC Server Address:", config.Rpc.Address) | ||
fmt.Println("- Rest Server Address:", config.Rest_server.Address) | ||
fmt.Println("- Validator Operator Address:", config.Validator_info.OperatorAddress) | ||
fmt.Println("- Exporter Listen Port:", config.Option.ExporterListenPort) | ||
fmt.Printf("- Output Print: %v\n\n", config.Option.OutputPrint) | ||
|
||
|
||
fmt.Printf("\033[32m## Start Exporter\033[0m\n\n") | ||
|
||
fmt.Printf("\033[34m## This exporter was created by \"Node A-Team\"\n") | ||
fmt.Printf("## Validator: https://www.mintscan.io/validators/cosmosvaloper14l0fp639yudfl46zauvv8rkzjgd4u0zk2aseys\n") | ||
fmt.Printf("## Git: https://github.com/node-a-team/cosmos-validator_exporter.git\033[0m\n\n") | ||
|
||
time.Sleep(1*time.Second) | ||
} | ||
|
||
func readConfig() t.Config { | ||
|
||
var configfile string = "config.toml" | ||
var config t.Config | ||
|
||
_, err := os.Stat(configfile) | ||
|
||
if err != nil { | ||
log.Fatal("Config file is missing: ", configfile) | ||
} | ||
|
||
if _, err := toml.DecodeFile(configfile, &config); err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
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
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,28 @@ | ||
package websocket | ||
|
||
import ( | ||
t "github.com/node-a-team/cosmos-validator_exporter/types" | ||
tmclient "github.com/tendermint/tendermint/rpc/client" | ||
// "encoding/json" | ||
"fmt" | ||
// "os/exec" | ||
// "strconv" | ||
|
||
) | ||
|
||
|
||
func OpenSocket() { | ||
t.Client = tmclient.NewHTTP("tcp://"+t.RpcServer, "/websocket") | ||
|
||
err := t.Client.Start() | ||
if err != nil { | ||
// handle error | ||
fmt.Println("######## RPC/websockets Connection Error ########") | ||
} | ||
defer t.Client.Stop() | ||
|
||
fmt.Println("####### RPC/websockets Connect -> tcp://"+t.RpcServer +" ########") | ||
} | ||
|
||
|
||
|
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
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
Binary file not shown.
Oops, something went wrong.