2022-11-10 09:29:34 +00:00
|
|
|
|
import
|
|
|
|
|
std/strutils,
|
|
|
|
|
chronicles,
|
|
|
|
|
chronicles/topics_registry,
|
|
|
|
|
chronos,
|
|
|
|
|
confutils,
|
|
|
|
|
stew/results,
|
|
|
|
|
stew/shims/net
|
|
|
|
|
|
|
|
|
|
type
|
|
|
|
|
NetworkMonitorConf* = object
|
|
|
|
|
logLevel* {.
|
|
|
|
|
desc: "Sets the log level",
|
2023-09-25 12:38:59 +00:00
|
|
|
|
defaultValue: LogLevel.INFO,
|
2022-11-10 09:29:34 +00:00
|
|
|
|
name: "log-level",
|
|
|
|
|
abbr: "l" .}: LogLevel
|
|
|
|
|
|
|
|
|
|
timeout* {.
|
|
|
|
|
desc: "Timeout to consider that the connection failed",
|
|
|
|
|
defaultValue: chronos.seconds(10),
|
|
|
|
|
name: "timeout",
|
|
|
|
|
abbr: "t" }: chronos.Duration
|
|
|
|
|
|
|
|
|
|
bootstrapNodes* {.
|
|
|
|
|
desc: "Bootstrap ENR node. Argument may be repeated.",
|
|
|
|
|
defaultValue: @[""],
|
|
|
|
|
name: "bootstrap-node",
|
|
|
|
|
abbr: "b" }: seq[string]
|
|
|
|
|
|
2022-12-05 19:02:21 +00:00
|
|
|
|
dnsDiscoveryUrl* {.
|
|
|
|
|
desc: "URL for DNS node list in format 'enrtree://<key>@<fqdn>'",
|
|
|
|
|
defaultValue: ""
|
|
|
|
|
name: "dns-discovery-url" }: string
|
|
|
|
|
|
2022-11-10 09:29:34 +00:00
|
|
|
|
refreshInterval* {.
|
2022-11-14 07:33:36 +00:00
|
|
|
|
desc: "How often new peers are discovered and connected to (in seconds)",
|
|
|
|
|
defaultValue: 5,
|
2022-11-10 09:29:34 +00:00
|
|
|
|
name: "refresh-interval",
|
|
|
|
|
abbr: "r" }: int
|
|
|
|
|
|
|
|
|
|
## Prometheus metrics config
|
|
|
|
|
metricsServer* {.
|
|
|
|
|
desc: "Enable the metrics server: true|false"
|
|
|
|
|
defaultValue: true
|
|
|
|
|
name: "metrics-server" }: bool
|
|
|
|
|
|
|
|
|
|
metricsServerAddress* {.
|
|
|
|
|
desc: "Listening address of the metrics server."
|
|
|
|
|
defaultValue: ValidIpAddress.init("127.0.0.1")
|
|
|
|
|
name: "metrics-server-address" }: ValidIpAddress
|
|
|
|
|
|
|
|
|
|
metricsServerPort* {.
|
|
|
|
|
desc: "Listening HTTP port of the metrics server."
|
|
|
|
|
defaultValue: 8008
|
|
|
|
|
name: "metrics-server-port" }: uint16
|
|
|
|
|
|
|
|
|
|
## Custom metrics rest server
|
|
|
|
|
metricsRestAddress* {.
|
|
|
|
|
desc: "Listening address of the metrics rest server.",
|
|
|
|
|
defaultValue: "127.0.0.1",
|
|
|
|
|
name: "metrics-rest-address" }: string
|
|
|
|
|
metricsRestPort* {.
|
|
|
|
|
desc: "Listening HTTP port of the metrics rest server.",
|
|
|
|
|
defaultValue: 8009,
|
|
|
|
|
name: "metrics-rest-port" }: uint16
|
2022-12-05 19:02:21 +00:00
|
|
|
|
|
2022-11-10 09:29:34 +00:00
|
|
|
|
proc parseCmdArg*(T: type ValidIpAddress, p: string): T =
|
|
|
|
|
try:
|
|
|
|
|
result = ValidIpAddress.init(p)
|
|
|
|
|
except CatchableError as e:
|
2023-09-21 11:12:14 +00:00
|
|
|
|
raise newException(ValueError, "Invalid IP address")
|
2022-11-10 09:29:34 +00:00
|
|
|
|
|
|
|
|
|
proc completeCmdArg*(T: type ValidIpAddress, val: string): seq[string] =
|
|
|
|
|
return @[]
|
|
|
|
|
|
|
|
|
|
proc parseCmdArg*(T: type chronos.Duration, p: string): T =
|
|
|
|
|
try:
|
|
|
|
|
result = chronos.seconds(parseInt(p))
|
|
|
|
|
except CatchableError as e:
|
2023-09-21 11:12:14 +00:00
|
|
|
|
raise newException(ValueError, "Invalid duration value")
|
2022-11-10 09:29:34 +00:00
|
|
|
|
|
|
|
|
|
proc completeCmdArg*(T: type chronos.Duration, val: string): seq[string] =
|
|
|
|
|
return @[]
|
|
|
|
|
|
|
|
|
|
proc loadConfig*(T: type NetworkMonitorConf): Result[T, string] =
|
|
|
|
|
try:
|
2023-09-28 08:07:27 +00:00
|
|
|
|
let conf = NetworkMonitorConf.load(version=git_version)
|
2022-11-10 09:29:34 +00:00
|
|
|
|
ok(conf)
|
|
|
|
|
except CatchableError:
|
2022-12-05 19:02:21 +00:00
|
|
|
|
err(getCurrentExceptionMsg())
|