FokiDoki / WireRest

REST API for Wireguard
MIT License
18 stars 5 forks source link

Help me add an indicator #72

Closed PPMagick closed 4 months ago

PPMagick commented 4 months ago

I want an indicator that will show the number of peers that are currently connected to the server, in digital form or as a fill scale, please help

FokiDoki commented 4 months ago

Hello! At this time, the WireRest monitoring endpoint does not provide any data about currently connected peers. But you can make your own exporter based on WireRest.

You can get information about currently connected users by sending a request to /v1/peers. Docs

curl -X 'GET' \
  'http://WIREREST_IP:WIREREST_PORT/v1/peers?sort=lastHandshakeTime.DESC' \
  -H 'accept: application/json'

There is latestHandshake timestamp when user was connected last time. Then you need to select a time that will conditionally indicate that the user is connected (timeout). 5 minutes, for example. And accordingly if currentTimestamp-timeout-peerTimestamp<=0 then the user is connected. Now you have recently connected peers (with a slight delay, since wireguard does not allow you to see who is connected live). Set up a web server and distribute the data needed for prometheus from it. Connect your exporter to prometheus. Profit