diff --git a/grafana-panel,json b/grafana-panel,json new file mode 100644 index 0000000..a39557a --- /dev/null +++ b/grafana-panel,json @@ -0,0 +1,364 @@ +{ + "annotations": { + "list": [ + { + "builtIn": 1, + "datasource": "-- Grafana --", + "enable": true, + "hide": true, + "iconColor": "rgba(0, 211, 255, 1)", + "name": "Annotations & Alerts", + "target": { + "limit": 100, + "matchAny": false, + "tags": [], + "type": "dashboard" + }, + "type": "dashboard" + } + ] + }, + "editable": true, + "fiscalYearStartMonth": 0, + "graphTooltip": 0, + "id": 33, + "iteration": 1681026014890, + "links": [], + "liveNow": false, + "panels": [ + { + "collapsed": false, + "gridPos": { + "h": 1, + "w": 24, + "x": 0, + "y": 0 + }, + "id": 8, + "panels": [], + "title": "Row title", + "type": "row" + }, + { + "fieldConfig": { + "defaults": { + "color": { + "mode": "palette-classic" + }, + "custom": { + "axisLabel": "", + "axisPlacement": "auto", + "barAlignment": 0, + "drawStyle": "line", + "fillOpacity": 0, + "gradientMode": "none", + "hideFrom": { + "legend": false, + "tooltip": false, + "viz": false + }, + "lineInterpolation": "linear", + "lineWidth": 1, + "pointSize": 5, + "scaleDistribution": { + "type": "linear" + }, + "showPoints": "auto", + "spanNulls": false, + "stacking": { + "group": "A", + "mode": "none" + }, + "thresholdsStyle": { + "mode": "off" + } + }, + "decimals": 0, + "displayName": "Wins", + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + } + ] + } + }, + "overrides": [] + }, + "gridPos": { + "h": 9, + "w": 12, + "x": 0, + "y": 1 + }, + "id": 2, + "options": { + "legend": { + "calcs": [], + "displayMode": "list", + "placement": "bottom" + }, + "tooltip": { + "mode": "single" + } + }, + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "Jw3mnDJnz" + }, + "exemplar": true, + "expr": "fortnite_wins{username=\"$User\",gameType=\"$Gamemode\",app=\"fortnite-api\"}", + "interval": "", + "legendFormat": "", + "refId": "A" + } + ], + "title": "Wins ($Gamemode)", + "type": "timeseries" + }, + { + "collapsed": false, + "gridPos": { + "h": 1, + "w": 24, + "x": 0, + "y": 10 + }, + "id": 6, + "panels": [], + "title": "Row title", + "type": "row" + }, + { + "fieldConfig": { + "defaults": { + "color": { + "mode": "palette-classic" + }, + "custom": { + "axisLabel": "", + "axisPlacement": "auto", + "barAlignment": 0, + "drawStyle": "line", + "fillOpacity": 0, + "gradientMode": "none", + "hideFrom": { + "legend": false, + "tooltip": false, + "viz": false + }, + "lineInterpolation": "linear", + "lineWidth": 1, + "pointSize": 5, + "scaleDistribution": { + "type": "linear" + }, + "showPoints": "auto", + "spanNulls": false, + "stacking": { + "group": "A", + "mode": "none" + }, + "thresholdsStyle": { + "mode": "off" + } + }, + "displayName": "Kills", + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + } + ] + } + }, + "overrides": [] + }, + "gridPos": { + "h": 9, + "w": 12, + "x": 0, + "y": 11 + }, + "id": 4, + "options": { + "legend": { + "calcs": [], + "displayMode": "list", + "placement": "bottom" + }, + "tooltip": { + "mode": "single" + } + }, + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "Jw3mnDJnz" + }, + "exemplar": true, + "expr": "fortnite_kills{username=\"$User\",gameType=\"$Gamemode\",app=\"fortnite-api\"}", + "interval": "", + "legendFormat": "", + "refId": "A" + } + ], + "title": "Kills ($Gamemode)", + "type": "timeseries" + }, + { + "fieldConfig": { + "defaults": { + "color": { + "mode": "palette-classic" + }, + "custom": { + "axisLabel": "", + "axisPlacement": "auto", + "barAlignment": 0, + "drawStyle": "line", + "fillOpacity": 0, + "gradientMode": "none", + "hideFrom": { + "legend": false, + "tooltip": false, + "viz": false + }, + "lineInterpolation": "linear", + "lineWidth": 1, + "pointSize": 5, + "scaleDistribution": { + "type": "linear" + }, + "showPoints": "auto", + "spanNulls": false, + "stacking": { + "group": "A", + "mode": "none" + }, + "thresholdsStyle": { + "mode": "off" + } + }, + "displayName": "Deaths", + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + } + ] + } + }, + "overrides": [] + }, + "gridPos": { + "h": 9, + "w": 12, + "x": 12, + "y": 11 + }, + "id": 3, + "options": { + "legend": { + "calcs": [], + "displayMode": "list", + "placement": "bottom" + }, + "tooltip": { + "mode": "single" + } + }, + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "Jw3mnDJnz" + }, + "exemplar": true, + "expr": "fortnite_deaths{username=\"$User\",gameType=\"$Gamemode\",app=\"fortnite-api\"}", + "interval": "", + "legendFormat": "", + "refId": "A" + } + ], + "title": "Deaths ($Gamemode)", + "type": "timeseries" + } + ], + "refresh": "5s", + "schemaVersion": 34, + "style": "dark", + "tags": [], + "templating": { + "list": [ + { + "current": { + "selected": false, + "text": "RealFascinated", + "value": "RealFascinated" + }, + "definition": "label_values(fortnite_score{app=\"fortnite-api\"}, username)", + "hide": 0, + "includeAll": false, + "label": "Username", + "multi": false, + "name": "User", + "options": [], + "query": { + "query": "label_values(fortnite_score{app=\"fortnite-api\"}, username)", + "refId": "StandardVariableQuery" + }, + "refresh": 1, + "regex": "", + "skipUrlSync": false, + "sort": 0, + "type": "query" + }, + { + "current": { + "selected": false, + "text": "overall", + "value": "overall" + }, + "definition": "label_values(fortnite_score{app=\"fortnite-api\"}, gameType)", + "hide": 0, + "includeAll": false, + "label": "Gamemode", + "multi": false, + "name": "Gamemode", + "options": [], + "query": { + "query": "label_values(fortnite_score{app=\"fortnite-api\"}, gameType)", + "refId": "StandardVariableQuery" + }, + "refresh": 1, + "regex": "", + "skipUrlSync": false, + "sort": 0, + "type": "query" + } + ] + }, + "time": { + "from": "now-6h", + "to": "now" + }, + "timepicker": {}, + "timezone": "", + "title": "Fortnite Metrics", + "uid": "jkkaSLL4z", + "version": 5, + "weekStart": "" +} \ No newline at end of file diff --git a/src/index.js b/src/index.js index 28b7222..e755948 100644 --- a/src/index.js +++ b/src/index.js @@ -44,6 +44,12 @@ for (const metric of Object.values(metricTrackers)) { register.registerMetric(metric); } +const totalAccoutsMetric = new promClient.Gauge({ + name: "fortnite_total_accounts", + help: "Total number of accounts being tracked", +}); +register.registerMetric(totalAccoutsMetric); + // Track accounts before starting the server so we dont get no data trackAccounts(); setInterval(() => { @@ -65,6 +71,7 @@ app.get("/metrics", async (req, res) => { }); async function trackAccounts() { + totalAccoutsMetric.set(ACCOUNTS_TO_TRACK.length); for (const username of ACCOUNTS_TO_TRACK) { try { const account = await client.brStats({