keep-network / keep-core

The smart contracts and reference client behind the Keep network
https://keep.network
MIT License
122 stars 75 forks source link

Adding metric and diagnostics for the Bitcoin chain #3648

Closed dimpar closed 1 year ago

dimpar commented 1 year ago

Refs https://github.com/keep-network/keep-core/issues/3608

Example output:

http://192.168.1.8:9601/diagnostics

{
  "btc_chain_info": {
    "latest_block_number": 2438768
  },
  "client_info": {
    "chain_address": "0x04BdC8f5051f21CF6E788eA451bB81A75266b473",
    "network_id": "16Uiu2HAkzBpWcRgxEY8W4vuRYCJiSAzseEpVjFtHEawqow5xvTQw",
    "revision": "0f3c7b137",
    "version": "v2.0.0-m3-268-g0f3c7b137"
  },
  "connected_peers": [
    {
      "chain_address": "0x407190f04d838Ec47dad4C0e0D2a9c49d7737479",
      "multiaddrs": [
        "/ip6/::1/tcp/3920",
        "/ip4/192.168.1.8/tcp/3920",
        "/ip4/127.0.0.1/tcp/3920"
      ],
      "network_id": "16Uiu2HAm4WrMWq9Gc7WsymsqgrwbaD1KeW2eH8eY63DTZHXbRsuE"
    }
  ],
  "eth_chain_info": {
    "latest_block_number": 6073
  }
}

http://192.168.1.8:9601/metrics

# TYPE btc_connectivity gauge
btc_connectivity 1 1687513222959

client_info{version="v2.0.0-m3-268-g0f3c7b137"} 1

# TYPE connected_bootstrap_count gauge
connected_bootstrap_count 0 1687513282171

# TYPE connected_peers_count gauge
connected_peers_count 1 1687513282170

# TYPE eth_connectivity gauge
eth_connectivity 1 1687513222166

# TYPE tbtc_pre_params_count gauge
tbtc_pre_params_count 100 1687513282894
pdyraga commented 1 year ago

The code looks good to me but before it is merged we decided to make an experiment with Grafana on how it handles empty query results from Prometheus: most nodes will have the Bitcoin connectivity metric and diagnostics and some nodes (bootstraps) will not.

dimpar commented 1 year ago

The code looks good to me but before it is merged we decided to make an experiment with Grafana on how it handles empty query results from Prometheus: most nodes will have the Bitcoin connectivity metric and diagnostics and some nodes (bootstraps) will not.

I've simulated on Testnet Grafana by querying a non-existent metric name. Nothing bad happened, Grafana simply didn't pull it. I've used it along with other metric names that do exist and it also worked. I think we should be fine having the btc metrics and diagnostics available only for some of the nodes.