2023-03-19 23:38:30 -07:00
|
|
|
{{- if and (ne .host.distro.family "windows") (stat (joinPath .host.home ".config" "age" "chezmoi.txt")) (or (stat (joinPath .chezmoi.sourceDir ".chezmoitemplates" "secrets" "NETDATA_TOKEN")) (env "NETDATA_TOKEN")) (or (stat (joinPath .chezmoi.sourceDir ".chezmoitemplates" "secrets" "NETDATA_ROOM")) (env "NETDATA_ROOM")) -}}
|
2023-01-28 20:47:57 -08:00
|
|
|
#!/usr/bin/env bash
|
2023-04-11 20:26:25 -07:00
|
|
|
# @file Netdata
|
|
|
|
# @brief Connects Netdata with Netdata's free cloud dashboard and applies some system optimizations, if necessary
|
|
|
|
# @description
|
|
|
|
# This script connects Netdata with Netdata Cloud if Netdata is installed, the `NETDATA_TOKEN` is provided, and the
|
|
|
|
# `NETDATA_ROOM` is defined. This allows you to graphically browse through system metrics on all your connected devices
|
|
|
|
# from a single free web application.
|
2023-01-28 20:47:57 -08:00
|
|
|
|
|
|
|
{{ includeTemplate "universal/profile" }}
|
|
|
|
{{ includeTemplate "universal/logg" }}
|
|
|
|
|
|
|
|
### Claim the instance with Netdata Cloud
|
|
|
|
if command -v netdata-claim.sh > /dev/null; then
|
2023-03-19 23:38:30 -07:00
|
|
|
NETDATA_TOKEN="{{ if (stat (joinPath .chezmoi.sourceDir ".chezmoitemplates" "secrets" "NETDATA_TOKEN")) }}{{ includeTemplate "secrets/NETDATA_TOKEN" | decrypt }}{{ else }}{{ env "NETDATA_TOKEN" }}{{ end }}"
|
|
|
|
NETDATA_ROOM="{{ if (stat (joinPath .chezmoi.sourceDir ".chezmoitemplates" "secrets" "NETDATA_ROOM")) }}{{ includeTemplate "secrets/NETDATA_ROOM" | decrypt }}{{ else }}{{ env "NETDATA_ROOM" }}{{ end }}"
|
2023-05-29 19:28:25 -07:00
|
|
|
# netdata-claim.sh must be run as netdata user
|
|
|
|
sudo -H -u netdata bash -c 'netdata-claim.sh -token="$NETDATA_TOKEN" -rooms="$NETDATA_ROOM" -url="{{ .netdataClaimURL }}"'
|
2023-01-28 20:47:57 -08:00
|
|
|
|
|
|
|
# Kernel optimizations
|
2023-01-28 22:07:01 -08:00
|
|
|
# These are mentioned while installing via the kickstart.sh script method. We are using Homebrew for the installation though.
|
|
|
|
# Assuming these optimizations do not cause any harm.
|
2023-01-28 20:47:57 -08:00
|
|
|
if [ -d /Applications ] && [ -d /System ]; then
|
|
|
|
# macOS
|
|
|
|
logg info 'System is macOS so Netdata kernel optimizations are not required'
|
|
|
|
else
|
|
|
|
# Linux
|
|
|
|
if [ -d /sys/kernel/mm/ksm ]; then
|
|
|
|
logg info 'Adding Netdata kernel optimization for `/sys/kernel/mm/ksm/run`'
|
|
|
|
echo 1 | sudo tee /sys/kernel/mm/ksm/run
|
|
|
|
logg info 'Adding Netdata kernel optimization for `/sys/kernel/mm/ksm/sleep_millisecs`'
|
|
|
|
echo 1000 | sudo tee /sys/kernel/mm/ksm/sleep_millisecs
|
|
|
|
else
|
|
|
|
logg info 'The `/sys/kernel/mm/ksm` directory does not exist so Netdata kernel optimizations are not being applied'
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
logg warn '`netdata-claim.sh` is not available in the PATH'
|
|
|
|
fi
|
|
|
|
|
2023-01-30 00:31:07 -08:00
|
|
|
{{ end -}}
|