Skip to content

Commit

Permalink
add last handshake metric (#1)
Browse files Browse the repository at this point in the history
* feat: add latest handshake metric

* docs: add last handshake metric
  • Loading branch information
rogercoll authored Oct 29, 2022
1 parent d2356cc commit b7b533f
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ receivers:
```
peer.usage.rx_bytes
peer.usage.tx_bytes
peer.last_handshake
```

## Attributes
Expand Down
2 changes: 1 addition & 1 deletion metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ func peerToMetrics(ts time.Time, deviceName string, peer *wgtypes.Peer) pmetric.
resourceAttr := rs.Resource().Attributes()
resourceAttr.PutStr("peer.device.name", deviceName)
resourceAttr.PutStr("peer.name", peer.PublicKey.String())

ms := rs.ScopeMetrics().AppendEmpty().Metrics()
appendPeerMetrics(ms, peer, pbts)

Expand All @@ -29,6 +28,7 @@ func peerToMetrics(ts time.Time, deviceName string, peer *wgtypes.Peer) pmetric.
func appendPeerMetrics(ms pmetric.MetricSlice, peer *wgtypes.Peer, ts pcommon.Timestamp) {
gaugeI(ms, "usage.rx_bytes", "By", peer.ReceiveBytes, ts)
gaugeI(ms, "usage.tx_bytes", "By", peer.TransmitBytes, ts)
gaugeI(ms, "last_handshake", "s", int64(peer.LastHandshakeTime.Second()), ts)
}

func initMetric(ms pmetric.MetricSlice, name, unit string) pmetric.Metric {
Expand Down
2 changes: 1 addition & 1 deletion metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func assertPeerToMetrics(t *testing.T, peer *wgtypes.Peer, md pmetric.Metrics) {
assert.Equal(t, rsm.ScopeMetrics().Len(), 1)

metrics := rsm.ScopeMetrics().At(0).Metrics()
assert.Equal(t, metrics.Len(), 2)
assert.Equal(t, metrics.Len(), 3)
}

func getPeer() (*wgtypes.Peer, error) {
Expand Down

0 comments on commit b7b533f

Please sign in to comment.