Skip to content

Commit

Permalink
feat(dot/babe) implement block production time metric (#1648)
Browse files Browse the repository at this point in the history
* metric: gossamer_proposer_block_constructed

* chore: improve metrics instance and add tests

* chore: add peer check and peerstore metrics

* chore: fix pacakge name and interface to gauge struct

* chore: change to const

* chore: adjust babe metrics

* chore: removing duplicated net metrics

* chore: improve babe time to build block test

* chore: fix CI tests failures

* exec go mod tidy

* chore: go mod

* change docker-compose instructions to docs/ folder
  • Loading branch information
EclesioMeloJunior authored Jun 24, 2021
1 parent 51cfcd7 commit 23007f0
Show file tree
Hide file tree
Showing 13 changed files with 382 additions and 77 deletions.
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:
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)

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

0 comments on commit 23007f0

Please sign in to comment.