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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
import { collectDefaultMetrics, Gauge, register } from 'prom-client'
import { fetchServerStats, fetchServerStatus } from './database.js'
import { getKeyUsage } from './hypixelApi.js'
export { register } from 'prom-client'
// grafana integration
collectDefaultMetrics()
const apiKeyCounter = new Gauge({
name: 'hypixel_api_key_usage',
help: 'API requests in the past minute.',
registers: [ register ],
collect() {
let keyUsage = getKeyUsage()
apiKeyCounter.set(keyUsage.usage)
}
})
const connectionsCounter = new Gauge({
name: 'mongodb_current_connections',
help: 'Number of active connections to the database.',
registers: [ register ],
async collect() {
let status = await fetchServerStatus()
connectionsCounter.set(status.connections.current)
networkBytesInCounter.set(status.network.bytesIn)
networkBytesOutCounter.set(status.network.bytesOut)
readCounter.set(status.opLatencies.reads.ops)
writeCounter.set(status.opLatencies.writes.ops)
}
})
const networkBytesInCounter = new Gauge({
name: 'mongodb_network_bytes_in',
help: 'Number of bytes received by the database.',
registers: [ register ],
})
const networkBytesOutCounter = new Gauge({
name: 'mongodb_network_bytes_out',
help: 'Number of bytes sent by the database.',
registers: [ register ],
})
const readCounter = new Gauge({
name: 'mongodb_read_ops',
help: 'Number of read operations by the database.',
registers: [ register ],
})
const writeCounter = new Gauge({
name: 'mongodb_write_ops',
help: 'Number of write operations by the database.',
registers: [ register ],
})
const dbSizeCounter = new Gauge({
name: 'mongodb_db_size',
help: 'Size of the database in bytes.',
registers: [ register ],
async collect() {
let stats = await fetchServerStats()
dbSizeCounter.set(stats.dataSize + stats.indexSize)
}
})
|