-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
94 lines (72 loc) · 2.4 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package main
import (
"context"
"fmt"
"github.com/celestiaorg/celestia-node/api/rpc/client"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/rs/zerolog"
"github.com/spf13/cobra"
"net/http"
"os"
)
var (
ListenAddress string
NodeAddress string
LogLevel string
Token string
ConstLabels map[string]string
)
var log = zerolog.New(zerolog.ConsoleWriter{Out: os.Stdout}).With().Timestamp().Logger()
var rootCmd = &cobra.Command{
Use: "oracle-exporter",
Long: "Scrape the data about the validators set, specific validators or wallets in the Cosmos network.",
Run: Execute,
}
var ctx = context.Background()
func Execute(_ *cobra.Command, _ []string) {
logLevel, err := zerolog.ParseLevel(LogLevel)
if err != nil {
log.Fatal().Err(err).Msg("Could not parse log level")
}
zerolog.SetGlobalLevel(logLevel)
log.Info().
Str("--listen-address", ListenAddress).
Str("--node", NodeAddress).
Str("--log-level", LogLevel).
Msg("Started with following parameters")
config := sdk.GetConfig()
config.Seal()
if err != nil {
log.Fatal().Err(err).Msg("Could not connect to RPC node")
}
rpcClient, err := client.NewClient(ctx, NodeAddress, Token)
if err != nil {
fmt.Print(err)
}
http.HandleFunc("/metrics/p2p", func(w http.ResponseWriter, r *http.Request) {
P2pHandler(w, r, rpcClient)
})
http.HandleFunc("/metrics/header", func(w http.ResponseWriter, r *http.Request) {
HeaderHandler(w, r, rpcClient)
})
http.HandleFunc("/metrics/state", func(w http.ResponseWriter, r *http.Request) {
StateHandler(w, r, rpcClient)
})
http.HandleFunc("/metrics/shares", func(w http.ResponseWriter, r *http.Request) {
SharesHandler(w, r, rpcClient)
})
log.Info().Str("address", ListenAddress).Msg("Listening")
err = http.ListenAndServe(ListenAddress, nil)
if err != nil {
log.Fatal().Err(err).Msg("Could not start application")
}
}
func main() {
rootCmd.PersistentFlags().StringVar(&ListenAddress, "listen-address", ":9300", "The address this exporter would listen on")
rootCmd.PersistentFlags().StringVar(&NodeAddress, "node", "http://127.0.0.0:26658", "RPC bridge node address")
rootCmd.PersistentFlags().StringVar(&Token, "token", "eyJhbGciOiJ.celestia.testing", "OAuth token to bridge node with admin rights")
rootCmd.PersistentFlags().StringVar(&LogLevel, "log-level", "info", "Logging level")
if err := rootCmd.Execute(); err != nil {
log.Fatal().Err(err).Msg("Could not start application")
}
}