-
Notifications
You must be signed in to change notification settings - Fork 2
/
pinner-metrics.js
39 lines (34 loc) · 1.69 KB
/
pinner-metrics.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
'use strict'
// How often to update the metrics
const REFRESH_INTERVAL = 5000
module.exports = (pinner) => {
const client = require('prom-client')
const register = client.register
client.collectDefaultMetrics()
const metrics = {
totalConnectedPeers: new client.Gauge({ name: 'peerstar_peers', help: 'total peers connected' }),
totalCollaborations: new client.Gauge({ name: 'peerstar_collaborations', help: 'total number of active collaborations' })
}
setInterval(() => {
const numberOfCollabs = pinner._collaborations.size
metrics.totalCollaborations.set(numberOfCollabs)
if (!pinner.ipfs) return
try {
pinner.ipfs.swarm.peers((err, peers) => {
if (err) {
throw err
}
metrics.totalConnectedPeers.set(peers.length)
})
} catch (e) {
console.error('metrics exception:', e)
}
}, REFRESH_INTERVAL)
// const dialsSuccessTotal = new client.Counter({ name: 'rendezvous_dials_total_success', help: 'sucessfully completed dials since server started' })
// const dialsFailureTotal = new client.Counter({ name: 'rendezvous_dials_total_failure', help: 'failed dials since server started' })
// const dialsTotal = new client.Counter({ name: 'rendezvous_dials_total', help: 'all dials since server started' })
// const joinsSuccessTotal = new client.Counter({ name: 'rendezvous_joins_total_success', help: 'sucessfully completed joins since server started' })
// const joinsFailureTotal = new client.Counter({ name: 'rendezvous_joins_total_failure', help: 'failed joins since server started' })
// const joinsTotal = new client.Counter({ name: 'rendezvous_joins_total', help: 'all joins since server started' })
return register
}