aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAkshay Nair <phenax5@gmail.com>2025-06-13 21:50:54 +0530
committerAkshay Nair <phenax5@gmail.com>2025-06-13 21:50:54 +0530
commite11b9a851851bb47109545093e3accdbcab76859 (patch)
treee733232829ccca32d6ff3cfc88e4794222448676
parent6df186662a37b17015959bf0d6b456ab282b1826 (diff)
downloadhomeserver-nixos-config-e11b9a851851bb47109545093e3accdbcab76859.tar.gz
homeserver-nixos-config-e11b9a851851bb47109545093e3accdbcab76859.zip
Add grafana+prometheus + embed into dashboard
-rw-r--r--configuration.nix1
-rw-r--r--modules/dashboard/dashboard-template.nix17
-rw-r--r--modules/dashboard/default.nix14
-rw-r--r--modules/monitoring/default.nix7
-rw-r--r--modules/monitoring/grafana.nix29
-rw-r--r--modules/monitoring/prometheus.nix34
-rw-r--r--modules/network/default.nix1
-rw-r--r--modules/network/service-router.service.nix19
-rw-r--r--settings.nix3
9 files changed, 117 insertions, 8 deletions
diff --git a/configuration.nix b/configuration.nix
index 8acda64..af520fb 100644
--- a/configuration.nix
+++ b/configuration.nix
@@ -8,6 +8,7 @@
./modules/dashboard
./modules/storage
./modules/notifications
+ ./modules/monitoring
];
nixpkgs.config.allowUnfree = true;
diff --git a/modules/dashboard/dashboard-template.nix b/modules/dashboard/dashboard-template.nix
index 5a99e20..43812a0 100644
--- a/modules/dashboard/dashboard-template.nix
+++ b/modules/dashboard/dashboard-template.nix
@@ -52,7 +52,7 @@ let
grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
padding: 0 1rem;
width: 100%;
- margin: 1rem auto;
+ margin: 1rem auto 2rem;
max-width: 1200px
}
.card {
@@ -93,6 +93,18 @@ let
margin: 0;
border: 0;
}
+ .stats-container {
+ padding: 1rem;
+ border-top: 1px solid #1a1824;
+ }
+ .stats-container iframe {
+ width: 100%;
+ display: block;
+ min-height: 1100px;
+ height: 100%;
+ border: 2px solid #1a1824;
+ border-radius: 5px;
+ }
'';
headerHTML = ''
@@ -115,6 +127,9 @@ in
<section class="links-container">
${concatStringsSep "" (map linkHTML links)}
</section>
+ <section class="stats-container">
+ <iframe src="http://grafana.local/public-dashboards/4d3d386f6eb9475bb202fe793c0a72c3"></iframe>
+ </section>
<script>${script}</script>
</body>
</html>
diff --git a/modules/dashboard/default.nix b/modules/dashboard/default.nix
index 9e434c2..42583dd 100644
--- a/modules/dashboard/default.nix
+++ b/modules/dashboard/default.nix
@@ -47,6 +47,20 @@ in
altUrl = "http://${settings.network.host}:${toString ports.syncthing}";
color = "#0891d1";
}
+ {
+ title = "Ntfy-sh";
+ key = "n";
+ url = "http://ntfy.local";
+ altUrl = "http://${settings.network.host}:${toString ports.ntfy}";
+ color = "#2dc9b5";
+ }
+ {
+ title = "Grafana";
+ key = "g";
+ url = "http://grafana.local";
+ altUrl = "http://${settings.network.host}:${toString ports.grafana}";
+ color = "#f05a28";
+ }
];
};
}
diff --git a/modules/monitoring/default.nix b/modules/monitoring/default.nix
new file mode 100644
index 0000000..d93681b
--- /dev/null
+++ b/modules/monitoring/default.nix
@@ -0,0 +1,7 @@
+{ ... }:
+{
+ imports = [
+ ./grafana.nix
+ ./prometheus.nix
+ ];
+}
diff --git a/modules/monitoring/grafana.nix b/modules/monitoring/grafana.nix
new file mode 100644
index 0000000..8e98ffc
--- /dev/null
+++ b/modules/monitoring/grafana.nix
@@ -0,0 +1,29 @@
+{ lib, ... }:
+let
+ settings = import ../../settings.nix { inherit lib; };
+ ports = settings.network.ports;
+in
+{
+ services.grafana = {
+ enable = true;
+ settings = {
+ server = {
+ protocol = "http";
+ http_addr = "0.0.0.0";
+ http_port = ports.grafana;
+ domain = "grafana.local";
+ serve_from_sub_path = true;
+ };
+ security = {
+ secret_key = settings.grafana.secretKey;
+ allow_sign_up = false;
+ disable_initial_admin_creation = false;
+ disable_gravatar = true;
+ admin_user = settings.grafana.adminUser;
+ admin_email = settings.grafana.adminEmail;
+ admin_password = settings.grafana.adminPassword;
+ allow_embedding = true;
+ };
+ };
+ };
+}
diff --git a/modules/monitoring/prometheus.nix b/modules/monitoring/prometheus.nix
new file mode 100644
index 0000000..5f71c58
--- /dev/null
+++ b/modules/monitoring/prometheus.nix
@@ -0,0 +1,34 @@
+{ lib, ... }:
+let
+ settings = import ../../settings.nix { inherit lib; };
+ ports = settings.network.ports;
+in
+{
+ services.prometheus = {
+ enable = true;
+ port = ports.prometheus;
+
+ exporters.node = {
+ enable = true;
+ port = ports.prometheusNodeExporter;
+ enabledCollectors = [ "systemd" ];
+ extraFlags = [
+ "--collector.ethtool"
+ "--collector.softirqs"
+ "--collector.tcpstat"
+ "--collector.wifi"
+ ];
+ };
+
+ scrapeConfigs = [
+ {
+ job_name = "system";
+ scrape_interval = "10s";
+ static_configs = [{
+ targets = [ "127.0.0.1:${toString ports.prometheusNodeExporter}" ];
+ }];
+ }
+ ];
+ };
+}
+
diff --git a/modules/network/default.nix b/modules/network/default.nix
index 55a4c43..f6263f5 100644
--- a/modules/network/default.nix
+++ b/modules/network/default.nix
@@ -22,6 +22,7 @@ in
"lidarr.local" = { inherit host; port = ports.lidarr; };
"git.local" = { inherit host; port = 80; basePath = "/gitweb/"; };
"ntfy.local" = { inherit host; port = ports.ntfy; };
+ "grafana.local" = { inherit host; port = ports.grafana; extraOptions.recommendedProxySettings = true; };
};
};
diff --git a/modules/network/service-router.service.nix b/modules/network/service-router.service.nix
index 3d0b6e7..14fc1b2 100644
--- a/modules/network/service-router.service.nix
+++ b/modules/network/service-router.service.nix
@@ -21,6 +21,7 @@ in {
protocol = mkOption { type = types.str; default = "http"; };
basePath = mkOption { type = types.str; default = ""; };
nginx = mkOption { type = types.attrs; default = {}; };
+ extraOptions = mkOption { type = types.attrs; default = {}; };
}; });
default = {};
};
@@ -30,13 +31,17 @@ in {
services.nginx = {
enable = true;
recommendedOptimisation = true;
- virtualHosts = lib.mapAttrs (_: val: {
- locations."/" = if val.nginx == {} then {
- proxyPass =
- "${val.protocol}://${val.host}:${toString val.port}${val.basePath}";
- proxyWebsockets = true;
- } else val.nginx;
- }) cfg.routes;
+ virtualHosts = lib.mapAttrs (_: val:
+ let
+ opts = if hasAttr "extraOptions" val then val.extraOptions else {};
+ in {
+ locations."/" = if val.nginx == {} then {
+ proxyPass =
+ "${val.protocol}://${val.host}:${toString val.port}${val.basePath}";
+ proxyWebsockets = true;
+ } // opts else val.nginx;
+ }
+ ) cfg.routes;
};
services.nsd = {
diff --git a/settings.nix b/settings.nix
index 041e375..06c10a0 100644
--- a/settings.nix
+++ b/settings.nix
@@ -14,6 +14,9 @@ in lib.recursiveUpdate privateSettings rec {
transmissionRPC = 9091;
syncthing = 3141;
ntfy = 3142;
+ grafana = 3143;
+ prometheus = 9001;
+ prometheusNodeExporter = 9002;
};
exposeTransmissionRPC = false;
};