85 lines
2.3 KiB
Nix
85 lines
2.3 KiB
Nix
{ config, lib, pkgs, ... }:
|
|
{
|
|
services = {
|
|
prometheus = {
|
|
enable = true;
|
|
exporters.node.enable = true;
|
|
scrapeConfigs = [ {
|
|
job_name = "node";
|
|
static_configs = [ { targets = [
|
|
"localhost:${toString config.services.prometheus.exporters.node.port}"
|
|
]; } ];
|
|
} ];
|
|
};
|
|
grafana = {
|
|
enable = true;
|
|
settings = {
|
|
security.secret_key = "$__file{/secrets/grafana-key}";
|
|
server = {
|
|
enable_gzip = true;
|
|
protocol = "socket";
|
|
socket_mode = "0666";
|
|
root_url = "https://bogaledev.ru/grafana";
|
|
};
|
|
};
|
|
};
|
|
};
|
|
systemd = {
|
|
timers = {
|
|
tgbot-send = {
|
|
wantedBy = [ "timers.target" ];
|
|
timerConfig = {
|
|
Persistent = true;
|
|
OnCalendar = "*-*-01 16:00";
|
|
};
|
|
};
|
|
network-watchdog = {
|
|
wantedBy = [ "timers.target" ];
|
|
timerConfig = {
|
|
OnBootSec = 30;
|
|
AccuracySec = 1;
|
|
OnUnitActiveSec = 10;
|
|
};
|
|
};
|
|
};
|
|
services = {
|
|
tgbot-send = {
|
|
serviceConfig.Type = "oneshot";
|
|
script = ''
|
|
. /secrets/tgbot.env
|
|
for msg in "''${MESSAGES[@]}"; do
|
|
TEXT="''${msg#*:}"
|
|
CHAT_ID="''${msg%%:*}"
|
|
${pkgs.curl}/bin/curl -X POST "https://api.telegram.org/$BOT/sendMessage" \
|
|
-d "chat_id=$CHAT_ID" -d "text=$TEXT" 2> /dev/null | ${pkgs.jq}/bin/jq
|
|
sleep 1
|
|
done
|
|
'';
|
|
};
|
|
network-watchdog = {
|
|
serviceConfig = {
|
|
Type = "oneshot";
|
|
LogLevelMax = "warning";
|
|
};
|
|
script = ''
|
|
if [ ! -e /run/network.failures ] || [ ! -e /run/network.limit ] || \
|
|
${pkgs.curl}/bin/curl --head --max-time 3 https://www.google.com; then
|
|
limit=3
|
|
failures=0
|
|
else
|
|
limit=$(cat /run/network.limit)
|
|
failures=$((1+$(cat /run/network.failures)))
|
|
fi
|
|
if [ $failures -ge $limit ]; then
|
|
echo "<4>restarting network"
|
|
systemctl restart NetworkManager.service
|
|
[ $limit -lt 360 ] && limit=$((2*$limit))
|
|
failures=0
|
|
fi
|
|
echo $limit > /run/network.limit
|
|
echo $failures > /run/network.failures
|
|
'';
|
|
};
|
|
};
|
|
};
|
|
}
|