Node exporter setup

Install

# Installer le package (config, systemd, etc..)
apt install prometheus-node-exporter

Web config (certificate + basic auth)

If needed..



# Créer la config, le certificat et le fichier web.yml
# From https://stackoverflow.com/questions/7580508/getting-chrome-to-accept-self-signed-localhost-certificate/60516812#60516812

mkdir /etc/node_exporter
cd /etc/node_exporter
######################
# Become a Certificate Authority
######################

# Generate private key
openssl genrsa -des3 -out myCA.key 2048
# Generate root certificate
openssl req -x509 -new -nodes -key myCA.key -sha256 -days 825 -out myCA.pem

######################
# Create CA-signed certs
######################

NAME=mydomain.com # Use your own domain name
# Generate a private key
openssl genrsa -out $NAME.key 2048
# Create a certificate-signing request
openssl req -new -key $NAME.key -out $NAME.csr
# Create a config file for the extensions
>$NAME.ext cat <<-EOF
authorityKeyIdentifier=keyid,issuer
basicConstraints=CA:FALSE
keyUsage = digitalSignature, nonRepudiation, keyEncipherment, dataEncipherment
subjectAltName = @alt_names
[alt_names]
DNS.1 = $NAME # Be sure to include the domain name here because Common Name is not so commonly honoured by itself
EOF
# Create the signed certificate
openssl x509 -req -in $NAME.csr -CA myCA.pem -CAkey myCA.key -CAcreateserial \
-out $NAME.crt -days 825 -sha256 -extfile $NAME.ext
chown jmbarbier *
vi web.yml
# 8<-------------------------------
# tls_server_config:
#   cert_file: /etc/node_exporter/monitoring.soli.dev.crt
#   key_file: /etc/node_exporter/monitoring.soli.dev.key
# basic_auth_users:
#   monitoring: xxxxxx
# --------------------------------->8

vi /etc/default/prometheus-node-exporter
# 8<-------------------------------
# ARGS="--web.config=/etc/node_exporter/web.yml"
# --------------------------------->8

chown -R prometheus /etc/node_exporter


# Restart node exporter
systemctl restart prometheus-node-exporter
# Check le status
systemctl status prometheus-node-exporter

# Copy CA file
cp myCA.pem /root/infra/services/grafana/conf/certs/node_exporter.crt
chown jmbarbier /root/infra/services/grafana/conf/certs/node_exporter.crt

Add apt collector

# Create prom txt directory
apt -y install moreutils
mkdir /var/local/proms
chown prometheus /var/local/proms

cd /usr/local/src
git clone https://github.com/prometheus-community/node-exporter-textfile-collector-scripts.git
ln -s /usr/local/src/node-exporter-textfile-collector-scripts/apt_info.sh /usr/local/bin/node-apt-collector


tee /etc/cron.d/apt-collector <<EOF
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
* 16 * * *      root node-apt-collector | sponge /var/local/proms/apt.prom
EOF

# Write ARGS to prometheus config
vi /etc/default/prometheus-node-exporter
# ARGS="--web.config=/etc/node_exporter/web.yml --collector.textfile.directory=/var/local/proms"
# or
# ARGS="--collector.textfile.directory=/var/local/proms"

systemctl reload prometheus-node-exporter
node-apt-collector | sponge /var/local/proms/apt.prom

Cadvisor

TODO: check versions on 22.04

apt-get install cadvisor
cd /tmp
wget https://github.com/google/cadvisor/releases/download/v0.37.5/cadvisor
dpkg-divert --divert /usr/bin/cadvisor.real --rename /usr/bin/cadvisor
mv cadvisor /usr/bin/cadvisor
chmod +x /usr/bin/cadvisor
rm /tmp/cadvisor

Create passwd file :

htpasswd -bc passd monitoring password
cp /tmp/passd /etc/node-exporter/passd

Edit /etc/default/cadvisor

DAEMON_ARGS="-http_auth_file=/etc/node-exporter/passd -http_auth_realm=monitoring"
systemctl restart cadvisor
systemctl status cadvisor