Skip to content

Commit 6a55707

Browse files
committed
Add grafana and prometheues
1 parent cee1dec commit 6a55707

File tree

3 files changed

+122
-0
lines changed

3 files changed

+122
-0
lines changed

nixos/_grafana.nix

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
{config, ...}: {
2+
# Prometheus - monitoring system and time series database
3+
services.prometheus = {
4+
enable = true;
5+
port = 9090;
6+
7+
scrapeConfigs = [
8+
{
9+
job_name = "polkadot-validator";
10+
scrape_interval = "15s";
11+
static_configs = [{
12+
targets = ["localhost:${toString config.dotnix.polkadot-validator.prometheusPort}"];
13+
}];
14+
}
15+
{
16+
job_name = "prometheus";
17+
scrape_interval = "15s";
18+
static_configs = [{
19+
targets = ["localhost:9090"];
20+
}];
21+
}
22+
];
23+
};
24+
25+
# Grafana - visualization and analytics platform
26+
services.grafana = {
27+
enable = true;
28+
29+
settings = {
30+
server = {
31+
http_addr = "127.0.0.1"; # Only listen on localhost, nginx will proxy
32+
http_port = 3000;
33+
domain = "grafana.138-199-167-2.nip.io";
34+
root_url = "https://grafana.138-199-167-2.nip.io";
35+
serve_from_sub_path = false;
36+
enforce_domain = false;
37+
};
38+
39+
analytics = {
40+
reporting_enabled = false;
41+
};
42+
43+
security = {
44+
admin_user = "admin";
45+
admin_password = "admin"; # Grafana will prompt you to change this on first login
46+
};
47+
};
48+
49+
# Datasource configuration
50+
provision = {
51+
enable = true;
52+
53+
datasources.settings.datasources = [{
54+
name = "Prometheus";
55+
type = "prometheus";
56+
access = "proxy";
57+
url = "http://localhost:${toString config.services.prometheus.port}";
58+
isDefault = true;
59+
jsonData = {
60+
timeInterval = "15s";
61+
};
62+
}];
63+
};
64+
};
65+
66+
# Grafana and Prometheus are now only accessible via nginx reverse proxy
67+
# No direct firewall ports needed
68+
}

nixos/_nginx.nix

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
{config, lib, ...}: let
2+
publicIP = "138.199.167.2";
3+
domain = lib.replaceStrings ["."] ["-"] publicIP;
4+
baseDomain = "${domain}.nip.io";
5+
6+
grafanaDomain = "grafana.${baseDomain}";
7+
prometheusDomain = "prometheus.${baseDomain}";
8+
in {
9+
# ACME configuration for Let's Encrypt
10+
security.acme = {
11+
acceptTerms = true;
12+
defaults.email = "admin@${baseDomain}"; # Change this to your email
13+
};
14+
15+
# Nginx reverse proxy
16+
services.nginx = {
17+
enable = true;
18+
19+
recommendedProxySettings = true;
20+
recommendedTlsSettings = true;
21+
recommendedOptimisation = true;
22+
recommendedGzipSettings = true;
23+
24+
virtualHosts = {
25+
# Grafana with HTTPS
26+
"${grafanaDomain}" = {
27+
forceSSL = true;
28+
enableACME = true;
29+
30+
locations."/" = {
31+
proxyPass = "http://127.0.0.1:${toString config.services.grafana.settings.server.http_port}";
32+
proxyWebsockets = true;
33+
};
34+
};
35+
36+
"${prometheusDomain}" = {
37+
forceSSL = true;
38+
enableACME = true;
39+
40+
locations."/" = {
41+
proxyPass = "http://127.0.0.1:${toString config.services.prometheus.port}";
42+
};
43+
};
44+
};
45+
};
46+
47+
# Open HTTP and HTTPS ports
48+
networking.firewall.allowedTCPPorts = [
49+
80 # HTTP (needed for ACME challenge)
50+
443 # HTTPS
51+
];
52+
}

nixos/configuration.nix

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
inputs.disko.nixosModules.default
1010
./_base.nix
1111
./_disko.nix
12+
./_grafana.nix
13+
./_nginx.nix
1214
{
1315
environment.systemPackages = [
1416
inputs.polkadot-nix.packages.x86_64-linux.polkadot

0 commit comments

Comments
 (0)