Remove telegraf from all hosts
I basically ignore the data anyway. I'll redo monitoring from the ground up later.
This commit is contained in:
parent
d5b308d2d1
commit
8e821442af
15 changed files with 0 additions and 312 deletions
|
@ -10,7 +10,6 @@
|
|||
./smartd
|
||||
./ssh
|
||||
./sshd
|
||||
./telegraf
|
||||
./tmux
|
||||
./zfs
|
||||
./zsh
|
||||
|
|
|
@ -1,50 +0,0 @@
|
|||
{ config, lib, pkgs, ... }:
|
||||
|
||||
{
|
||||
services.telegraf = {
|
||||
enable = true;
|
||||
extraConfig = {
|
||||
agent = {
|
||||
interval = "10s";
|
||||
round_interval = true;
|
||||
metric_batch_size = 1000;
|
||||
metric_buffer_limit = 10000;
|
||||
collection_jitter = "0s";
|
||||
flush_interval = "10s";
|
||||
flush_jitter = "0s";
|
||||
precision = "0s";
|
||||
omit_hostname = false;
|
||||
};
|
||||
outputs.influxdb_v2 = {
|
||||
urls = [ "https://stats.chvp.be:8086" ];
|
||||
token = "$TOKEN";
|
||||
organization = "default";
|
||||
bucket = "default";
|
||||
};
|
||||
inputs = {
|
||||
cpu = {
|
||||
percpu = true;
|
||||
totalcpu = true;
|
||||
collect_cpu_time = false;
|
||||
report_active = false;
|
||||
};
|
||||
diskio = { };
|
||||
exec = {
|
||||
commands = [ "${pkgs.zfs}/libexec/zfs/zpool_influxdb" ];
|
||||
timeout = "5s";
|
||||
data_format = "influx";
|
||||
};
|
||||
kernel = { };
|
||||
mem = { };
|
||||
processes = { };
|
||||
swap = { };
|
||||
system = { };
|
||||
};
|
||||
};
|
||||
environmentFiles = [ config.age.secrets."passwords/services/telegraf-env".path ];
|
||||
};
|
||||
age.secrets."passwords/services/telegraf-env" = {
|
||||
file = ../../../../secrets/passwords/services/telegraf-env.age;
|
||||
owner = "telegraf";
|
||||
};
|
||||
}
|
|
@ -5,9 +5,7 @@
|
|||
./accentor
|
||||
./containers
|
||||
./data-access
|
||||
./garmin-scraper
|
||||
./git
|
||||
./grafana
|
||||
./mail
|
||||
./mastodon
|
||||
./matrix
|
||||
|
|
|
@ -1,39 +0,0 @@
|
|||
{ config, lib, pkgs, ... }:
|
||||
|
||||
let
|
||||
garmin2influx = pkgs.writers.writePython3Bin "garmin2influx"
|
||||
{
|
||||
libraries = with pkgs.python3Packages; [ garminconnect influxdb-client ];
|
||||
}
|
||||
(builtins.readFile ./garmin2influx.py);
|
||||
in
|
||||
{
|
||||
options.chvp.services.garmin-scraper.enable = lib.mkEnableOption "garmin scraper";
|
||||
|
||||
config = lib.mkIf config.chvp.services.garmin-scraper.enable {
|
||||
# Install in environment to allow manual data collection
|
||||
environment.systemPackages = [ garmin2influx ];
|
||||
systemd = {
|
||||
services.garmin2influx = {
|
||||
description = "Garmin health data importer";
|
||||
restartIfChanged = false;
|
||||
unitConfig.X-StopOnRemoval = false;
|
||||
serviceConfig = {
|
||||
EnvironmentFile = config.age.secrets."passwords/services/garmin2influx-env".path;
|
||||
Type = "oneshot";
|
||||
User = "charlotte";
|
||||
Group = "users";
|
||||
ExecStart = "${garmin2influx}/bin/garmin2influx";
|
||||
RestartSec = "5s";
|
||||
Restart = "on-failure";
|
||||
};
|
||||
startAt = "02/4:00";
|
||||
};
|
||||
timers.garmin2influx.timerConfig.RandomizedDelaySec = "30min";
|
||||
};
|
||||
age.secrets."passwords/services/garmin2influx-env" = {
|
||||
file = ../../../../secrets/passwords/services/garmin2influx-env.age;
|
||||
owner = "charlotte";
|
||||
};
|
||||
};
|
||||
}
|
|
@ -1,88 +0,0 @@
|
|||
import os
|
||||
import sys
|
||||
from datetime import date, datetime, timedelta, timezone
|
||||
from garminconnect import (
|
||||
Garmin,
|
||||
GarminConnectConnectionError,
|
||||
GarminConnectTooManyRequestsError,
|
||||
GarminConnectAuthenticationError,
|
||||
)
|
||||
from influxdb_client import InfluxDBClient, Point, WritePrecision
|
||||
from influxdb_client.client.write_api import SYNCHRONOUS
|
||||
|
||||
email = os.getenv('EMAIL')
|
||||
password = os.getenv('PASSWORD')
|
||||
token = os.getenv('TOKEN')
|
||||
org = 'default'
|
||||
bucket = 'default'
|
||||
|
||||
|
||||
def hr2point(time, val):
|
||||
return Point("health") \
|
||||
.field("heart_rate", val) \
|
||||
.time(
|
||||
datetime.fromtimestamp(time / 1000, timezone.utc),
|
||||
WritePrecision.S
|
||||
)
|
||||
|
||||
|
||||
def stress2point(time, val):
|
||||
return Point("health") \
|
||||
.field("stress", max(val, 0)) \
|
||||
.time(
|
||||
datetime.fromtimestamp(time / 1000, timezone.utc),
|
||||
WritePrecision.S
|
||||
)
|
||||
|
||||
|
||||
def hr_for_date(api, date_to_fetch):
|
||||
return api.get_heart_rates(date_to_fetch.isoformat())['heartRateValues']
|
||||
|
||||
|
||||
def stress_for_date(api, date_to_fetch):
|
||||
return api.get_stress_data(date_to_fetch.isoformat())['stressValuesArray']
|
||||
|
||||
|
||||
date_to_fetch = date.today().isoformat()
|
||||
if len(sys.argv) > 1:
|
||||
date_to_fetch = sys.argv[1]
|
||||
|
||||
date_to_fetch = date.fromisoformat(date_to_fetch)
|
||||
|
||||
try:
|
||||
api = Garmin(email, password)
|
||||
api.login()
|
||||
hr_points = list(map(
|
||||
lambda p: hr2point(*p),
|
||||
hr_for_date(api, date_to_fetch - timedelta(days=1))
|
||||
))
|
||||
stress_points = list(map(
|
||||
lambda p: stress2point(*p),
|
||||
stress_for_date(api, date_to_fetch - timedelta(days=1))
|
||||
))
|
||||
hr_points += list(map(
|
||||
lambda p: hr2point(*p),
|
||||
hr_for_date(api, date_to_fetch)
|
||||
))
|
||||
stress_points += list(map(
|
||||
lambda p: stress2point(*p),
|
||||
stress_for_date(api, date_to_fetch)
|
||||
))
|
||||
with InfluxDBClient(
|
||||
url="https://stats.chvp.be:8086",
|
||||
token=token,
|
||||
org=org
|
||||
) as client:
|
||||
write_api = client.write_api(write_options=SYNCHRONOUS)
|
||||
write_api.write(bucket, org, hr_points)
|
||||
write_api.write(bucket, org, stress_points)
|
||||
except (
|
||||
GarminConnectConnectionError,
|
||||
GarminConnectAuthenticationError,
|
||||
GarminConnectTooManyRequestsError,
|
||||
) as err:
|
||||
print(
|
||||
f'Error occured during Garmin Connect communication: {err}',
|
||||
file=sys.stderr
|
||||
)
|
||||
sys.exit(1)
|
|
@ -1,96 +0,0 @@
|
|||
{ config, lib, pkgs, ... }:
|
||||
|
||||
{
|
||||
options.chvp.services.grafana.enable = lib.mkEnableOption "grafana";
|
||||
|
||||
config = lib.mkIf config.chvp.services.grafana.enable {
|
||||
chvp.services.nginx.hosts = [{
|
||||
fqdn = "stats.chvp.be";
|
||||
options.locations."/" = {
|
||||
proxyPass = "http://grafana";
|
||||
proxyWebsockets = true;
|
||||
};
|
||||
}];
|
||||
users.users = {
|
||||
influxdb2.extraGroups = [ "acme" ];
|
||||
nginx.extraGroups = [ "grafana" ];
|
||||
};
|
||||
networking.firewall.allowedTCPPorts = [ 8086 ];
|
||||
services = {
|
||||
nginx.upstreams.grafana.servers = { "unix:/run/grafana/grafana.sock" = { }; };
|
||||
influxdb2 = {
|
||||
enable = true;
|
||||
settings = {
|
||||
reporting-disabled = true;
|
||||
tls-cert = "${config.security.acme.certs."vanpetegem.me".directory}/fullchain.pem";
|
||||
tls-key = "${config.security.acme.certs."vanpetegem.me".directory}/key.pem";
|
||||
};
|
||||
};
|
||||
grafana = {
|
||||
enable = true;
|
||||
dataDir = "${config.chvp.dataPrefix}/var/lib/grafana";
|
||||
settings = {
|
||||
analytics.reporting_enabled = false;
|
||||
"auth.anonymous" = {
|
||||
enabled = "true";
|
||||
org_name = "Van Petegem";
|
||||
};
|
||||
database = {
|
||||
user = "grafana";
|
||||
type = "postgres";
|
||||
host = "/run/postgresql/";
|
||||
name = "grafana";
|
||||
};
|
||||
security = {
|
||||
admin_user = "chvp";
|
||||
admin_password = "$__file{${config.age.secrets."passwords/services/grafana/admin-password".path}}";
|
||||
secret_key = "$__file{${config.age.secrets."passwords/services/grafana/secret-key".path}}";
|
||||
};
|
||||
server = {
|
||||
domain = "stats.chvp.be";
|
||||
http_port = 3000;
|
||||
protocol = "socket";
|
||||
root_url = "https://stats.chvp.be";
|
||||
socket = "/run/grafana/grafana.sock";
|
||||
};
|
||||
smtp = {
|
||||
enabled = true;
|
||||
host = "mail.vanpetegem.me:25";
|
||||
user = "noreply@vanpetegem.me";
|
||||
from_address = "noreply@vanpetegem.me";
|
||||
password = "$__file{${config.age.secrets."passwords/services/grafana/smtp".path}}";
|
||||
};
|
||||
users = {
|
||||
default_theme = "light";
|
||||
allow_sign_up = false;
|
||||
};
|
||||
};
|
||||
};
|
||||
grafana-image-renderer = {
|
||||
enable = true;
|
||||
provisionGrafana = true;
|
||||
chromium = pkgs.ungoogled-chromium;
|
||||
};
|
||||
postgresql = {
|
||||
enable = true;
|
||||
ensureDatabases = [ "grafana" ];
|
||||
ensureUsers = [{
|
||||
name = "grafana";
|
||||
ensureDBOwnership = true;
|
||||
}];
|
||||
};
|
||||
};
|
||||
age.secrets."passwords/services/grafana/smtp" = {
|
||||
file = ../../../../secrets/passwords/services/grafana/smtp.age;
|
||||
owner = "grafana";
|
||||
};
|
||||
age.secrets."passwords/services/grafana/admin-password" = {
|
||||
file = ../../../../secrets/passwords/services/grafana/admin-password.age;
|
||||
owner = "grafana";
|
||||
};
|
||||
age.secrets."passwords/services/grafana/secret-key" = {
|
||||
file = ../../../../secrets/passwords/services/grafana/secret-key.age;
|
||||
owner = "grafana";
|
||||
};
|
||||
};
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue