Skip to content

Commit

Permalink
monitoring: grafana and prometheus service enabled
Browse files Browse the repository at this point in the history
This enables the foundations for grafana and prometheus services on the
monitoring vm. Currently we still need to:

  - Enable TLS
  - Generate a static configs for scapers
  - Enable prometheus exporters on Servers
  - Enable prometheus exporters on APs
  - Enable prometheus exporters on Pis

This will be done in follow up PRs.

Prometheus is also added as a common nixos module so that it can be
consumed from other machines.
  • Loading branch information
sarcasticadmin committed Nov 25, 2023
1 parent 74b10ec commit 319aaed
Show file tree
Hide file tree
Showing 3 changed files with 116 additions and 0 deletions.
20 changes: 20 additions & 0 deletions nix/machines/_common/prometheus.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{ ... }:
let
port = 9100;
in
{
networking.firewall.allowedTCPPorts = [ port ];

services.prometheus.exporters.node = {
enable = true;
port = port;
enabledCollectors = [
"logind"
"systemd"
"network_route"
];
disabledCollectors = [
"textfile"
];
};
}
8 changes: 8 additions & 0 deletions nix/machines/flake-module.nix
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ in
];
specialArgs = { inherit inputs; };
};
monitor = lib.nixosSystem {
inherit system;
modules = [
common
./monitor.nix
];
specialArgs = { inherit inputs; };
};
massflash = lib.nixosSystem {
inherit system;
modules = [
Expand Down
88 changes: 88 additions & 0 deletions nix/machines/monitor.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
{ config, lib, pkgs, ... }:
let
hostname = "monitoring.scale.lan";
in
{
imports =
[
./_common/prometheus.nix
];

# If not present then warning and will be set to latest release during build
system.stateVersion = "23.05";

boot.kernelParams = [ "console=ttyS0" "boot.shell_on_fail" ];

networking.firewall.allowedTCPPorts = [ 80 443 ];

# TODO: How to handle sudo esculation
security.sudo.wheelNeedsPassword = false;

environment.systemPackages = with pkgs; [
vim
git
bintools
];

services = {
openssh = {
enable = true;
};

prometheus = {
enable = true;
enableReload = true;
scrapeConfigs = [
{
job_name = "prometheus";
static_configs = [
{
targets = [ "localhost:${toString config.services.prometheus.exporters.node.port}" ];
labels = { instance = "localhost"; };
}
];
}
];
};

grafana = {
enable = true;
settings = {
server = {
http_addr = "127.0.0.1";
http_port = 3000;
domain = "${hostname}";
};
analytics.reporting_enabled = false;
};
provision = {
# Can use just datasources anymore
# https://github.com/NixOS/nixpkgs/blob/41de143fda10e33be0f47eab2bfe08a50f234267/nixos/modules/services/monitoring/grafana.nix#L101-L104
datasources.settings.datasources = [
{
name = "prometheus";
type = "prometheus";
access = "proxy";
url = "http://127.0.0.1:${toString config.services.prometheus.port}";
}
];
};
};

nginx = {
enable = true;
# TODO: TLS enabled
# Good example enable TLS, but would like to keep it out of the /nix/store
# ref: https://github.com/NixOS/nixpkgs/blob/c6fd903606866634312e40cceb2caee8c0c9243f/nixos/tests/custom-ca.nix#L80
virtualHosts."${hostname}" = {
default = true;
# ACME wont work for us on the private network
enableACME = false;
locations."/" = {
proxyPass = "http://${toString config.services.grafana.settings.server.http_addr}:${toString config.services.grafana.settings.server.http_port}/";
proxyWebsockets = true;
};
};
};
};
}

0 comments on commit 319aaed

Please sign in to comment.