Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: NixOS/nixpkgs
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 05f368b60a68
Choose a base ref
...
head repository: NixOS/nixpkgs
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 6795bdd58ca1
Choose a head ref
  • 2 commits
  • 1 file changed
  • 1 contributor

Commits on Nov 4, 2018

  1. nixos/prometheus: add package option

    With a package option we can let the user decide what package to use for
    prometheus without requiring an overlay.
    andir authored and globin committed Nov 4, 2018
    Copy the full SHA
    0de150e View commit details
  2. nixos/prometheus: check configuration before starting service

    With `promtool` we can check the validity of a configuration before
    deploying it. This avoids situations where you would end up with a
    broken monitoring system without noticing it - since the monitoring
    broke down. :-)
    andir authored and globin committed Nov 4, 2018

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    6795bdd View commit details
Showing with 23 additions and 6 deletions.
  1. +23 −6 nixos/modules/services/monitoring/prometheus/default.nix
29 changes: 23 additions & 6 deletions nixos/modules/services/monitoring/prometheus/default.nix
Original file line number Diff line number Diff line change
@@ -10,6 +10,13 @@ let
# Get a submodule without any embedded metadata:
_filter = x: filterAttrs (k: v: k != "_module") x;

# a wrapper that verifies that the configuration is valid
promtoolCheck = what: name: file: pkgs.runCommand "${name}-${what}-checked"
{ buildInputs = [ cfg.package ]; } ''
ln -s ${file} $out
promtool ${what} $out
'';

# Pretty-print JSON to a file
writePrettyJSON = name: x:
pkgs.runCommand name { } ''
@@ -19,18 +26,19 @@ let
# This becomes the main config file
promConfig = {
global = cfg.globalConfig;
rule_files = cfg.ruleFiles ++ [
rule_files = map (promtoolCheck "check-rules" "rules") (cfg.ruleFiles ++ [
(pkgs.writeText "prometheus.rules" (concatStringsSep "\n" cfg.rules))
];
]);
scrape_configs = cfg.scrapeConfigs;
};

generatedPrometheusYml = writePrettyJSON "prometheus.yml" promConfig;

prometheusYml =
if cfg.configText != null then
prometheusYml = let
yml = if cfg.configText != null then
pkgs.writeText "prometheus.yml" cfg.configText
else generatedPrometheusYml;
else generatedPrometheusYml;
in promtoolCheck "check-config" "prometheus.yml" yml;

cmdlineArgs = cfg.extraFlags ++ [
"-storage.local.path=${cfg.dataDir}/metrics"
@@ -376,6 +384,15 @@ in {
'';
};

package = mkOption {
type = types.package;
default = pkgs.prometheus;
defaultText = "pkgs.prometheus";
description = ''
The prometheus package that should be used.
'';
};

listenAddress = mkOption {
type = types.str;
default = "0.0.0.0:9090";
@@ -495,7 +512,7 @@ in {
after = [ "network.target" ];
script = ''
#!/bin/sh
exec ${pkgs.prometheus}/bin/prometheus \
exec ${cfg.package}/bin/prometheus \
${concatStringsSep " \\\n " cmdlineArgs}
'';
serviceConfig = {