aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormat <github@matdoes.dev>2021-12-30 18:23:02 -0600
committermat <github@matdoes.dev>2021-12-30 18:23:02 -0600
commit8f1855732cd86f891e84d15cf63b404f5e46191e (patch)
tree68bcffa61ba4d978aad2cc931deb4e8b65da9449
parent2f0fcf231524feeec0344c9acb231014e8112efa (diff)
downloadskyblock-api-8f1855732cd86f891e84d15cf63b404f5e46191e.tar.gz
skyblock-api-8f1855732cd86f891e84d15cf63b404f5e46191e.tar.bz2
skyblock-api-8f1855732cd86f891e84d15cf63b404f5e46191e.zip
Update index.ts
-rw-r--r--src/index.ts16
1 files changed, 14 insertions, 2 deletions
diff --git a/src/index.ts b/src/index.ts
index 2612647..d6a18f7 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -6,7 +6,7 @@ import * as discord from './discord.js'
import express from 'express'
import { getKeyUsage } from './hypixelApi.js'
import { basicPlayerCache, basicProfilesCache, playerCache, profileCache, profileNameCache, profilesCache, usernameCache } from './hypixelCached.js'
-import { collectDefaultMetrics, register } from 'prom-client'
+import { collectDefaultMetrics, Counter, Gauge, register } from 'prom-client'
const app = express()
@@ -191,7 +191,19 @@ app.post('/accounts/update', async (req, res) => {
// grafana integration
collectDefaultMetrics()
-app.get('/metrics', async (_req, res) => {
+
+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)
+ }
+})
+
+app.get('/metrics', async (req, res) => {
+ console.log(req.params, req.headers)
try {
res.set('Content-Type', register.contentType)
res.end(await register.metrics())