Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(metrics): replace metrics port with address #2382

Merged
merged 3 commits into from
Mar 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Dockerfile.staging
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ RUN go get ./...
RUN go build github.com/ChainSafe/gossamer/cmd/gossamer

RUN ["sh", "-c", "gossamer init --chain=${chain}"]
ENTRYPOINT ["sh", "-c", "service datadog-agent restart && gossamer --chain=${chain} --basepath=${basepath}/${chain} --publish-metrics --pprofserver --pprofaddress=\":6060\""]
ENTRYPOINT ["sh", "-c", "service datadog-agent restart && gossamer --chain=${chain} --basepath=${basepath}/${chain} --publish-metrics --metrics-address=\":9876\" --pprofserver --pprofaddress=\":6060\""]
EXPOSE 7001 8546 8540 9876 6060
2 changes: 1 addition & 1 deletion chain/dev/config.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[global]
basepath = "~/.gossamer/dev"
log = "info"
metrics-port = 9876
metrics-address = ":9876"

[log]
core = ""
Expand Down
4 changes: 2 additions & 2 deletions chain/dev/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ var (
// DefaultBasePath is the node base directory path
DefaultBasePath = string("~/.gossamer/dev")

// DefaultMetricsPort is the metrics server port
DefaultMetricsPort = uint32(9876)
// DefaultMetricsAddress is the default metrics server listening address.
DefaultMetricsAddress = ":9876"

// DefaultLvl is the default log level
DefaultLvl = log.Info
Expand Down
2 changes: 1 addition & 1 deletion chain/gssmr/config.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[global]
basepath = "~/.gossamer/gssmr"
log = "info"
metrics-port = 9876
metrics-address = "localhost:9876"

[log]
core = ""
Expand Down
4 changes: 2 additions & 2 deletions chain/gssmr/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ var (
// DefaultBasePath Default node base directory path
DefaultBasePath = string("~/.gossamer/gssmr")

// DefaultMetricsPort is the metrics server port
DefaultMetricsPort = uint32(9876)
// DefaultMetricsAddress is the default metrics server listening address.
DefaultMetricsAddress = "localhost:9876"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

potato question but this doesn't need the http://?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🥔 no, this is just the host:port for the tcp net listener, go source code relevant line 😉

Although you can also use localhost:http for example, and Go will understand it as localhost:80, but that's another thing.


// DefaultLvl is the default log level
DefaultLvl = log.Info
Expand Down
2 changes: 1 addition & 1 deletion chain/kusama/config.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[global]
basepath = "~/.gossamer/kusama"
log = "info"
metrics-port = 9876
metrics-address = "localhost:9876"

[log]
core = ""
Expand Down
4 changes: 2 additions & 2 deletions chain/kusama/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ var (
// DefaultBasePath Default node base directory path
DefaultBasePath = string("~/.gossamer/kusama")

// DefaultMetricsPort is the metrics server port
DefaultMetricsPort = uint32(9876)
// DefaultMetricsAddress is the default metrics server listening address.
DefaultMetricsAddress = "localhost:9876"

// DefaultLvl is the default log level
DefaultLvl = log.Info
Expand Down
2 changes: 1 addition & 1 deletion chain/polkadot/config.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[global]
basepath = "~/.gossamer/polkadot"
log = "info"
metrics-port = 9876
metrics-address = "localhost:9876"

[log]
core = ""
Expand Down
4 changes: 2 additions & 2 deletions cmd/gossamer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ defined in [lib/runtime/wasmer/exports.go](../../lib/runtime/wasmer/exports.go).
Gossamer publishes telemetry data and also includes an embedded Prometheus server that reports metrics. The metrics
capabilities are defined in the [dot/metrics](../../dot/metrics) package and build on
[the metrics library that is included with Go Ethereum](https://github.com/ethereum/go-ethereum/blob/master/metrics/README.md).
The default port for Prometheus metrics is 9090, and Gossamer allows the user to configure this parameter with the
`--metrics-port` command-line parameter. The Gossamer telemetry server publishes telemetry data that is compatible with
The default listening address for Prometheus metrics is `localhost:9090`, and Gossamer allows the user to configure this parameter with the
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually this is false right @danforbes ? It's 9876 not 9090 I think?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

`--metrics-address` command-line parameter. The Gossamer telemetry server publishes telemetry data that is compatible with
[Polkadot Telemetry](https://github.com/paritytech/substrate-telemetry) and
[its helpful UI](https://telemetry.polkadot.io/).
8 changes: 4 additions & 4 deletions cmd/gossamer/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ func setDotGlobalConfigFromToml(tomlCfg *ctoml.Config, cfg *dot.GlobalConfig) {
}
}

cfg.MetricsPort = tomlCfg.Global.MetricsPort
cfg.MetricsAddress = tomlCfg.Global.MetricsAddress

cfg.RetainBlocks = tomlCfg.Global.RetainBlocks
cfg.Pruning = pruner.Mode(tomlCfg.Global.Pruning)
Expand All @@ -485,9 +485,9 @@ func setDotGlobalConfigFromFlags(ctx *cli.Context, cfg *dot.GlobalConfig) error

cfg.PublishMetrics = ctx.Bool("publish-metrics")

// check --metrics-port flag and update node configuration
if metricsPort := ctx.GlobalUint(MetricsPortFlag.Name); metricsPort != 0 {
cfg.MetricsPort = uint32(metricsPort)
// check --metrics-address flag and update node configuration
if metricsAddress := ctx.GlobalString(MetricsAddressFlag.Name); metricsAddress != "" {
cfg.MetricsAddress = metricsAddress
}

cfg.RetainBlocks = ctx.Int64(RetainBlockNumberFlag.Name)
Expand Down
30 changes: 15 additions & 15 deletions cmd/gossamer/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ func TestGlobalConfigFromFlags(t *testing.T) {
BasePath: testCfg.Global.BasePath,
LogLvl: log.Info,
PublishMetrics: testCfg.Global.PublishMetrics,
MetricsPort: testCfg.Global.MetricsPort,
MetricsAddress: testCfg.Global.MetricsAddress,
},
},
{
Expand All @@ -149,7 +149,7 @@ func TestGlobalConfigFromFlags(t *testing.T) {
BasePath: dot.KusamaConfig().Global.BasePath,
LogLvl: log.Info,
PublishMetrics: testCfg.Global.PublishMetrics,
MetricsPort: testCfg.Global.MetricsPort,
MetricsAddress: testCfg.Global.MetricsAddress,
},
},
{
Expand All @@ -162,7 +162,7 @@ func TestGlobalConfigFromFlags(t *testing.T) {
BasePath: testCfg.Global.BasePath,
LogLvl: log.Info,
PublishMetrics: testCfg.Global.PublishMetrics,
MetricsPort: testCfg.Global.MetricsPort,
MetricsAddress: testCfg.Global.MetricsAddress,
},
},
{
Expand All @@ -175,7 +175,7 @@ func TestGlobalConfigFromFlags(t *testing.T) {
BasePath: "test_basepath",
LogLvl: log.Info,
PublishMetrics: testCfg.Global.PublishMetrics,
MetricsPort: testCfg.Global.MetricsPort,
MetricsAddress: testCfg.Global.MetricsAddress,
},
},
{
Expand All @@ -188,7 +188,7 @@ func TestGlobalConfigFromFlags(t *testing.T) {
BasePath: testCfg.Global.BasePath,
LogLvl: log.Info,
PublishMetrics: testCfg.Global.PublishMetrics,
MetricsPort: testCfg.Global.MetricsPort,
MetricsAddress: testCfg.Global.MetricsAddress,
},
},
{
Expand All @@ -201,20 +201,20 @@ func TestGlobalConfigFromFlags(t *testing.T) {
BasePath: testCfg.Global.BasePath,
LogLvl: log.Info,
PublishMetrics: true,
MetricsPort: testCfg.Global.MetricsPort,
MetricsAddress: testCfg.Global.MetricsAddress,
},
},
{
"Test gossamer --metrics-port",
[]string{"config", "metrics-port", "name"},
[]interface{}{testCfgFile.Name(), "9871", testCfg.Global.Name},
"Test gossamer --metrics-address",
[]string{"config", "metrics-address", "name"},
[]interface{}{testCfgFile.Name(), ":9871", testCfg.Global.Name},
dot.GlobalConfig{
Name: testCfg.Global.Name,
ID: testCfg.Global.ID,
BasePath: testCfg.Global.BasePath,
LogLvl: log.Info,
PublishMetrics: testCfg.Global.PublishMetrics,
MetricsPort: uint32(9871),
MetricsAddress: ":9871",
},
},
{
Expand All @@ -227,7 +227,7 @@ func TestGlobalConfigFromFlags(t *testing.T) {
BasePath: testCfg.Global.BasePath,
LogLvl: log.Info,
PublishMetrics: testCfg.Global.PublishMetrics,
MetricsPort: testCfg.Global.MetricsPort,
MetricsAddress: testCfg.Global.MetricsAddress,
NoTelemetry: true,
},
},
Expand All @@ -245,7 +245,7 @@ func TestGlobalConfigFromFlags(t *testing.T) {
BasePath: testCfg.Global.BasePath,
LogLvl: log.Info,
PublishMetrics: testCfg.Global.PublishMetrics,
MetricsPort: testCfg.Global.MetricsPort,
MetricsAddress: testCfg.Global.MetricsAddress,
NoTelemetry: false,
TelemetryURLs: []genesis.TelemetryEndpoint{
{Endpoint: "ws://localhost:8001/submit", Verbosity: 0},
Expand Down Expand Up @@ -783,7 +783,7 @@ func TestUpdateConfigFromGenesisJSON(t *testing.T) {
BasePath: testCfg.Global.BasePath,
LogLvl: testCfg.Global.LogLvl,
PublishMetrics: testCfg.Global.PublishMetrics,
MetricsPort: testCfg.Global.MetricsPort,
MetricsAddress: testCfg.Global.MetricsAddress,
TelemetryURLs: testCfg.Global.TelemetryURLs,
},
Log: dot.LogConfig{
Expand Down Expand Up @@ -837,7 +837,7 @@ func TestUpdateConfigFromGenesisJSON_Default(t *testing.T) {
BasePath: testCfg.Global.BasePath,
LogLvl: testCfg.Global.LogLvl,
PublishMetrics: testCfg.Global.PublishMetrics,
MetricsPort: testCfg.Global.MetricsPort,
MetricsAddress: testCfg.Global.MetricsAddress,
TelemetryURLs: testCfg.Global.TelemetryURLs,
},
Log: dot.LogConfig{
Expand Down Expand Up @@ -887,7 +887,7 @@ func TestUpdateConfigFromGenesisData(t *testing.T) {
BasePath: testCfg.Global.BasePath,
LogLvl: testCfg.Global.LogLvl,
PublishMetrics: testCfg.Global.PublishMetrics,
MetricsPort: testCfg.Global.MetricsPort,
MetricsAddress: testCfg.Global.MetricsAddress,
TelemetryURLs: testCfg.Global.TelemetryURLs,
},
Log: dot.LogConfig{
Expand Down
14 changes: 7 additions & 7 deletions cmd/gossamer/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,13 @@ func dotConfigToToml(dcfg *dot.Config) *ctoml.Config {
}

cfg.Global = ctoml.GlobalConfig{
Name: dcfg.Global.Name,
ID: dcfg.Global.ID,
BasePath: dcfg.Global.BasePath,
LogLvl: dcfg.Global.LogLvl.String(),
MetricsPort: dcfg.Global.MetricsPort,
RetainBlocks: dcfg.Global.RetainBlocks,
Pruning: string(dcfg.Global.Pruning),
Name: dcfg.Global.Name,
ID: dcfg.Global.ID,
BasePath: dcfg.Global.BasePath,
LogLvl: dcfg.Global.LogLvl.String(),
MetricsAddress: dcfg.Global.MetricsAddress,
RetainBlocks: dcfg.Global.RetainBlocks,
Pruning: string(dcfg.Global.Pruning),
}

cfg.Log = ctoml.LogConfig{
Expand Down
2 changes: 1 addition & 1 deletion cmd/gossamer/export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func TestExportCommand(t *testing.T) {
BasePath: testCfg.Global.BasePath,
LogLvl: log.Info,
PublishMetrics: testCfg.Global.PublishMetrics,
MetricsPort: testCfg.Global.MetricsPort,
MetricsAddress: testCfg.Global.MetricsAddress,
},
Log: dot.LogConfig{
CoreLvl: log.Info,
Expand Down
10 changes: 5 additions & 5 deletions cmd/gossamer/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,10 @@ var (
Usage: "Publish node metrics",
}

// MetricsPortFlag set metric listen port
MetricsPortFlag = cli.StringFlag{
Name: "metrics-port",
Usage: "Set metric listening port ",
// MetricsAddressFlag sets the metric server listening address
MetricsAddressFlag = cli.StringFlag{
Name: "metrics-address",
Usage: "Set the metric server listening address",
}

// NoTelemetryFlag stops publishing telemetry to default defined in genesis.json
Expand Down Expand Up @@ -442,7 +442,7 @@ var (

// metrics flag
PublishMetricsFlag,
MetricsPortFlag,
MetricsAddressFlag,

// telemetry flags
NoTelemetryFlag,
Expand Down
2 changes: 1 addition & 1 deletion cmd/gossamer/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func newTestConfig(t *testing.T) *dot.Config {
BasePath: dir,
LogLvl: log.Info,
PublishMetrics: dot.GssmrConfig().Global.PublishMetrics,
MetricsPort: dot.GssmrConfig().Global.MetricsPort,
MetricsAddress: dot.GssmrConfig().Global.MetricsAddress,
RetainBlocks: dot.GssmrConfig().Global.RetainBlocks,
Pruning: dot.GssmrConfig().Global.Pruning,
TelemetryURLs: dot.GssmrConfig().Global.TelemetryURLs,
Expand Down
2 changes: 1 addition & 1 deletion devnet/alice.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,6 @@ RUN go run cmd/update-dd-agent-confd/main.go -n=${METRICS_NAMESPACE} -t=key:alic

WORKDIR /gossamer

ENTRYPOINT service datadog-agent start && gossamer --key=alice --babe-lead --publish-metrics --rpc --rpc-external=true --pubdns=alice --port 7001
ENTRYPOINT service datadog-agent start && gossamer --key=alice --babe-lead --publish-metrics --metrics-address=":9876" --rpc --rpc-external=true --pubdns=alice --port 7001

EXPOSE 7001/tcp 8545/tcp 8546/tcp 8540/tcp 9876/tcp 6060/tcp
1 change: 1 addition & 0 deletions devnet/bob.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ WORKDIR /gossamer
ENTRYPOINT service datadog-agent start && gossamer --key=${key} \
--bootnodes=/dns/alice/tcp/7001/p2p/12D3KooWMER5iow67nScpWeVqEiRRx59PJ3xMMAYPTACYPRQbbWU \
--publish-metrics \
--metrics-address=":9876" \
--rpc \
--port 7001 \
--pubdns=${key}
Expand Down
6 changes: 4 additions & 2 deletions docs/docs/integrate/using-prometheus.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@ the above command will starts the Prometheus service on `0.0.0.0:9090`.

### Prometheus

Actually the Prometheus service reads a file `prometheus.yml` placed in the root level project folder, this file contains the definitions that Prometheus needs to collect the metrics.
Actually the Prometheus service reads a file `prometheus.yml` placed in the root level project folder, this file contains the definitions that Prometheus needs to collect the metrics.

Linux: In the **job_name == gossamer** the **targets** property should be `[localhost:9876]`

To publish metrics from the node use the flag **--publish-metrics**; i.e, `./bin/gossamer --chain {chain} --key {key} --publish-metrics`
To publish metrics from the node use the flag `--publish-metrics`; i.e, `./bin/gossamer --chain {chain} --key {key} --publish-metrics`.

By default, the Prometheus server listens on `localhost:9876`, which you can change with `--metrics-address`. To listen on all interfaces, you can use `--metrics-address=":9876"`.
Loading