This repository has been archived by the owner on Sep 26, 2019. It is now read-only.
/
utils.go
574 lines (502 loc) · 18.1 KB
/
utils.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
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
// Copyright 2019 The go-pttai Authors
// This file is part of go-pttai.
//
// go-pttai is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// go-pttai is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with go-pttai. If not, see <http://www.gnu.org/licenses/>.
package utils
import (
"crypto/ecdsa"
"fmt"
"io/ioutil"
golog "log"
"net/url"
"path/filepath"
"strconv"
"strings"
"time"
"github.com/ailabstw/go-pttai/account"
"github.com/ailabstw/go-pttai/common/types"
"github.com/ailabstw/go-pttai/content"
"github.com/ailabstw/go-pttai/friend"
"github.com/ailabstw/go-pttai/internal/debug"
"github.com/ailabstw/go-pttai/log"
"github.com/ailabstw/go-pttai/me"
"github.com/ailabstw/go-pttai/node"
"github.com/ailabstw/go-pttai/p2p"
"github.com/ailabstw/go-pttai/p2p/discover"
"github.com/ailabstw/go-pttai/p2p/nat"
"github.com/ailabstw/go-pttai/p2p/netutil"
"github.com/ailabstw/go-pttai/params"
"github.com/ailabstw/etcd/raft"
pkgservice "github.com/ailabstw/go-pttai/service"
"github.com/ethereum/go-ethereum/common/fdlimit"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/metrics"
"github.com/ethereum/go-ethereum/metrics/influxdb"
logging "github.com/whyrusleeping/go-logging"
cli "gopkg.in/urfave/cli.v1"
)
func SetLogging(ctx *cli.Context) {
logging.SetLevel(logging.DEBUG, "swarm2")
if ctx.GlobalIsSet(debug.VerbosityFlag.Name) {
log.LogLevel = log.Lvl(ctx.GlobalInt(debug.VerbosityFlag.Name))
}
if ctx.GlobalIsSet(LogFilenameFlag.Name) {
log.LogFilename = ctx.GlobalString(LogFilenameFlag.Name)
logging.SetLevel(logging.CRITICAL, "swarm2")
raft.SetLogger(&raft.DefaultLogger{Logger: golog.New(ioutil.Discard, "", 0)})
}
}
// SetContentConfig applies node-related command line flags to the config.
func SetUtilsConfig(ctx *cli.Context, cfg *Config) {
switch {
case ctx.GlobalIsSet(HTTPDirFlag.Name):
cfg.HTTPDir = ctx.GlobalString(HTTPDirFlag.Name)
}
switch {
case ctx.GlobalIsSet(HTTPAddrFlag.Name):
cfg.HTTPAddr = ctx.GlobalString(HTTPAddrFlag.Name)
}
switch {
case ctx.GlobalIsSet(ExternHTTPAddrFlag.Name):
cfg.ExternHTTPAddr = ctx.GlobalString(ExternHTTPAddrFlag.Name)
default:
cfg.ExternHTTPAddr = "http://" + cfg.HTTPAddr
}
}
// SetNodeConfig applies node-related command line flags to the config.
func SetNodeConfig(ctx *cli.Context, cfg *node.Config) {
log.Debug("SetNodeConfig: start")
setP2PConfig(ctx, &cfg.P2P)
setIPC(ctx, cfg)
setHTTP(ctx, cfg)
setWS(ctx, cfg)
// data-dir
switch {
case ctx.GlobalIsSet(DataDirFlag.Name):
cfg.DataDir = ctx.GlobalString(DataDirFlag.Name)
}
if ctx.GlobalIsSet(KeyStoreDirFlag.Name) {
cfg.KeyStoreDir = ctx.GlobalString(KeyStoreDirFlag.Name)
}
}
// SetMyConfig applies node-related command line flags to the config.
func SetMeConfig(ctx *cli.Context, cfg *me.Config, cfgNode *node.Config) {
// data-dir
log.Debug("SetMeConfig: to set DataDir", "cfgNode.DataDIR", cfgNode.DataDir)
cfg.DataDir = filepath.Join(cfgNode.DataDir, "me")
// key/id/postfix
setMyKey(ctx, cfg)
}
// SetMyKey creates a node key from set command line flags, either loading it
// from a file or as a specified hex value. If neither flags were provided, this
// method returns nil and an emphemeral key is to be generated.
func setMyKey(ctx *cli.Context, cfg *me.Config) error {
var (
hex = ctx.GlobalString(MyKeyHexFlag.Name)
file = ctx.GlobalString(MyKeyFileFlag.Name)
postfix = ctx.GlobalString(MyPostfixFlag.Name)
)
err := cfg.SetMyKey(hex, file, postfix, false)
if err != nil {
return err
}
return nil
}
// SetContentConfig applies node-related command line flags to the config.
func SetAccountConfig(ctx *cli.Context, cfg *account.Config, cfgNode *node.Config) {
// datadir
log.Debug("SetAccountConfig: to set DataDir", "cfgNode.DataDIR", cfgNode.DataDir)
cfg.DataDir = filepath.Join(cfgNode.DataDir, "account")
}
// SetContentConfig applies node-related command line flags to the config.
func SetContentConfig(ctx *cli.Context, cfg *content.Config, cfgNode *node.Config) {
// datadir
log.Debug("SetContentConfig: to set DataDir", "cfgNode.DataDIR", cfgNode.DataDir)
cfg.DataDir = filepath.Join(cfgNode.DataDir, "content")
switch {
case ctx.GlobalIsSet(ContentKeystoreDirFlag.Name):
cfg.KeystoreDir = ctx.GlobalString(ContentKeystoreDirFlag.Name)
default:
cfg.KeystoreDir = filepath.Join(cfgNode.DataDir, ".keystore")
}
}
// SetContentConfig applies node-related command line flags to the config.
func SetFriendConfig(ctx *cli.Context, cfg *friend.Config, cfgNode *node.Config) {
// datadir
log.Debug("SetFriendConfig: to set DataDir", "cfgNode.DataDIR", cfgNode.DataDir)
cfg.DataDir = filepath.Join(cfgNode.DataDir, "friend")
if ctx.GlobalIsSet(FriendMaxSyncRandomSecondsFlag.Name) {
cfg.MaxSyncRandomSeconds = ctx.GlobalInt(FriendMaxSyncRandomSecondsFlag.Name)
}
if ctx.GlobalIsSet(FriendMinSyncRandomSecondsFlag.Name) {
cfg.MinSyncRandomSeconds = ctx.GlobalInt(FriendMinSyncRandomSecondsFlag.Name)
}
friend.MaxSyncRandomSeconds = cfg.MaxSyncRandomSeconds
friend.MinSyncRandomSeconds = cfg.MinSyncRandomSeconds
}
// SetPttConfig applies ptt-related command line flags to the config.
func SetPttConfig(ctx *cli.Context, cfg *pkgservice.Config, cfgNode *node.Config, gitCommit string, version string) {
log.Debug("SetPttConfig: start", "cfg", cfg, "cfgNode", cfgNode, "cfgNode.DataDir", cfgNode.DataDir, "params.Version", params.Version)
// data-dir
cfg.DataDir = filepath.Join(cfgNode.DataDir, "ptt")
cfg.Version = version
cfg.GitCommit = gitCommit
// node-type
switch {
case ctx.GlobalBool(ServerFlag.Name):
cfg.NodeType = pkgservice.NodeTypeServer
default:
cfg.NodeType = pkgservice.NodeTypeDesktop
}
// expire oplog seconds
if ctx.GlobalIsSet(ServiceExpireOplogSecondsFlag.Name) {
cfg.ExpireOplogSeconds = ctx.GlobalInt(ServiceExpireOplogSecondsFlag.Name)
}
pkgservice.ExpireOplogSeconds = cfg.ExpireOplogSeconds
// e2e
if ctx.GlobalIsSet(E2EFlag.Name) {
cfg.IsE2E = ctx.GlobalBool(E2EFlag.Name)
}
pkgservice.IsE2E = cfg.IsE2E
// private as public
if ctx.GlobalIsSet(PrivateAsPublicFlag.Name) {
cfg.IsPrivateAsPublic = ctx.GlobalBool(PrivateAsPublicFlag.Name)
}
pkgservice.IsPrivateAsPublic = cfg.IsPrivateAsPublic
// offset second
if ctx.GlobalIsSet(OffsetSecondFlag.Name) {
types.OffsetSecond = ctx.GlobalInt64(OffsetSecondFlag.Name)
}
log.Debug("SetPttConfig: to return", "ExpireOplogSeconds", pkgservice.ExpireOplogSeconds, "IsE2E", pkgservice.IsE2E, "IsPrivateAsPublic", pkgservice.IsPrivateAsPublic, "OffsetSecond", types.OffsetSecond)
}
// MakeDataDir retrieves the currently requested data directory, terminating
// if none (or the empty string) is specified. If the node is starting a testnet,
// the a subdirectory of the specified datadir will be used.
func MakeDataDir(ctx *cli.Context) string {
if path := ctx.GlobalString(DataDirFlag.Name); path != "" {
return path
}
Fatalf("Cannot determine default data directory, please set manually (--datadir)")
return ""
}
// setNodeKey creates a node key from set command line flags, either loading it
// from a file or as a specified hex value. If neither flags were provided, this
// method returns nil and an emphemeral key is to be generated.
func setNodeKey(ctx *cli.Context, cfg *p2p.Config) {
var (
hex = ctx.GlobalString(NodeKeyHexFlag.Name)
file = ctx.GlobalString(NodeKeyFileFlag.Name)
key *ecdsa.PrivateKey
err error
)
switch {
case file != "" && hex != "":
Fatalf("Options %q and %q are mutually exclusive", NodeKeyFileFlag.Name, NodeKeyHexFlag.Name)
case file != "":
if key, err = crypto.LoadECDSA(file); err != nil {
Fatalf("Option %q: %v", NodeKeyFileFlag.Name, err)
}
cfg.PrivateKey = key
case hex != "":
if key, err = crypto.HexToECDSA(hex); err != nil {
Fatalf("Option %q: %v", NodeKeyHexFlag.Name, err)
}
cfg.PrivateKey = key
}
}
// setBootstrapNodes creates a list of bootstrap nodes from the command line
// flags, reverting to pre-configured ones if none have been specified.
func setBootstrapNodes(ctx *cli.Context, cfg *p2p.Config) {
var urls []string
switch {
case ctx.GlobalIsSet(BootnodesFlag.Name) || ctx.GlobalIsSet(BootnodesV4Flag.Name):
if ctx.GlobalIsSet(BootnodesV4Flag.Name) {
urls = strings.Split(ctx.GlobalString(BootnodesV4Flag.Name), ",")
} else {
urls = strings.Split(ctx.GlobalString(BootnodesFlag.Name), ",")
}
case cfg.BootstrapNodes != nil:
return // already set, don't apply defaults.
default:
urls = params.MainnetBootnodes
}
cfg.BootstrapNodes = make([]*discover.Node, 0, len(urls))
for _, url := range urls {
node, err := discover.ParseNode(url)
if err != nil {
log.Error("Bootstrap URL invalid", "enode", url, "err", err)
continue
}
cfg.BootstrapNodes = append(cfg.BootstrapNodes, node)
}
}
func setP2PBootnodes(ctx *cli.Context, cfg *p2p.Config) {
var urls []string
switch {
case ctx.GlobalBool(TestP2PFlag.Name):
urls = params.TestP2PBootnodes
case ctx.GlobalBool(DevP2PFlag.Name):
urls = params.DevP2PBootnodes
case ctx.GlobalBool(IPFSP2PFlag.Name):
urls = params.IPFSBootnodes
case cfg.P2PBootnodes != nil:
return // already set, don't apply defaults.
default:
urls = params.MainP2PBootnodes
}
cfg.P2PBootnodes = make([]*discover.Node, 0, len(urls))
for _, url := range urls {
node, err := discover.ParseP2PNode(url)
if err != nil {
log.Error("Bootstrap P2P URL invalid", "pnode", url, "e", err)
continue
}
cfg.P2PBootnodes = append(cfg.P2PBootnodes, node)
}
log.Info("setP2PBootnodes: done", "P2PBootnodes", len(cfg.P2PBootnodes))
}
func setSignalServerURL(ctx *cli.Context, cfg *p2p.Config) {
var addr string
switch {
case ctx.GlobalIsSet(WebrtcSignalServerFlag.Name):
addr = ctx.GlobalString(WebrtcSignalServerFlag.Name)
case ctx.GlobalBool(TestWebrtcFlag.Name):
addr = params.TestSignalServerAddr
}
if addr == "" {
return
}
cfg.SignalServerURL = url.URL{Scheme: "ws", Host: addr, Path: "/signal"}
}
// setListenAddress creates a TCP listening address string from set command
// line flags.
func setListenAddress(ctx *cli.Context, cfg *p2p.Config) {
if ctx.GlobalIsSet(ListenPortFlag.Name) {
cfg.ListenAddr = fmt.Sprintf(":%d", ctx.GlobalInt(ListenPortFlag.Name))
}
}
// setListenAddress creates a TCP listening address string from set command
// line flags.
func setP2PListenAddress(ctx *cli.Context, cfg *p2p.Config) {
if ctx.GlobalIsSet(P2PListenPortFlag.Name) {
cfg.P2PListenAddr = fmt.Sprintf("/ip4/0.0.0.0/tcp/%d", ctx.GlobalInt(P2PListenPortFlag.Name))
}
}
// setNAT creates a port mapper from command line flags.
func setNAT(ctx *cli.Context, cfg *p2p.Config) {
if ctx.GlobalIsSet(NATFlag.Name) {
natif, err := nat.Parse(ctx.GlobalString(NATFlag.Name))
if err != nil {
Fatalf("Option %s: %v", NATFlag.Name, err)
}
cfg.NAT = natif
}
}
// splitAndTrim splits input separated by a comma
// and trims excessive white space from the substrings.
func splitAndTrim(input string) []string {
result := strings.Split(input, ",")
for i, r := range result {
result[i] = strings.TrimSpace(r)
}
return result
}
// setHTTP creates the HTTP RPC listener interface string from the set
// command line flags, returning empty if the HTTP endpoint is disabled.
func setHTTP(ctx *cli.Context, cfg *node.Config) {
if ctx.GlobalBool(RPCEnabledFlag.Name) && cfg.HTTPHost == "" {
cfg.HTTPHost = "127.0.0.1"
if ctx.GlobalIsSet(RPCListenAddrFlag.Name) {
cfg.HTTPHost = ctx.GlobalString(RPCListenAddrFlag.Name)
}
}
if ctx.GlobalIsSet(RPCPortFlag.Name) {
cfg.HTTPPort = ctx.GlobalInt(RPCPortFlag.Name)
}
if ctx.GlobalIsSet(RPCCORSDomainFlag.Name) {
cfg.HTTPCors = splitAndTrim(ctx.GlobalString(RPCCORSDomainFlag.Name))
}
if ctx.GlobalIsSet(RPCApiFlag.Name) {
cfg.HTTPModules = splitAndTrim(ctx.GlobalString(RPCApiFlag.Name))
}
if ctx.GlobalIsSet(RPCVirtualHostsFlag.Name) {
cfg.HTTPVirtualHosts = splitAndTrim(ctx.GlobalString(RPCVirtualHostsFlag.Name))
}
if ctx.GlobalIsSet(ExternRPCAddrFlag.Name) {
cfg.ExternHTTPAddr = ctx.GlobalString(ExternRPCAddrFlag.Name)
} else {
cfg.ExternHTTPAddr = "http://" + cfg.HTTPHost + ":" + strconv.Itoa(cfg.HTTPPort)
}
}
// setWS creates the WebSocket RPC listener interface string from the set
// command line flags, returning empty if the HTTP endpoint is disabled.
func setWS(ctx *cli.Context, cfg *node.Config) {
if ctx.GlobalBool(WSEnabledFlag.Name) && cfg.WSHost == "" {
cfg.WSHost = "127.0.0.1"
if ctx.GlobalIsSet(WSListenAddrFlag.Name) {
cfg.WSHost = ctx.GlobalString(WSListenAddrFlag.Name)
}
}
if ctx.GlobalIsSet(WSPortFlag.Name) {
cfg.WSPort = ctx.GlobalInt(WSPortFlag.Name)
}
if ctx.GlobalIsSet(WSAllowedOriginsFlag.Name) {
cfg.WSOrigins = splitAndTrim(ctx.GlobalString(WSAllowedOriginsFlag.Name))
}
if ctx.GlobalIsSet(WSApiFlag.Name) {
cfg.WSModules = splitAndTrim(ctx.GlobalString(WSApiFlag.Name))
}
}
// setIPC creates an IPC path configuration from the set command line flags,
// returning an empty string if IPC was explicitly disabled, or the set path.
func setIPC(ctx *cli.Context, cfg *node.Config) {
checkExclusive(ctx, IPCDisabledFlag, IPCPathFlag)
switch {
case ctx.GlobalBool(IPCDisabledFlag.Name):
cfg.IPCPath = ""
case ctx.GlobalIsSet(IPCPathFlag.Name):
cfg.IPCPath = ctx.GlobalString(IPCPathFlag.Name)
}
}
// makeDatabaseHandles raises out the number of allowed file handles per process
// for Geth and returns half of the allowance to assign to the database.
func makeDatabaseHandles() int {
limit, err := fdlimit.Current()
if err != nil {
Fatalf("Failed to retrieve file descriptor allowance: %v", err)
}
if limit < 2048 {
if _, err := fdlimit.Raise(2048); err != nil {
Fatalf("Failed to raise file descriptor allowance: %v", err)
}
}
if limit > 2048 { // cap database file descriptors even if more is available
limit = 2048
}
return limit / 2 // Leave half for networking and other stuff
}
func setP2PConfig(ctx *cli.Context, cfg *p2p.Config) {
setNodeKey(ctx, cfg)
setNAT(ctx, cfg)
setListenAddress(ctx, cfg)
setBootstrapNodes(ctx, cfg)
setP2PListenAddress(ctx, cfg)
setP2PBootnodes(ctx, cfg)
setSignalServerURL(ctx, cfg)
if ctx.GlobalIsSet(MaxPeersFlag.Name) {
cfg.MaxPeers = ctx.GlobalInt(MaxPeersFlag.Name)
}
pttPeers := cfg.MaxPeers
log.Info("Maximum peer count", "PTT", pttPeers, "total", cfg.MaxPeers)
if ctx.GlobalIsSet(MaxPendingPeersFlag.Name) {
cfg.MaxPendingPeers = ctx.GlobalInt(MaxPendingPeersFlag.Name)
}
if ctx.GlobalIsSet(NoDiscoverFlag.Name) {
cfg.NoDiscovery = true
}
// if we're running a light client or server, force enable the v5 peer discovery
// unless it is explicitly disabled with --nodiscover note that explicitly specifying
// --v5disc overrides --nodiscover, in which case the later only disables v4 discovery
// forceV5Discovery := (lightClient || lightServer) && !ctx.GlobalBool(NoDiscoverFlag.Name)
forceV5Discovery := false
if ctx.GlobalIsSet(DiscoveryV5Flag.Name) {
cfg.DiscoveryV5 = ctx.GlobalBool(DiscoveryV5Flag.Name)
} else if forceV5Discovery {
cfg.DiscoveryV5 = true
}
if netrestrict := ctx.GlobalString(NetrestrictFlag.Name); netrestrict != "" {
list, err := netutil.ParseNetlist(netrestrict)
if err != nil {
Fatalf("Option %q: %v", NetrestrictFlag.Name, err)
}
cfg.NetRestrict = list
}
}
// checkExclusive verifies that only a single isntance of the provided flags was
// set by the user. Each flag might optionally be followed by a string type to
// specialize it further.
func checkExclusive(ctx *cli.Context, args ...interface{}) {
set := make([]string, 0, 1)
for i := 0; i < len(args); i++ {
// Make sure the next argument is a flag and skip if not set
flag, ok := args[i].(cli.Flag)
if !ok {
panic(fmt.Sprintf("invalid argument, not cli.Flag type: %T", args[i]))
}
// Check if next arg extends current and expand its name if so
name := flag.GetName()
if i+1 < len(args) {
switch option := args[i+1].(type) {
case string:
// Extended flag, expand the name and shift the arguments
if ctx.GlobalString(flag.GetName()) == option {
name += "=" + option
}
i++
case cli.Flag:
default:
panic(fmt.Sprintf("invalid argument, not cli.Flag or string extension: %T", args[i+1]))
}
}
// Mark the flag if it's set
if ctx.GlobalIsSet(flag.GetName()) {
set = append(set, "--"+name)
}
}
if len(set) > 1 {
Fatalf("Flags %v can't be used at the same time", strings.Join(set, ", "))
}
}
// MigrateFlags sets the global flag from a local flag when it's set.
// This is a temporary function used for migrating old command/flags to the
// new format.
//
// e.g. geth account new --keystore /tmp/mykeystore --lightkdf
//
// is equivalent after calling this method with:
//
// geth --keystore /tmp/mykeystore --lightkdf account new
//
// 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)
}
}
func SetupMetrics(ctx *cli.Context) {
if metrics.Enabled {
log.Info("Enabling metrics collection")
var (
enableExport = ctx.GlobalBool(MetricsEnableInfluxDBFlag.Name)
endpoint = ctx.GlobalString(MetricsInfluxDBEndpointFlag.Name)
database = ctx.GlobalString(MetricsInfluxDBDatabaseFlag.Name)
username = ctx.GlobalString(MetricsInfluxDBUsernameFlag.Name)
password = ctx.GlobalString(MetricsInfluxDBPasswordFlag.Name)
hosttag = ctx.GlobalString(MetricsInfluxDBHostTagFlag.Name)
)
if enableExport {
log.Info("Enabling metrics export to InfluxDB")
go influxdb.InfluxDBWithTags(metrics.DefaultRegistry, 10*time.Second, endpoint, database, username, password, "gptt.", map[string]string{
"host": hosttag,
})
}
}
}