diff options
author | mat <github@matdoes.dev> | 2021-12-30 22:02:36 -0600 |
---|---|---|
committer | mat <github@matdoes.dev> | 2021-12-30 22:02:36 -0600 |
commit | 0493cb2600f16ae38ab0d0f496358dcd6030ebe0 (patch) | |
tree | 0d3c377a85366253526c2e97c2cec11441ef2755 /src/metrics.ts | |
parent | 1dc1752adf4b3191fe3debf8a0dc8b4f78b37950 (diff) | |
download | skyblock-api-0493cb2600f16ae38ab0d0f496358dcd6030ebe0.tar.gz skyblock-api-0493cb2600f16ae38ab0d0f496358dcd6030ebe0.tar.bz2 skyblock-api-0493cb2600f16ae38ab0d0f496358dcd6030ebe0.zip |
database metrics
Diffstat (limited to 'src/metrics.ts')
-rw-r--r-- | src/metrics.ts | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/src/metrics.ts b/src/metrics.ts new file mode 100644 index 0000000..9db3ec3 --- /dev/null +++ b/src/metrics.ts @@ -0,0 +1,54 @@ +import { collectDefaultMetrics, Gauge, register } from 'prom-client' +import { 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) + queryOpCounter.set(status.opcounters.query) + updateOpCounter.set(status.opcounters.update) + } +}) +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 queryOpCounter = new Gauge({ + name: 'mongodb_query_op_count', + help: 'Number of queries executed by the database.', + registers: [ register ], +}) +const updateOpCounter = new Gauge({ + name: 'mongodb_update_op_count', + help: 'Number of updates executed by the database.', + registers: [ register ], +}) + + |