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(dot/babe) implement block production time metric #1648

Merged
merged 16 commits into from
Jun 24, 2021
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
15 changes: 15 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
version: '3.7'

services:
noot marked this conversation as resolved.
Show resolved Hide resolved
prometheus:
image: prom/prometheus
volumes:
- ./prometheus.yml:/etc/prometheus/prometheus.yml
command:
- '--config.file=/etc/prometheus/prometheus.yml'
- '--storage.tsdb.path=/prometheus'
- '--web.console.libraries=/usr/share/prometheus/console_libraries'
- '--web.console.templates=/usr/share/prometheus/consoles'
ports:
- 9090:9090
restart: always
29 changes: 29 additions & 0 deletions docs/docs/integrate/using-prometheus.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
---
layout: default
title: Using Prometheus
permalink: /integrate/using-prometheus/
---

# Using Prometheus Locally

To get started with Prometheus locally make sure you have installed [Docker](https://docs.docker.com/engine/install/) and [Docker Compose](https://docs.docker.com/compose/install/).

The docker-compose.yml file has, currently, the Prometheus to collect metrics, so to start that service you can execute (in the project root folder):

```
docker-compose up (-d to disatach the terminal)

or

docker-compose up prometheus (-d to disatach the terminal)
```

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.

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`
1 change: 0 additions & 1 deletion dot/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ const (

// CollectProcessMetrics periodically collects various metrics about the running process.
func CollectProcessMetrics() {
metrics.Enabled = true
// Create the various data collectors
cpuStats := make([]*metrics.CPUStats, 2)
memStats := make([]*runtime.MemStats, 2)
Expand Down
9 changes: 9 additions & 0 deletions dot/network/discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"fmt"
"time"

ethmetrics "github.com/ethereum/go-ethereum/metrics"
badger "github.com/ipfs/go-ds-badger2"
libp2phost "github.com/libp2p/go-libp2p-core/host"
"github.com/libp2p/go-libp2p-core/peer"
Expand All @@ -31,6 +32,11 @@ import (
"github.com/libp2p/go-libp2p-kad-dht/dual"
)

const (
checkPeerCountMetrics = "gossamer/network/peer_count"
peersStoreMetrics = "gossamer/network/peerstore_count"
)

var (
startDHTTimeout = time.Second * 10
initialAdvertisementTimeout = time.Millisecond
Expand Down Expand Up @@ -115,6 +121,9 @@ func (d *discovery) stop() error {
return nil
}

ethmetrics.Unregister(checkPeerCountMetrics)
ethmetrics.Unregister(peersStoreMetrics)
Comment on lines +124 to +125
Copy link
Contributor

Choose a reason for hiding this comment

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

what does this do?

Copy link
Member Author

Choose a reason for hiding this comment

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

this allows the unused metrics to be collected by the gc


return d.dht.Close()
}

Expand Down
1 change: 1 addition & 0 deletions dot/network/discovery_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,4 +213,5 @@ func TestBeginDiscovery_ThreeNodes(t *testing.T) {
// assert B and C can discover each other
addrs := nodeB.host.h.Peerstore().Addrs(nodeC.host.id())
require.NotEqual(t, 0, len(addrs))

}
1 change: 0 additions & 1 deletion dot/network/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,6 @@ func (s *Service) Start() error {
}

func (s *Service) collectNetworkMetrics() {
metrics.Enabled = true
for {
peerCount := metrics.GetOrRegisterGauge("network/node/peerCount", metrics.DefaultRegistry)
totalConn := metrics.GetOrRegisterGauge("network/node/totalConnection", metrics.DefaultRegistry)
Expand Down
1 change: 1 addition & 0 deletions dot/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,7 @@ func NewNode(cfg *Config, ks *keystore.GlobalKeystore, stopFunc func()) (*Node,
}

func publishMetrics(cfg *Config) {
metrics.Enabled = true
address := fmt.Sprintf("%s:%d", cfg.RPC.Host, cfg.Global.MetricsPort)
log.Info("Enabling stand-alone metrics HTTP endpoint", "address", address)
setupMetricsServer(address)
Expand Down
21 changes: 8 additions & 13 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,16 @@ require (
github.com/centrifuge/go-substrate-rpc-client/v2 v2.0.1
github.com/chyeh/pubip v0.0.0-20170203095919-b7e679cf541c
github.com/cosmos/go-bip39 v1.0.0
github.com/davidlazar/go-crypto v0.0.0-20190912175916-7055855a373f // indirect
github.com/dgraph-io/badger/v2 v2.2007.2
github.com/dgraph-io/ristretto v0.0.3-0.20200630154024-f66de99634de
github.com/disiqueira/gotree v1.0.0
github.com/docker/docker v1.13.1
github.com/elastic/gosigar v0.14.0 // indirect
github.com/ethereum/go-ethereum v1.9.7
github.com/go-playground/validator/v10 v10.4.1
github.com/golang/groupcache v0.0.0-20191227052852-215e87163ea7 // indirect
github.com/golang/protobuf v1.4.3
github.com/golang/snappy v0.0.3-0.20201103224600-674baa8c7fc3 // indirect
github.com/google/go-cmp v0.5.6 // indirect
github.com/google/go-cmp v0.5.6
github.com/google/uuid v1.1.5 // indirect
github.com/gorilla/mux v1.7.4
github.com/gorilla/rpc v1.2.0
Expand All @@ -35,13 +33,12 @@ require (
github.com/jpillora/backoff v1.0.0 // indirect
github.com/jpillora/ipfilter v1.2.2
github.com/kylelemons/godebug v1.1.0 // indirect
github.com/libp2p/go-libp2p v0.12.0
github.com/libp2p/go-libp2p-core v0.7.0
github.com/libp2p/go-libp2p v0.14.2
github.com/libp2p/go-libp2p-core v0.8.5
github.com/libp2p/go-libp2p-discovery v0.5.0
github.com/libp2p/go-libp2p-kad-dht v0.11.1
github.com/libp2p/go-libp2p-peerstore v0.2.6
github.com/libp2p/go-libp2p-peerstore v0.2.7
github.com/libp2p/go-libp2p-secio v0.2.2
github.com/libp2p/go-sockaddr v0.1.0 // indirect
github.com/mattn/go-colorable v0.1.4 // indirect
github.com/mattn/go-isatty v0.0.11 // indirect
github.com/multiformats/go-multiaddr v0.3.1
Expand All @@ -54,13 +51,11 @@ require (
github.com/syndtr/goleveldb v1.0.1-0.20200815110645-5c35d600f0ca // indirect
github.com/urfave/cli v1.20.0
github.com/wasmerio/go-ext-wasm v0.3.2-0.20200326095750-0a32be6068ec
go.opencensus.io v0.22.5 // indirect
golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad
golang.org/x/lint v0.0.0-20191125180803-fdd1cda4f05f // indirect
golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c // indirect
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221
golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2
golang.org/x/sys v0.0.0-20210603081109-ebe580a85c40 // indirect
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1
google.golang.org/appengine v1.6.5 // indirect
google.golang.org/protobuf v1.25.0
google.golang.org/protobuf v1.26.0-rc.1
)

go 1.15
Loading