-
Notifications
You must be signed in to change notification settings - Fork 95
/
flags.go
290 lines (257 loc) · 7.22 KB
/
flags.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
package utils
import (
"github.com/vitelabs/go-vite/metrics"
"github.com/vitelabs/go-vite/metrics/influxdb"
"gopkg.in/urfave/cli.v1"
"time"
)
var (
// Config settings
ConfigFileFlag = cli.StringFlag{
Name: "config",
Usage: "Json configuration file",
}
// General settings
DataDirFlag = DirectoryFlag{
Name: "datadir",
Usage: "use for store all files",
}
KeyStoreDirFlag = DirectoryFlag{
Name: "keystore",
Usage: "Directory for the keystore (default = inside the datadir)",
}
// Network Settings
TestNetFlag = cli.BoolFlag{
Name: "testnet",
Usage: "Ropsten network: pre-configured proof-of-work test network",
}
DevNetFlag = cli.BoolFlag{
Name: "devnet",
Usage: "Rinkeby network: pre-configured proof-of-authority dev network",
}
MainNetFlag = cli.BoolFlag{
Name: "mainnet",
Usage: "Rinkeby network: pre-configured proof-of-authority prod network",
}
IdentityFlag = cli.StringFlag{
Name: "identity", //mapping:p2p.Name
Usage: "Custom node name",
}
NetworkIdFlag = cli.UintFlag{
Name: "networkid", //mapping:p2p.NetID
Usage: "Network identifier (integer," +
" 1=MainNet," +
" 2=TestNet," +
" 3~12=DevNet,)",
}
MaxPeersFlag = cli.UintFlag{
Name: "maxpeers", //mapping:p2p.MaxPeers
Usage: "Maximum number of network peers (network disabled if set to 0)",
}
MaxPendingPeersFlag = cli.UintFlag{
Name: "maxpendpeers", //mapping:p2p.MaxPendingPeers
Usage: "Maximum number of pending connection attempts (defaults used if set to 0)",
}
ListenPortFlag = cli.IntFlag{
Name: "port", //mapping:p2p.Addr
Usage: "Network listening port",
}
NodeKeyHexFlag = cli.StringFlag{
Name: "nodekeyhex", //mapping:p2p.PeerKey
Usage: "P2P node key as hex",
}
DiscoveryFlag = cli.StringFlag{
Name: "discovery", //mapping:p2p.Discovery
Usage: "enable p2p discovery or not",
}
//IPC Settings
IPCEnabledFlag = cli.BoolFlag{
Name: "ipc",
Usage: "Enable the IPC-RPC server",
}
IPCPathFlag = DirectoryFlag{
Name: "ipcpath",
Usage: "Filename for IPC socket/pipe within the datadir (explicit paths escape it)",
}
//HTTP RPC Settings
RPCEnabledFlag = cli.BoolFlag{
Name: "rpc",
Usage: "Enable the HTTP-RPC server",
}
RPCListenAddrFlag = cli.StringFlag{
Name: "rpcaddr",
Usage: "HTTP-RPC server listening interface",
}
RPCPortFlag = cli.IntFlag{
Name: "rpcport",
Usage: "HTTP-RPC server listening port",
}
//WS Settings
WSEnabledFlag = cli.BoolFlag{
Name: "ws",
Usage: "Enable the WS-RPC server",
}
WSListenAddrFlag = cli.StringFlag{
Name: "wsaddr",
Usage: "WS-RPC server listening interface",
}
WSPortFlag = cli.IntFlag{
Name: "wsport",
Usage: "WS-RPC server listening port",
}
//Console Settings
JSPathFlag = cli.StringFlag{
Name: "jspath",
Usage: "JavaScript root path for `loadScript`",
Value: ".",
}
ExecFlag = cli.StringFlag{
Name: "exec",
Usage: "Execute JavaScript statement",
}
PreloadJSFlag = cli.StringFlag{
Name: "preload",
Usage: "Comma separated list of JavaScript files to preload into the console",
}
//Producer
MinerFlag = cli.BoolFlag{
Name: "miner",
Usage: "Enable the Miner",
}
CoinBaseFlag = cli.StringFlag{
Name: "coinbase",
Usage: "Coinbase is an address into which the rewards for the SuperNode produce snapshot-block",
}
MinerIntervalFlag = cli.IntFlag{
Name: "minerinterval",
Usage: "Miner Interval(unit: second)",
}
//Log Lvl
LogLvlFlag = cli.StringFlag{
Name: "loglevel",
Usage: "log level (info,eror,warn,dbug)",
}
//VM
VMTestFlag = cli.BoolFlag{
Name: "vmtest",
Usage: "Enable the VM Test ",
}
VMTestParamFlag = cli.BoolFlag{
Name: "vmtestparam",
Usage: "Enable the VM Test params ",
}
VMDebugFlag = cli.BoolFlag{
Name: "vmdebug",
Usage: "Enable VM debug",
}
// Subscribe
SubscribeFlag = cli.BoolFlag{
Name: "subscribe",
Usage: "Enable Subscribe",
}
// Ledger
LedgerDeleteToHeight = cli.Uint64Flag{
Name: "del",
Usage: "Delete to height",
}
// Trie
RecoverTrieFlag = cli.BoolFlag{
Name: "trie",
Usage: "Recover trie",
}
// Export sb height
ExportSbHeightFlags = cli.Uint64Flag{
Name: "sbHeight",
Usage: "The snapshot block height",
}
//Net
SingleFlag = cli.BoolFlag{
Name: "single",
Usage: "Enable the NodeServer single ",
}
FilePortFlag = cli.IntFlag{
Name: "fileport",
Usage: "File transfer listening port",
}
//Stat
PProfEnabledFlag = cli.BoolFlag{
Name: "pprof",
Usage: "Enable a performance analysis tool, you can visit the address[http://localhost:8080/debug/pprof]",
}
PProfPortFlag = cli.UintFlag{
Name: "pprofport",
Usage: "pporof visit `port`, you can visit the address[http://localhost:`port`/debug/pprof]",
}
// Metrics flags
MetricsEnabledFlag = cli.BoolFlag{
Name: "metrics",
Usage: "Enable metrics collection and reporting",
}
InfluxDBEnableFlag = cli.BoolFlag{
Name: "metrics.influxdb",
Usage: "Enable metrics export/push to an external InfluxDB database",
}
InfluxDBEndpointFlag = cli.StringFlag{
Name: "metrics.influxdb.endpoint",
Usage: "InfluxDB API endpoint to report metrics to",
}
InfluxDBDatabaseFlag = cli.StringFlag{
Name: "metrics.influxdb.database",
Usage: "InfluxDB database name to push reported metrics to",
Value: "metrics",
}
InfluxDBUsernameFlag = cli.StringFlag{
Name: "metrics.influxdb.username",
Usage: "Username to authorize access to the database",
Value: "test",
}
InfluxDBPasswordFlag = cli.StringFlag{
Name: "metrics.influxdb.password",
Usage: "Password to authorize access to the database",
Value: "test",
}
// The `host` tag is part of every measurement sent to InfluxDB. Queries on tags are faster in InfluxDB.
// It is used so that we can group all nodes and average a measurement across all of them, but also so
// that we can select a specific node and inspect its measurements.
// https://docs.influxdata.com/influxdb/v1.4/concepts/key_concepts/#tag-key
InfluxDBHostTagFlag = cli.StringFlag{
Name: "metrics.influxdb.host.tag",
Usage: "InfluxDB `host` tag attached to all measurements",
Value: "localhost",
}
)
// This allows the use of the existing configuration functionality.
// When all flags are migrated this function can be removed and the existing
// configuration functionality must be changed that is uses local flags
func MigrateFlags(action func(ctx *cli.Context) error) func(*cli.Context) error {
return func(ctx *cli.Context) error {
for _, name := range ctx.FlagNames() {
if ctx.IsSet(name) {
ctx.GlobalSet(name, ctx.String(name))
}
}
return action(ctx)
}
}
// merge flags
func MergeFlags(flagsSet ...[]cli.Flag) []cli.Flag {
mergeFlags := []cli.Flag{}
for _, flags := range flagsSet {
mergeFlags = append(mergeFlags, flags...)
}
return mergeFlags
}
func SetupMetricsExport(ctx *cli.Context) {
if metrics.MetricsEnabled {
var (
endpoint = ctx.GlobalString(InfluxDBEndpointFlag.Name)
database = ctx.GlobalString(InfluxDBDatabaseFlag.Name)
username = ctx.GlobalString(InfluxDBUsernameFlag.Name)
password = ctx.GlobalString(InfluxDBPasswordFlag.Name)
hosttag = ctx.GlobalString(InfluxDBHostTagFlag.Name)
namespace = "monitor"
)
go influxdb.InfluxDBWithTags(metrics.DefaultRegistry, 10*time.Second, endpoint, database, username, password, namespace,
map[string]string{"host": hosttag})
}
}