-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3341bbb
commit e2b7021
Showing
2 changed files
with
94 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,5 +3,6 @@ | |
{ | ||
imports = [ | ||
./qemu-ga.nix | ||
./statistics.nix | ||
]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
{ config, lib, ... }: | ||
|
||
let | ||
cfg = config.services.statistics; | ||
in | ||
|
||
{ | ||
options.services.statistics = { | ||
enable = lib.mkEnableOption (lib.mdDoc "Enable statistics service."); | ||
|
||
backup = { | ||
enable = lib.mkEnableOption (lib.mdDoc "Enable statistics periodical backup service.") // { default = true; }; | ||
|
||
period = lib.mkOption { | ||
default = "0 * * * *"; | ||
example = "0 * * * *"; | ||
type = lib.types.str; | ||
description = '' | ||
Crontab formatted string for backup period. Protect against unintended | ||
poweroff event. | ||
Default to backup every hour. | ||
''; | ||
}; | ||
}; | ||
|
||
monitors = { | ||
interfaces = { | ||
enable = lib.mkEnableOption (lib.mdDoc "Monitor network interfaces.") // { default = true; }; | ||
|
||
targets = lib.mkOption { | ||
default = []; | ||
example = ["eth0"]; | ||
type = lib.types.listOf lib.types.str; | ||
description = '' | ||
List of network interfaces that will be monitored. | ||
''; | ||
}; | ||
}; | ||
}; | ||
}; | ||
|
||
config = lib.mkIf cfg.enable { | ||
packages = [ | ||
"luci-app-statistics" | ||
]; | ||
|
||
etc = { | ||
"crontabs/root".text = lib.mkIf cfg.backup.enable '' | ||
${cfg.backup.period} service luci_statistics backup | ||
''; | ||
}; | ||
|
||
uci = { | ||
settings = { | ||
collectd.globals.globals = { | ||
alt_config_file = "/etc/collectd.conf"; | ||
}; | ||
luci_statistics = { | ||
statistics = { | ||
collectd = { | ||
BaseDir = "/var/run/collectd"; | ||
PIDFile = "/var/run/collectd.pid"; | ||
PluginDir = "/usr/lib/collectd"; | ||
TypesDB = "/usr/share/collectd/types.db"; | ||
Interval = 30; | ||
ReadThreads = 2; | ||
FQDNLookup = 1; | ||
}; | ||
rrdtool = { | ||
default_timespan = "2hour"; | ||
image_width = 600; | ||
image_height = 150; | ||
image_path = "/tmp/rrdimg"; | ||
}; | ||
collectd_rrdtool = { | ||
enable = 1; | ||
DataDir = "/tmp/rrd"; | ||
RRARows = 288; | ||
RRASingle = 1; | ||
backup = 1; | ||
RRATimespans = "2hour 1day 1week 1month 1year"; | ||
}; | ||
collectd_interface = { | ||
enable = if cfg.monitors.interfaces.enable == true then 1 else 0; | ||
Interfaces = cfg.monitors.interfaces.targets; | ||
}; | ||
}; | ||
}; | ||
}; | ||
}; | ||
}; | ||
} |