Skip to content

Commit

Permalink
swarm: add ip_version to metrics (#2114)
Browse files Browse the repository at this point in the history
* add ip_version to swarm metrics

* use "unknown" as a default for the IP version

---------

Co-authored-by: Marten Seemann <martenseemann@gmail.com>
  • Loading branch information
sukunrt and marten-seemann authored Feb 18, 2023
1 parent 32f2f25 commit d9004d2
Show file tree
Hide file tree
Showing 6 changed files with 245 additions and 35 deletions.
209 changes: 199 additions & 10 deletions dashboards/swarm/swarm.json
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@
"uid": "${DS_PROMETHEUS}"
},
"editorMode": "code",
"expr": "libp2p_swarm_connections_opened_total{dir=\"inbound\"} - libp2p_swarm_connections_closed_total{dir=\"inbound\"}",
"expr": "sum by (transport, security, muxer) (libp2p_swarm_connections_opened_total{dir=\"inbound\"}) - sum by (transport, security, muxer) (libp2p_swarm_connections_closed_total{dir=\"inbound\"})",
"legendFormat": "{{transport}} {{security}} {{muxer}}",
"range": true,
"refId": "A"
Expand Down Expand Up @@ -691,7 +691,7 @@
"uid": "${DS_PROMETHEUS}"
},
"editorMode": "code",
"expr": "libp2p_swarm_connections_opened_total{dir=\"outbound\"} - libp2p_swarm_connections_closed_total{dir=\"outbound\"}",
"expr": "sum by (transport, security, muxer)(libp2p_swarm_connections_opened_total{dir=\"outbound\"}) - sum by (transport, security, muxer) (libp2p_swarm_connections_closed_total{dir=\"outbound\"})",
"legendFormat": "{{transport}} {{security}} {{muxer}}",
"range": true,
"refId": "A"
Expand Down Expand Up @@ -1289,7 +1289,7 @@
"uid": "${DS_PROMETHEUS}"
},
"editorMode": "code",
"expr": "rate(libp2p_swarm_connections_opened_total{dir=\"inbound\"}[$__rate_interval])",
"expr": "sum (rate(libp2p_swarm_connections_opened_total{dir=\"inbound\"}[$__rate_interval])) by (transport, security, muxer)",
"legendFormat": "{{transport}} {{security}} {{muxer}}",
"range": true,
"refId": "A"
Expand Down Expand Up @@ -1515,7 +1515,7 @@
"uid": "${DS_PROMETHEUS}"
},
"editorMode": "code",
"expr": "rate(libp2p_swarm_connections_opened_total{dir=\"outbound\"}[$__rate_interval])",
"expr": "sum (rate(libp2p_swarm_connections_opened_total{dir=\"outbound\"}[$__rate_interval])) by (transport, security, muxer)",
"legendFormat": "{{transport}} {{security}} {{muxer}}",
"range": true,
"refId": "A"
Expand Down Expand Up @@ -1713,7 +1713,7 @@
"uid": "${DS_PROMETHEUS}"
},
"editorMode": "code",
"expr": "increase(libp2p_swarm_connections_opened_total{dir=\"inbound\"}[$__range])",
"expr": "sum (increase(libp2p_swarm_connections_opened_total{dir=\"inbound\"}[$__range])) by (transport, security, muxer)",
"legendFormat": "{{transport}} {{security}} {{muxer}}",
"range": true,
"refId": "A"
Expand Down Expand Up @@ -1913,7 +1913,7 @@
"uid": "${DS_PROMETHEUS}"
},
"editorMode": "code",
"expr": "increase(libp2p_swarm_connections_opened_total{dir=\"outbound\"}[$__range])",
"expr": "sum (increase(libp2p_swarm_connections_opened_total{dir=\"outbound\"}[$__range])) by (transport, security, muxer)",
"legendFormat": "{{transport}} {{security}} {{muxer}}",
"range": true,
"refId": "A"
Expand Down Expand Up @@ -1941,14 +1941,203 @@
},
"mappings": []
},
"overrides": []
"overrides": [
{
"matcher": {
"id": "byName",
"options": "ip4"
},
"properties": [
{
"id": "color",
"value": {
"fixedColor": "light-blue",
"mode": "fixed"
}
}
]
},
{
"matcher": {
"id": "byName",
"options": "ip6"
},
"properties": [
{
"id": "color",
"value": {
"fixedColor": "super-light-purple",
"mode": "fixed"
}
}
]
}
]
},
"gridPos": {
"h": 8,
"w": 12,
"x": 0,
"y": 51
},
"id": 32,
"options": {
"legend": {
"displayMode": "list",
"placement": "bottom",
"showLegend": true
},
"pieType": "pie",
"reduceOptions": {
"calcs": [
"lastNotNull"
],
"fields": "",
"values": false
},
"tooltip": {
"mode": "single",
"sort": "none"
}
},
"targets": [
{
"datasource": {
"type": "prometheus",
"uid": "${DS_PROMETHEUS}"
},
"editorMode": "code",
"expr": "sum by (ip_version) (libp2p_swarm_connections_opened_total{dir=\"inbound\"}) - sum by (ip_version) (libp2p_swarm_connections_closed_total{dir=\"inbound\"})",
"legendFormat": "{{ip_version}}",
"range": true,
"refId": "A"
}
],
"title": "New Inbound Connections: IP Version",
"type": "piechart"
},
{
"datasource": {
"type": "prometheus",
"uid": "${DS_PROMETHEUS}"
},
"description": "",
"fieldConfig": {
"defaults": {
"color": {
"mode": "palette-classic"
},
"custom": {
"hideFrom": {
"legend": false,
"tooltip": false,
"viz": false
}
},
"mappings": []
},
"overrides": [
{
"matcher": {
"id": "byName",
"options": "ip6"
},
"properties": [
{
"id": "color",
"value": {
"fixedColor": "super-light-purple",
"mode": "fixed"
}
}
]
},
{
"matcher": {
"id": "byName",
"options": "ip4"
},
"properties": [
{
"id": "color",
"value": {
"fixedColor": "light-blue",
"mode": "fixed"
}
}
]
}
]
},
"gridPos": {
"h": 8,
"w": 12,
"x": 12,
"y": 51
},
"id": 34,
"options": {
"legend": {
"displayMode": "list",
"placement": "bottom",
"showLegend": true
},
"pieType": "pie",
"reduceOptions": {
"calcs": [
"lastNotNull"
],
"fields": "",
"values": false
},
"tooltip": {
"mode": "single",
"sort": "none"
}
},
"targets": [
{
"datasource": {
"type": "prometheus",
"uid": "${DS_PROMETHEUS}"
},
"editorMode": "code",
"expr": "sum by (ip_version) (libp2p_swarm_connections_opened_total{dir=\"outbound\"}) - sum by (ip_version) (libp2p_swarm_connections_closed_total{dir=\"outbound\"})",
"legendFormat": "__auto",
"range": true,
"refId": "A"
}
],
"title": "New Outbound Connections: IP Version",
"type": "piechart"
},
{
"datasource": {
"type": "prometheus",
"uid": "${DS_PROMETHEUS}"
},
"fieldConfig": {
"defaults": {
"color": {
"mode": "palette-classic"
},
"custom": {
"hideFrom": {
"legend": false,
"tooltip": false,
"viz": false
}
},
"mappings": []
},
"overrides": []
},
"gridPos": {
"h": 8,
"w": 12,
"x": 0,
"y": 59
},
"id": 15,
"options": {
"legend": {
Expand Down Expand Up @@ -2137,7 +2326,7 @@
"h": 8,
"w": 12,
"x": 12,
"y": 51
"y": 59
},
"id": 17,
"options": {
Expand Down Expand Up @@ -2220,7 +2409,7 @@
"h": 8,
"w": 12,
"x": 0,
"y": 59
"y": 67
},
"id": 25,
"options": {
Expand Down Expand Up @@ -2296,6 +2485,6 @@
"timezone": "",
"title": "libp2p Swarm",
"uid": "a15PyhO4z",
"version": 68,
"version": 12,
"weekStart": ""
}
2 changes: 1 addition & 1 deletion p2p/net/swarm/swarm_conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func (c *Conn) Close() error {

func (c *Conn) doClose() {
if c.swarm.metricsTracer != nil {
c.swarm.metricsTracer.ClosedConnection(c.stat.Direction, time.Since(c.stat.Stats.Opened), c.ConnState())
c.swarm.metricsTracer.ClosedConnection(c.stat.Direction, time.Since(c.stat.Stats.Opened), c.ConnState(), c.LocalMultiaddr())
}

c.swarm.removeConn(c)
Expand Down
4 changes: 2 additions & 2 deletions p2p/net/swarm/swarm_dial.go
Original file line number Diff line number Diff line change
Expand Up @@ -500,8 +500,8 @@ func (s *Swarm) dialAddr(ctx context.Context, p peer.ID, addr ma.Multiaddr) (tra
canonicallog.LogPeerStatus(100, connC.RemotePeer(), connC.RemoteMultiaddr(), "connection_status", "established", "dir", "outbound")
if s.metricsTracer != nil {
connState := connC.ConnState()
s.metricsTracer.OpenedConnection(network.DirOutbound, connC.RemotePublicKey(), connState)
s.metricsTracer.CompletedHandshake(time.Since(start), connState)
s.metricsTracer.OpenedConnection(network.DirOutbound, connC.RemotePublicKey(), connState, connC.LocalMultiaddr())
s.metricsTracer.CompletedHandshake(time.Since(start), connState, connC.LocalMultiaddr())
}

// Trust the transport? Yeah... right.
Expand Down
2 changes: 1 addition & 1 deletion p2p/net/swarm/swarm_listen.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ func (s *Swarm) AddListenAddr(a ma.Multiaddr) error {
}
canonicallog.LogPeerStatus(100, c.RemotePeer(), c.RemoteMultiaddr(), "connection_status", "established", "dir", "inbound")
if s.metricsTracer != nil {
s.metricsTracer.OpenedConnection(network.DirInbound, c.RemotePublicKey(), c.ConnState())
s.metricsTracer.OpenedConnection(network.DirInbound, c.RemotePublicKey(), c.ConnState(), c.LocalMultiaddr())
}

log.Debugf("swarm listener accepted connection: %s <-> %s", c.LocalMultiaddr(), c.RemoteMultiaddr())
Expand Down
Loading

0 comments on commit d9004d2

Please sign in to comment.