Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[READY] - monitoring: grafana and prometheus service enabled #642

Merged
merged 5 commits into from
Jan 14, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
};
};
};
};
}
Loading