-
Notifications
You must be signed in to change notification settings - Fork 33
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
init grafana service #108
init grafana service #108
Changes from 1 commit
3fe73a1
a4f3ae8
1760bc1
9881117
85f089d
b15fb07
6a549d5
76f355d
1281a2e
a09072d
858db5c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,5 +13,6 @@ in | |
./redis-cluster.nix | ||
./redis.nix | ||
./zookeeper.nix | ||
./grafana | ||
]; | ||
} |
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
@@ -0,0 +1,83 @@ | ||||
{ pkgs, lib, name, config, ... }: | ||||
let | ||||
inherit (lib) types; | ||||
iniFormat = pkgs.formats.ini { }; | ||||
in | ||||
{ | ||||
options = { | ||||
description = '' | ||||
Configure grafana. | ||||
''; | ||||
enable = lib.mkEnableOption name; | ||||
|
||||
package = lib.mkPackageOption pkgs "grafana" { }; | ||||
|
||||
port = lib.mkOption { | ||||
type = types.int; | ||||
description = "Which port to run grafana on."; | ||||
default = 3000; | ||||
}; | ||||
|
||||
dataDir = lib.mkOption { | ||||
type = types.str; | ||||
description = "Directory where grafana stores its logs and data."; | ||||
default = "./data/${name}"; | ||||
}; | ||||
|
||||
extraConf = lib.mkOption { | ||||
type = iniFormat.type; | ||||
description = "Extra configuration for grafana."; | ||||
default = { }; | ||||
example = '' | ||||
{ | ||||
security.admin_user = "patato"; | ||||
security.admin_password = "potato"; | ||||
} | ||||
''; | ||||
}; | ||||
|
||||
outputs.settings = lib.mkOption { | ||||
type = types.deferredModule; | ||||
internal = true; | ||||
readOnly = true; | ||||
default = { | ||||
processes."${name}" = | ||||
let | ||||
grafanaConfig = | ||||
{ | ||||
server = { | ||||
protocol = "http"; | ||||
http_port = config.port; | ||||
domain = "localhost"; | ||||
}; | ||||
} // config.extraConf; | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What happens if There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i was not sure about this. i'll test this out There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i am using i have made this same error here. i'll create a PR to fix this
|
||||
grafanaConfigIni = iniFormat.generate "defaults.ini" grafanaConfig; | ||||
startScript = pkgs.writeShellApplication { | ||||
name = "start-grafana"; | ||||
runtimeInputs = [ config.package ]; | ||||
text = '' | ||||
grafana server --config ${grafanaConfigIni} \ | ||||
--homepath ${config.package}/share/grafana \ | ||||
cfg:paths.data="$(readlink -m ${config.dataDir})" | ||||
''; | ||||
}; | ||||
in | ||||
{ | ||||
command = startScript; | ||||
readiness_probe = { | ||||
exec.command = "${pkgs.curl}/bin/curl -f ${grafanaConfig.server.protocol}://${grafanaConfig.server.domain}:${builtins.toString grafanaConfig.server.http_port}/api/health"; | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can use the http_get readiness probe instead of curl. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, perhaps make the whole There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @srid sure. grafana has a config called |
||||
initial_delay_seconds = 15; | ||||
period_seconds = 10; | ||||
timeout_seconds = 2; | ||||
success_threshold = 1; | ||||
failure_threshold = 5; | ||||
}; | ||||
namespace = name; | ||||
|
||||
# https://github.com/F1bonacc1/process-compose#-auto-restart-if-not-healthy | ||||
availability.restart = "on_failure"; | ||||
}; | ||||
}; | ||||
}; | ||||
}; | ||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
{ pkgs, config, ... }: { | ||
services.grafana."gf1" = | ||
{ | ||
enable = true; | ||
port = 3000; | ||
extraConf = { | ||
security.admin_user = "patato"; | ||
security.admin_password = "potato"; | ||
}; | ||
}; | ||
|
||
settings.processes.test = | ||
let | ||
cfg = config.services.grafana."gf1"; | ||
in | ||
{ | ||
# Tests based on: https://github.com/NixOS/nixpkgs/blob/master/nixos/tests/grafana/basic.nix | ||
command = pkgs.writeShellApplication { | ||
runtimeInputs = [ cfg.package pkgs.gnugrep pkgs.curl pkgs.uutils-coreutils-noprefix ]; | ||
text = | ||
'' | ||
ADMIN=${cfg.extraConf.security.admin_user} | ||
PASSWORD=${cfg.extraConf.security.admin_password} | ||
curl -sSfN -u $ADMIN:$PASSWORD http://127.0.0.1:3000/api/org/users -i | ||
curl -sSfN -u $ADMIN:$PASSWORD http://127.0.0.1:3000/api/org/users | grep admin\@localhost | ||
''; | ||
name = "grafana-test"; | ||
}; | ||
depends_on."gf1".condition = "process_healthy"; | ||
}; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Usually we create folder for a service when there are more than just the service definition file and test file. We can preserve the flat hierarchy here.