tsuki: set up proper grafana infrastructure

- Set up a bunch of exporters
- Download matching dashboard declarations
- Remove influxdb
This commit is contained in:
Oystein Kristoffer Tveit 2023-01-20 19:55:52 +01:00
parent b772e3eca3
commit 45497aea2b
Signed by: oysteikt
GPG Key ID: 9F2F7D8250F35146
14 changed files with 41663 additions and 64 deletions

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,914 @@
{
"__inputs": [
{
"name": "DS_PROMETHEUS",
"label": "Prometheus",
"description": "",
"type": "datasource",
"pluginId": "prometheus",
"pluginName": "Prometheus"
}
],
"__requires": [
{
"type": "panel",
"id": "gauge",
"name": "Gauge",
"version": ""
},
{
"type": "grafana",
"id": "grafana",
"name": "Grafana",
"version": "6.4.2"
},
{
"type": "panel",
"id": "graph",
"name": "Graph",
"version": ""
},
{
"type": "datasource",
"id": "prometheus",
"name": "Prometheus",
"version": "1.0.0"
},
{
"type": "panel",
"id": "singlestat",
"name": "Singlestat",
"version": ""
}
],
"annotations": {
"list": [
{
"builtIn": 1,
"datasource": "-- Grafana --",
"enable": true,
"hide": true,
"iconColor": "rgba(0, 211, 255, 1)",
"name": "Annotations & Alerts",
"type": "dashboard"
}
]
},
"editable": true,
"gnetId": null,
"graphTooltip": 1,
"id": null,
"iteration": 1577496234812,
"links": [],
"panels": [
{
"aliasColors": {},
"bars": false,
"dashLength": 10,
"dashes": false,
"datasource": "${DS_PROMETHEUS}",
"decimals": 0,
"fill": 1,
"fillGradient": 0,
"gridPos": {
"h": 7,
"w": 12,
"x": 0,
"y": 0
},
"id": 1,
"legend": {
"alignAsTable": false,
"avg": false,
"current": false,
"max": false,
"min": false,
"show": true,
"total": false,
"values": false
},
"lines": true,
"linewidth": 1,
"links": [],
"nullPointMode": "connected",
"options": {
"dataLinks": []
},
"percentage": false,
"pointradius": 5,
"points": false,
"renderer": "flot",
"seriesOverrides": [
{
"alias": "Unique",
"color": "#C0D8FF",
"dashes": true,
"lines": false
},
{
"alias": "/Online/",
"stack": true
}
],
"spaceLength": 10,
"stack": false,
"steppedLine": true,
"targets": [
{
"expr": "mc_players_total{server_name=~\"$server_name\"}",
"format": "time_series",
"intervalFactor": 2,
"legendFormat": "Unique",
"metric": "mc_players_total",
"refId": "A",
"step": 4
},
{
"expr": "sum(mc_players_online_total{server_name=~\"$server_name\"}) by (world)",
"legendFormat": "Online ({{world}})",
"refId": "B"
}
],
"thresholds": [],
"timeFrom": null,
"timeRegions": [],
"timeShift": null,
"title": "Players",
"tooltip": {
"shared": true,
"sort": 0,
"value_type": "individual"
},
"type": "graph",
"xaxis": {
"buckets": null,
"mode": "time",
"name": null,
"show": true,
"values": []
},
"yaxes": [
{
"decimals": 0,
"format": "short",
"label": null,
"logBase": 1,
"max": null,
"min": "0",
"show": true
},
{
"format": "short",
"label": null,
"logBase": 1,
"max": null,
"min": null,
"show": true
}
],
"yaxis": {
"align": false,
"alignLevel": null
}
},
{
"cacheTimeout": null,
"colorBackground": false,
"colorValue": true,
"colors": [
"rgba(245, 54, 54, 0.9)",
"rgba(237, 129, 40, 0.89)",
"rgba(50, 172, 45, 0.97)"
],
"datasource": "${DS_PROMETHEUS}",
"format": "none",
"gauge": {
"maxValue": 100,
"minValue": 0,
"show": false,
"thresholdLabels": false,
"thresholdMarkers": true
},
"gridPos": {
"h": 7,
"w": 4,
"x": 12,
"y": 0
},
"id": 2,
"interval": null,
"links": [],
"mappingType": 1,
"mappingTypes": [
{
"name": "value to text",
"value": 1
},
{
"name": "range to text",
"value": 2
}
],
"maxDataPoints": 100,
"nullPointMode": "connected",
"nullText": null,
"options": {},
"postfix": "",
"postfixFontSize": "50%",
"prefix": "",
"prefixFontSize": "50%",
"rangeMaps": [
{
"from": "null",
"text": "N/A",
"to": "null"
}
],
"sparkline": {
"fillColor": "rgba(31, 189, 42, 0.18)",
"full": false,
"lineColor": "rgb(31, 120, 193)",
"show": false
},
"tableColumn": "",
"targets": [
{
"expr": "sum(mc_players_online_total{server_name=~\"$server_name\"})",
"format": "time_series",
"interval": "",
"intervalFactor": 2,
"legendFormat": "",
"metric": "mc_players_total",
"refId": "A",
"step": 40
}
],
"thresholds": "0,1",
"title": "Players Online",
"type": "singlestat",
"valueFontSize": "200%",
"valueMaps": [
{
"op": "=",
"text": "N/A",
"value": "null"
}
],
"valueName": "current"
},
{
"datasource": "${DS_PROMETHEUS}",
"description": "",
"gridPos": {
"h": 7,
"w": 4,
"x": 16,
"y": 0
},
"id": 9,
"options": {
"fieldOptions": {
"calcs": [
"last"
],
"defaults": {
"links": [],
"mappings": [],
"max": 4000000000,
"min": 0,
"thresholds": [
{
"color": "green",
"value": null
},
{
"color": "red",
"value": 3000000000
}
],
"title": "",
"unit": "bytes"
},
"override": {},
"values": false
},
"orientation": "auto",
"showThresholdLabels": false,
"showThresholdMarkers": true
},
"pluginVersion": "6.4.2",
"targets": [
{
"expr": "mc_jvm_memory{type='allocated', server_name=~\"$server_name\"} - scalar(mc_jvm_memory{type='free', server_name=~\"$server_name\"})",
"instant": false,
"refId": "A"
}
],
"timeFrom": null,
"timeShift": null,
"title": "JVM Memory",
"type": "gauge"
},
{
"datasource": "${DS_PROMETHEUS}",
"description": "",
"gridPos": {
"h": 7,
"w": 4,
"x": 20,
"y": 0
},
"id": 10,
"options": {
"fieldOptions": {
"calcs": [
"mean"
],
"defaults": {
"links": [],
"mappings": [],
"max": 20,
"min": 0,
"thresholds": [
{
"color": "red",
"value": null
},
{
"color": "light-orange",
"value": 15
},
{
"color": "green",
"value": 18
}
],
"title": "",
"unit": "none"
},
"override": {},
"values": false
},
"orientation": "auto",
"showThresholdLabels": false,
"showThresholdMarkers": true
},
"pluginVersion": "6.4.2",
"targets": [
{
"expr": "mc_tps{server_name=~\"$server_name\"}",
"instant": true,
"legendFormat": "",
"refId": "A"
}
],
"timeFrom": null,
"timeShift": null,
"title": "TPS",
"type": "gauge"
},
{
"aliasColors": {},
"bars": false,
"dashLength": 10,
"dashes": false,
"datasource": "${DS_PROMETHEUS}",
"fill": 1,
"fillGradient": 0,
"gridPos": {
"h": 7,
"w": 12,
"x": 0,
"y": 7
},
"id": 3,
"legend": {
"avg": false,
"current": false,
"max": false,
"min": false,
"show": true,
"total": false,
"values": false
},
"lines": true,
"linewidth": 1,
"links": [],
"nullPointMode": "connected",
"options": {
"dataLinks": []
},
"percentage": false,
"pointradius": 5,
"points": false,
"renderer": "flot",
"seriesOverrides": [],
"spaceLength": 10,
"stack": false,
"steppedLine": false,
"targets": [
{
"expr": "mc_loaded_chunks_total{server_name=~\"$server_name\"}",
"format": "time_series",
"intervalFactor": 2,
"legendFormat": "{{world}}",
"metric": "mc_loaded_chunks_total",
"refId": "A",
"step": 4
}
],
"thresholds": [],
"timeFrom": null,
"timeRegions": [],
"timeShift": null,
"title": "Loaded Chunks",
"tooltip": {
"shared": true,
"sort": 0,
"value_type": "individual"
},
"type": "graph",
"xaxis": {
"buckets": null,
"mode": "time",
"name": null,
"show": true,
"values": []
},
"yaxes": [
{
"format": "short",
"label": null,
"logBase": 1,
"max": null,
"min": null,
"show": true
},
{
"format": "short",
"label": null,
"logBase": 1,
"max": null,
"min": null,
"show": true
}
],
"yaxis": {
"align": false,
"alignLevel": null
}
},
{
"aliasColors": {},
"bars": false,
"dashLength": 10,
"dashes": false,
"datasource": "${DS_PROMETHEUS}",
"fill": 1,
"fillGradient": 0,
"gridPos": {
"h": 7,
"w": 12,
"x": 12,
"y": 7
},
"id": 5,
"legend": {
"avg": false,
"current": false,
"max": false,
"min": false,
"show": true,
"total": false,
"values": false
},
"lines": true,
"linewidth": 1,
"links": [],
"nullPointMode": "connected",
"options": {
"dataLinks": []
},
"percentage": false,
"pointradius": 5,
"points": false,
"renderer": "flot",
"seriesOverrides": [],
"spaceLength": 10,
"stack": false,
"steppedLine": true,
"targets": [
{
"expr": "mc_jvm_memory{type='max', server_name=~\"$server_name\"}",
"format": "time_series",
"hide": false,
"intervalFactor": 1,
"legendFormat": "Allocated",
"metric": "mc_jvm_memory",
"refId": "A",
"step": 4
},
{
"expr": "mc_jvm_memory{type='allocated', server_name=~\"$server_name\"} - scalar(mc_jvm_memory{type='free', server_name=~\"$server_name\"})",
"format": "time_series",
"instant": false,
"intervalFactor": 1,
"legendFormat": "Used",
"refId": "B",
"step": 4
},
{
"expr": "mc_jvm_memory{type='allocated', server_name=~\"$server_name\"}",
"hide": true,
"refId": "C"
}
],
"thresholds": [],
"timeFrom": null,
"timeRegions": [],
"timeShift": null,
"title": "JVM Memory",
"tooltip": {
"shared": true,
"sort": 0,
"value_type": "individual"
},
"type": "graph",
"xaxis": {
"buckets": null,
"mode": "time",
"name": null,
"show": true,
"values": []
},
"yaxes": [
{
"format": "bytes",
"label": "",
"logBase": 1,
"max": null,
"min": "0",
"show": true
},
{
"format": "short",
"label": null,
"logBase": 1,
"max": null,
"min": null,
"show": true
}
],
"yaxis": {
"align": false,
"alignLevel": null
}
},
{
"aliasColors": {},
"bars": false,
"dashLength": 10,
"dashes": false,
"datasource": "${DS_PROMETHEUS}",
"fill": 1,
"fillGradient": 0,
"gridPos": {
"h": 7,
"w": 12,
"x": 0,
"y": 14
},
"id": 4,
"legend": {
"alignAsTable": false,
"avg": false,
"current": false,
"max": false,
"min": false,
"rightSide": false,
"show": true,
"total": false,
"values": false
},
"lines": true,
"linewidth": 1,
"links": [],
"nullPointMode": "connected",
"options": {
"dataLinks": []
},
"percentage": false,
"pointradius": 5,
"points": false,
"renderer": "flot",
"seriesOverrides": [],
"spaceLength": 10,
"stack": false,
"steppedLine": false,
"targets": [
{
"expr": "sum (mc_entities_total{server_name=~\"$server_name\"}) by (world)",
"format": "time_series",
"hide": false,
"intervalFactor": 2,
"legendFormat": "{{world}}_total",
"metric": "mc_entities_total",
"refId": "A",
"step": 4
}
],
"thresholds": [],
"timeFrom": null,
"timeRegions": [],
"timeShift": null,
"title": "Entities",
"tooltip": {
"shared": true,
"sort": 0,
"value_type": "individual"
},
"type": "graph",
"xaxis": {
"buckets": null,
"mode": "time",
"name": null,
"show": true,
"values": []
},
"yaxes": [
{
"format": "short",
"label": null,
"logBase": 1,
"max": null,
"min": null,
"show": true
},
{
"format": "short",
"label": null,
"logBase": 1,
"max": null,
"min": null,
"show": true
}
],
"yaxis": {
"align": false,
"alignLevel": null
}
},
{
"aliasColors": {},
"bars": false,
"dashLength": 10,
"dashes": false,
"datasource": "${DS_PROMETHEUS}",
"decimals": 2,
"description": "",
"fill": 1,
"fillGradient": 0,
"gridPos": {
"h": 7,
"w": 12,
"x": 12,
"y": 14
},
"id": 7,
"legend": {
"avg": false,
"current": true,
"hideEmpty": false,
"max": false,
"min": true,
"rightSide": false,
"show": true,
"total": false,
"values": true
},
"lines": true,
"linewidth": 1,
"links": [],
"nullPointMode": "connected",
"options": {
"dataLinks": []
},
"percentage": false,
"pointradius": 5,
"points": false,
"renderer": "flot",
"seriesOverrides": [],
"spaceLength": 10,
"stack": false,
"steppedLine": true,
"targets": [
{
"expr": "mc_tps{server_name=~\"$server_name\"}",
"format": "time_series",
"intervalFactor": 2,
"legendFormat": "TPS",
"metric": "mc_tps",
"refId": "A",
"step": 4
}
],
"thresholds": [],
"timeFrom": null,
"timeRegions": [],
"timeShift": null,
"title": "Tickrate",
"tooltip": {
"shared": true,
"sort": 0,
"value_type": "individual"
},
"type": "graph",
"xaxis": {
"buckets": null,
"mode": "time",
"name": null,
"show": true,
"values": []
},
"yaxes": [
{
"format": "none",
"label": "",
"logBase": 1,
"max": "20",
"min": "0",
"show": true
},
{
"format": "short",
"label": null,
"logBase": 1,
"max": null,
"min": null,
"show": false
}
],
"yaxis": {
"align": false,
"alignLevel": null
}
},
{
"aliasColors": {},
"bars": false,
"dashLength": 10,
"dashes": false,
"datasource": "${DS_PROMETHEUS}",
"fill": 1,
"fillGradient": 0,
"gridPos": {
"h": 7,
"w": 12,
"x": 0,
"y": 21
},
"id": 11,
"legend": {
"alignAsTable": false,
"avg": false,
"current": false,
"max": false,
"min": false,
"rightSide": false,
"show": true,
"total": false,
"values": false
},
"lines": true,
"linewidth": 1,
"links": [],
"nullPointMode": "null as zero",
"options": {
"dataLinks": []
},
"percentage": false,
"pointradius": 5,
"points": false,
"renderer": "flot",
"seriesOverrides": [],
"spaceLength": 10,
"stack": true,
"steppedLine": true,
"targets": [
{
"expr": "sum (mc_villagers_total{server_name=~\"$server_name\"}) by (world, level, profession)",
"format": "time_series",
"hide": false,
"intervalFactor": 2,
"legendFormat": "{{world}}: {{profession}} (lv{{level}})",
"metric": "mc_entities_total",
"refId": "A",
"step": 4
}
],
"thresholds": [],
"timeFrom": null,
"timeRegions": [],
"timeShift": null,
"title": "Villagers",
"tooltip": {
"shared": true,
"sort": 0,
"value_type": "individual"
},
"type": "graph",
"xaxis": {
"buckets": null,
"mode": "time",
"name": null,
"show": true,
"values": []
},
"yaxes": [
{
"decimals": 0,
"format": "short",
"label": null,
"logBase": 1,
"max": null,
"min": null,
"show": true
},
{
"format": "short",
"label": null,
"logBase": 1,
"max": null,
"min": null,
"show": true
}
],
"yaxis": {
"align": false,
"alignLevel": null
}
}
],
"refresh": "30s",
"schemaVersion": 20,
"style": "dark",
"tags": [],
"templating": {
"list": [
{
"allValue": ".+",
"current": {},
"datasource": "${DS_PROMETHEUS}",
"definition": "",
"hide": 0,
"includeAll": false,
"label": "Server Name",
"multi": false,
"name": "server_name",
"options": [],
"query": "label_values(mc_players_total, server_name)",
"refresh": 1,
"regex": "",
"skipUrlSync": false,
"sort": 1,
"tagValuesQuery": "",
"tags": [],
"tagsQuery": "",
"type": "query",
"useTags": false
}
]
},
"time": {
"from": "now-30m",
"to": "now"
},
"timepicker": {
"refresh_intervals": [
"5s",
"10s",
"30s",
"1m",
"5m",
"15m",
"30m",
"1h",
"2h",
"1d"
],
"time_options": [
"5m",
"15m",
"1h",
"6h",
"12h",
"24h",
"2d",
"7d",
"30d"
]
},
"timezone": "browser",
"title": "Minecraft",
"version": 1
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,8 +1,7 @@
{ config, lib, secrets, ... }:
{ pkgs, config, lib, secrets, ... }:
{
imports = [
./prometheus.nix
./influxdb.nix
./loki.nix
];
@ -10,6 +9,54 @@
enable = true;
dataDir = "${config.machineVars.dataDrives.default}/var/grafana";
provision = {
enable = true;
datasources.settings.datasources = [
{
name = "Prometheus";
type = "prometheus";
access = "proxy";
url = "http://localhost:${toString config.services.prometheus.port}";
isDefault = true;
}
];
dashboards.settings.providers = let
makeReadOnly = x: lib.pipe x [
builtins.readFile
builtins.fromJSON
(x: x // { editable = false; })
builtins.toJSON
(pkgs.writeText (builtins.baseNameOf x))
];
in [
{
name = "Matrix Synapse";
options.path = makeReadOnly ./dashboards/matrix-synapse.json;
}
{
name = "PostgreSQL";
options.path = makeReadOnly ./dashboards/postgres.json;
}
{
name = "Node";
options.path = makeReadOnly ./dashboards/node.json;
}
# See https://github.com/grafana/grafana/issues/10786
# {
# name = "Redis";
# options.path = ./dashboards/redis.json;
# }
# {
# name = "Minecraft";
# options.path = makeReadOnly ./dashboards/minecraft.json;
# }
];
};
settings = {
server = {
domain = "log.nani.wtf";

View File

@ -1,16 +0,0 @@
{ config, secrets, ... }:
{
# services.influxdb = {
# enable = true;
# dataDir = "${config.machineVars.dataDrives.default}/var/influxdb";
# extraConfig = {
# udp = {
# enabled = true;
# bind-address = "0.0.0.0:8089";
# database = "proxmox";
# batch-size = 1000;
# batch-timeout = "1s";
# };
# };
# };
}

View File

@ -0,0 +1,28 @@
{ lib, config, ... }:
{
services.prometheus.scrapeConfigs =
lib.pipe config.services.matrix-synapse-next.workers.instances [
(lib.mapAttrsToList (_: v: v))
# Add metrics for main process to the list of workers
(x: x ++ [{ type = "master"; index = 1; settings.worker_listeners = [{ port = 9000; }]; }])
(map (w: let
port = lib.pipe w.settings.worker_listeners [
lib.last
(l: l.port)
toString
];
in {
job_name = "synapse-${port}";
scrape_interval = "15s";
metrics_path = "/_synapse/metrics";
static_configs = [{
targets = [ "localhost:${port}" ];
labels = {
instance = "matrix.nani.wtf";
job = w.type;
index = toString w.index;
};
}];
}))
];
}

View File

@ -0,0 +1,15 @@
{ ... }:
{
services.prometheus.scrapeConfigs = [{
job_name = "minecraft";
scrape_interval = "15s";
static_configs = [
{
targets = [ "localhost:9225" ];
labels = {
server_name = "kakuland";
};
}
];
}];
}

View File

@ -0,0 +1,18 @@
{ ... }:
{
services.prometheus = {
scrapeConfigs = [{
job_name = "node";
scrape_interval = "15s";
static_configs = [{
targets = [ "localhost:10393" ];
}];
}];
exporters.node = {
enable = true;
port = 10393;
enabledCollectors = [ "systemd" ];
};
};
}

View File

@ -0,0 +1,21 @@
{ ... }:
{
services.prometheus = {
scrapeConfigs = [{
job_name = "postgres";
scrape_interval = "15s";
static_configs = [
{
targets = [ "localhost:10392" ];
}
];
}];
exporters.postgres = {
enable = true;
port = 10392;
runAsLocalSuperUser = true;
extraFlags = [ "--auto-discover-databases" ];
};
};
}

View File

@ -0,0 +1,17 @@
{ ... }:
{
services.prometheus = {
scrapeConfigs = [{
job_name = "redis";
scrape_interval = "15s";
static_configs = [{
targets = [ "localhost:10394" ];
}];
}];
exporters.redis = {
enable = true;
port = 10394;
};
};
}

View File

@ -0,0 +1,21 @@
{ ... }:
{
services.prometheus = {
scrapeConfigs = [{
job_name = "systemd";
scrape_interval = "15s";
static_configs = [{
targets = [ "localhost:10395" ];
}];
}];
exporters.systemd = {
enable = true;
port = 10395;
extraFlags = [
"--systemd.collector.enable-restart-count"
"--systemd.collector.enable-ip-accounting"
];
};
};
}

View File

@ -1,52 +1,17 @@
{ secrets, ... }: {
# TODO: Autogenerate port infrastructure
imports = [
./prometheus-exporters/matrix-synapse.nix
./prometheus-exporters/node.nix
./prometheus-exporters/postgres.nix
./prometheus-exporters/redis.nix
./prometheus-exporters/systemd.nix
./prometheus-exporters/minecraft.nix
];
services.prometheus = {
enable = true;
port = secrets.ports.prometheus;
scrapeConfigs = [
{
job_name = "synapse";
scrape_interval = "15s";
metrics_path = "/_synapse/metrics";
static_configs = [
{
targets = [ "localhost:${toString secrets.ports.matrix.listener}" ];
}
];
}
# {
# job_name = "minecraft";
# # scrape_interval = "15s";
# # metrics_path = "/_synapse/metrics";
# static_configs = [
# {
# targets = [ "${secrets.ips.crafty}:${toString secrets.ports.prometheus-crafty}" ];
# labels = {
# server_name = "my-minecraft-server";
# };
# }
# ];
# }
];
exporters = {
# jitsi.enable = true;
nginx.enable = true;
nginxlog.enable = true;
systemd.enable = true;
# openldap
# openvpn
# nextcloud
# influxdb
# wireguard
# postgres = {
# enable = true;
# };
};
# globalConfig = {
# };
};
}