Sometimes everything looks fine on the surface but appearances can be deceiving. Here we will see how to set up the Prometheus monitoring stack to monitor our stuff and send alerts when needed.

The core component of the Prometheus monitoring stack is the Prometheus server. We configure targets for the server (meaning endpoints that expose metrics) and the server connects to them at regular intervals to scrape their metrics and store them locally in a time series database (TSDB).

We also configure rules for the server. Rules are PromQL expressions that run at regular intervals against the data stored in the TSDB and trigger alerts when certain conditions are met.

When an alert is triggered the server forwards it to the Alertmanager which is another component of the Prometheus monitoring stack. The Alertmanager applies some routing and grouping logic before sending a notification out to its configured receivers.

Some systems and services do not expose metrics by default. In these cases we use Prometheus exporters which are installed on systems or alongside services to collect metrics and expose them through endpoints. These endpoints can then be configured as targets for the Prometheus server.

Finally there are cases where we need to collect metrics from ephemeral jobs that complete before the Prometheus server has an opportunity to scrape them. In these situations we can configure the jobs to push their metrics to the Pushgateway allowing Prometheus to scrape the metrics from there instead.

Below we will see some more details about each component of the Prometheus monitoring stack and how to install them.

Note

All scripts below support both x86 and ARM systems running Debian with systemd.

Services bind to 0.0.0.0 by default. To restrict access update their unit files or use a firewall.

Each component uses a dedicated service account except cAdvisor which runs as root.


Prometheus Server

The script we will use to install the Prometheus server will place all the configuration files under the /etc/prometheus directory..

.
|-- prometheus.yaml # configuration file
|-- rules # rule files
|   |-- alert.yaml
|   `-- recording.yaml
`-- targets # target files
    |-- servers
    |-- services
    `-- sites

The main configuration file for the server is the /etc/prometheus/prometheus.yaml, where we configure things like how often to scrape targets, how often to evaluate rules, where is the Alertmanager, where are the rules, and where are the targets.

Note that any change we make to this configuration file will not take effect until we restart the Prometheus systemd service.

On the configuration file we have configured targets for all the components of the Prometheus monitoring stack that we will install. In addition to these we have also configured three scrape jobs with the names “servers”, “services” and “sites”. These jobs are using the file based discovery mechanism which allows us to add, update and remove targets without having to restart the Prometheus systemd service each time.

The target files are stored under /etc/prometheus/targets and are categorized according to the following convention. The /etc/prometheus/targets/servers directory contains Node Exporter targets for physical and virtual machines. The /etc/prometheus/targets/services directory contains targets for software that exposes metrics. The /etc/prometheus/targets/sites directory contains targets monitored through the Blackbox Exporter.

To add a target under servers..

TARGET_IP=""   # 10.0.0.3
TARGET_PORT="" # 9100
TARGET_NAME="" # server

cat << EOF > /etc/prometheus/targets/servers/${TARGET_NAME}.yaml
- targets:
    - "${TARGET_IP}:${TARGET_PORT}"
  labels:
    instance: "${TARGET_NAME}"
EOF

To add a target under services..

TARGET_IP=""   # 127.0.0.1
TARGET_PORT="" # 9323
TARGET_NAME="" # docker

cat << EOF > /etc/prometheus/targets/services/${TARGET_NAME}.yaml
- targets:
    - "${TARGET_IP}:${TARGET_PORT}"
  labels:
    instance: "${TARGET_NAME}"
EOF

To add a target under sites..

TARGET_URL=""  # https://google.com
TARGET_NAME="" # google

cat << EOF > /etc/prometheus/targets/sites/${TARGET_NAME}.yaml
- targets:
    - "${TARGET_URL}"
EOF

The names of the files under /etc/prometheus/targets don’t really matter and we can have files with multiple targets defined in them. The IP address we provide for the TARGET_IP needs to be reachable by the Prometheus server. We give a value for the instance label so it doesn’t automatically get the value from the __address__ label (more info on that here).

Finally, the script will also create rule files under the /etc/prometheus/rules directory. We can find a collection of alert rules here. Note that any change we make to the rule files will not take effect until we restart the Prometheus systemd service.

Show prometheus.sh
#!/bin/bash

# This script installs Prometheus on Debian based systems.

set -e
set -u
set -o pipefail

### color variables

GRAY=$'\033[0;90m'
RED=$'\033[0;91m'
GREEN=$'\033[0;92m'
YELLOW=$'\033[0;93m'
BLUE=$'\033[0;94m'
MAGENTA=$'\033[0;95m'
CYAN=$'\033[0;96m'
WHITE=$'\033[0;97m'
RESET=$'\033[0m'

### preflight checks

PREFLIGHT_CHECKS_FAIL="false"

if [[ "${EUID}" -ne 0 ]]; then
    printf "%sERROR:%s script not running as root\n" "${RED}" "${RESET}"
    exit 1
fi

BINARIES=(
    curl
    jq
)
for i in "${BINARIES[@]}"; do
    if ! command -v "${i}" > /dev/null 2>&1; then
        PREFLIGHT_CHECKS_FAIL="true"
        printf "%sERROR:%s %s is not installed\n" "${RED}" "${RESET}" "${i}"
    fi
done

if [[ "${PREFLIGHT_CHECKS_FAIL}" == "true" ]]; then
    exit 1
fi

### app variables

APP_SA="prometheus"
APP_VERSION="$(curl -Ls https://api.github.com/repos/prometheus/prometheus/releases/latest | jq -r .tag_name)"
SYSTEM_ARCH="$(dpkg --print-architecture)"

APP_UPGRADE=false
if [[ -f /usr/local/bin/prometheus ]]; then
    APP_UPGRADE=true
fi

TEMP_DIR="$(mktemp -d)"
trap 'rm -rf "$TEMP_DIR"' EXIT

APP_LISTEN_ADDRESS=""
APP_LISTEN_PORT=""

ALERTMANAGER_IP=""
ALERTMANAGER_PORT=""
BLACKBOX_EXPORTER_IP=""
BLACKBOX_EXPORTER_PORT=""
CADVISOR_IP=""
CADVISOR_PORT=""
NODE_EXPORTER_IP=""
NODE_EXPORTER_PORT=""
PROMETHEUS_IP=""
PROMETHEUS_PORT=""
PUSHGATEWAY_IP=""
PUSHGATEWAY_PORT=""

### download

printf "%sINFO:%s downloading prometheus %s for %s architecture\n" "${GREEN}" "${RESET}" "${APP_VERSION}" "${SYSTEM_ARCH}"
curl -sLo ${TEMP_DIR}/prometheus-${APP_VERSION#v}.linux-${SYSTEM_ARCH}.tar.gz https://github.com/prometheus/prometheus/releases/download/${APP_VERSION}/prometheus-${APP_VERSION#v}.linux-${SYSTEM_ARCH}.tar.gz
tar -xzf ${TEMP_DIR}/prometheus-${APP_VERSION#v}.linux-${SYSTEM_ARCH}.tar.gz --directory ${TEMP_DIR}

### upgrade

if [[ "${APP_UPGRADE}" == true ]]; then
    printf "%sINFO:%s upgrading the existing installation\n" "${GREEN}" "${RESET}"
    systemctl --quiet stop prometheus.service
    install -m 0755 -o ${APP_SA} -g ${APP_SA} ${TEMP_DIR}/prometheus-${APP_VERSION#v}.linux-${SYSTEM_ARCH}/prometheus /usr/local/bin/prometheus
    install -m 0755 -o ${APP_SA} -g ${APP_SA} ${TEMP_DIR}/prometheus-${APP_VERSION#v}.linux-${SYSTEM_ARCH}/promtool /usr/local/bin/promtool
    systemctl --quiet start prometheus.service
    printf "%sINFO:%s upgrade succeeded\n" "${GREEN}" "${RESET}"
    exit 0
fi

### install

printf "%sINFO:%s starting the installation\n" "${GREEN}" "${RESET}"
useradd --system --no-create-home --shell /bin/false ${APP_SA}
mkdir /etc/prometheus
mkdir /etc/prometheus/rules
mkdir /etc/prometheus/targets
mkdir /etc/prometheus/targets/servers
mkdir /etc/prometheus/targets/services
mkdir /etc/prometheus/targets/sites
mkdir /var/lib/prometheus

cat << EOF > /etc/prometheus/prometheus.yaml
global:
  scrape_interval: 15s
  evaluation_interval: 15s

alerting:
  alertmanagers:
    - static_configs:
        - targets:
            - ${ALERTMANAGER_IP:-127.0.0.1}:${ALERTMANAGER_PORT:-9093}

rule_files:
  - /etc/prometheus/rules/*.yml
  - /etc/prometheus/rules/*.yaml

scrape_configs:
  - job_name: alertmanager
    static_configs:
      - targets:
          - ${ALERTMANAGER_IP:-127.0.0.1}:${ALERTMANAGER_PORT:-9093}
        labels:
          instance: alertmanager
  - job_name: blackbox-exporter
    static_configs:
      - targets:
          - ${BLACKBOX_EXPORTER_IP:-127.0.0.1}:${BLACKBOX_EXPORTER_PORT:-9115}
        labels:
          instance: blackbox-exporter
  - job_name: cadvisor
    static_configs:
      - targets:
          - ${CADVISOR_IP:-127.0.0.1}:${CADVISOR_PORT:-8080}
        labels:
          instance: cadvisor
  - job_name: node-exporter
    static_configs:
      - targets:
          - ${NODE_EXPORTER_IP:-127.0.0.1}:${NODE_EXPORTER_IP:-9100}
        labels:
          instance: node-exporter
  - job_name: prometheus
    static_configs:
      - targets:
          - ${PROMETHEUS_IP:-127.0.0.1}:${PROMETHEUS_PORT:-9090}
        labels:
          instance: prometheus
  - job_name: pushgateway
    honor_labels: true
    static_configs:
      - targets:
          - ${PUSHGATEWAY_IP:-127.0.0.1}:${PUSHGATEWAY_PORT:-9091}
        labels:
          instance: pushgateway
  - job_name: servers
    metrics_path: /metrics
    file_sd_configs:
      - files:
          - /etc/prometheus/targets/servers/*.yml
          - /etc/prometheus/targets/servers/*.yaml
          - /etc/prometheus/targets/servers/*.json
  - job_name: services
    metrics_path: /metrics
    file_sd_configs:
      - files:
          - /etc/prometheus/targets/services/*.yml
          - /etc/prometheus/targets/services/*.yaml
          - /etc/prometheus/targets/services/*.json
  - job_name: sites
    metrics_path: /probe
    params:
      module: [http_2xx]
    file_sd_configs:
      - files:
          - /etc/prometheus/targets/sites/*.yml
          - /etc/prometheus/targets/sites/*.yaml
          - /etc/prometheus/targets/sites/*.json
    relabel_configs:
      - source_labels: [__address__]
        target_label: __param_target
      - source_labels: [__param_target]
        target_label: instance
      - target_label: __address__
        replacement: ${BLACKBOX_EXPORTER_IP:-127.0.0.1}:${BLACKBOX_EXPORTER_PORT:-9115}
EOF

cat << 'EOF' > /etc/prometheus/rules/alert.yaml
groups:
  - name: alertmanager
    rules:
      - alert: alertmanager_configuration_reload_failure
        expr: 'alertmanager_config_last_reload_successful != 1'
        for: 0m
      - alert: alertmanager_too_many_restarts
        expr: 'changes(process_start_time_seconds{job="alertmanager"}[15m]) > 2'
        for: 0m
      - alert: alertmanager_notifications_failing
        expr: 'rate(alertmanager_notifications_failed_total[1m]) > 0'
        for: 0m
  - name: blackbox_exporter
    rules:
      - alert: blackbox_exporter_configuration_reload_failure
        expr: 'blackbox_exporter_config_last_reload_successful != 1'
        for: 0m
      - alert: blackbox_exporter_too_many_restarts
        expr: 'changes(process_start_time_seconds{job="blackbox-exporter"}[15m]) > 2'
        for: 0m
      - alert: blackbox_exporter_probe_failed
        expr: 'probe_success == 0'
        for: 0m
      - alert: blackbox_exporter_probe_http_failure
        expr: 'probe_http_status_code <= 199 OR probe_http_status_code >= 400'
        for: 0m
      - alert: blackbox_exporter_ssl_certificate_expiration_7_days
        expr: '3 <= round((last_over_time(probe_ssl_earliest_cert_expiry[10m]) - time()) / 86400, 0.1) < 7'
        for: 0m
      - alert: blackbox_exporter_ssl_certificate_expiration_3_days
        expr: '0 <= round((last_over_time(probe_ssl_earliest_cert_expiry[10m]) - time()) / 86400, 0.1) < 3'
        for: 0m
      - alert: blackbox_exporter_ssl_certificate_expired
        expr: 'round((last_over_time(probe_ssl_earliest_cert_expiry[10m]) - time()) / 86400, 0.1) < 0'
        for: 0m
  - name: cadvisor
    rules:
      - alert: cadvisor_metrics_absent
        expr: 'absent(container_last_seen)'
        for: 5m
      - alert: cadvisor_container_unhealthy
        expr: 'container_health_state == 0'
        for: 5m
  - name: node_exporter
    rules:
      - alert: node_exporter_cpu_load_high
        expr: '(sum by (instance) (avg by (mode, instance) (rate(node_cpu_seconds_total{mode!="idle"}[2m]))) > 0.8) * on(instance) group_left (nodename) node_uname_info{nodename=~".+"}'
        for: 10m
      - alert: node_exporter_cpu_steal_high
        expr: '(avg by(instance) (rate(node_cpu_seconds_total{mode="steal"}[5m])) * 100 > 10) * on(instance) group_left (nodename) node_uname_info{nodename=~".+"}'
        for: 0m
      - alert: node_exporter_cpu_iowait_high
        expr: '(avg by (instance) (rate(node_cpu_seconds_total{mode="iowait"}[5m])) * 100 > 10) * on(instance) group_left (nodename) node_uname_info{nodename=~".+"}'
        for: 0m
      - alert: node_exporter_memory_available_low
        expr: '(node_memory_MemAvailable_bytes / node_memory_MemTotal_bytes * 100 < 10) * on(instance) group_left (nodename) node_uname_info{nodename=~".+"}'
        for: 2m
      - alert: node_exporter_memory_pressure_high
        expr: '(rate(node_vmstat_pgmajfault[1m]) > 1000) * on(instance) group_left (nodename) node_uname_info{nodename=~".+"}'
        for: 2m
      - alert: node_exporter_swap_usage_high
        expr: '((1 - (node_memory_SwapFree_bytes / node_memory_SwapTotal_bytes)) * 100 > 80) * on(instance) group_left (nodename) node_uname_info{nodename=~".+"}'
        for: 2m
      - alert: node_exporter_oom_kill_detected
        expr: '(increase(node_vmstat_oom_kill[1m]) > 0) * on(instance) group_left (nodename) node_uname_info{nodename=~".+"}'
        for: 0m
      - alert: node_exporter_disk_space_low
        expr: '((node_filesystem_avail_bytes * 100) / node_filesystem_size_bytes < 10 and ON (instance, device, mountpoint) node_filesystem_readonly == 0) * on(instance) group_left (nodename) node_uname_info{nodename=~".+"}'
        for: 2m
      - alert: node_exporter_disk_inodes_low
        expr: '(node_filesystem_files_free{fstype!="msdosfs"} / node_filesystem_files{fstype!="msdosfs"} * 100 < 10 and ON (instance, device, mountpoint) node_filesystem_readonly == 0) * on(instance) group_left (nodename) node_uname_info{nodename=~".+"}'
        for: 2m
      - alert: node_exporter_filesystem_error
        expr: 'node_filesystem_device_error == 1'
        for: 2m
      - alert: node_exporter_network_receive_errors
        expr: '(rate(node_network_receive_errs_total[2m]) / rate(node_network_receive_packets_total[2m]) > 0.01) * on(instance) group_left (nodename) node_uname_info{nodename=~".+"}'
        for: 2m
      - alert: node_exporter_network_transmit_errors
        expr: '(rate(node_network_transmit_errs_total[2m]) / rate(node_network_transmit_packets_total[2m]) > 0.01) * on(instance) group_left (nodename) node_uname_info{nodename=~".+"}'
        for: 2m
      - alert: node_exporter_network_interface_saturated
        expr: '((rate(node_network_receive_bytes_total{device!~"^tap.*|^vnet.*|^veth.*|^tun.*"}[1m]) + rate(node_network_transmit_bytes_total{device!~"^tap.*|^vnet.*|^veth.*|^tun.*"}[1m])) / node_network_speed_bytes{device!~"^tap.*|^vnet.*|^veth.*|^tun.*"} > 0.8 < 10000) * on(instance) group_left (nodename) node_uname_info{nodename=~".+"}'
        for: 1m
      - alert: node_exporter_network_conntrack_entries_high
        expr: '(node_nf_conntrack_entries / node_nf_conntrack_entries_limit > 0.8) * on(instance) group_left (nodename) node_uname_info{nodename=~".+"}'
        for: 5m
      - alert: node_exporter_hardware_temp_high
        expr: '((node_hwmon_temp_celsius * ignoring(label) group_left(instance, job, node, sensor) node_hwmon_sensor_label{label!="tctl"} > 75)) * on(instance) group_left (nodename) node_uname_info{nodename=~".+"}'
        for: 5m
      - alert: node_exporter_hardware_temp_alarm
        expr: '((node_hwmon_temp_crit_alarm_celsius == 1) or (node_hwmon_temp_alarm == 1)) * on(instance) group_left (nodename) node_uname_info{nodename=~".+"}'
        for: 0m
      - alert: node_exporter_time_offset_detected
        expr: '((node_timex_offset_seconds > 0.05 and deriv(node_timex_offset_seconds[5m]) >= 0) or (node_timex_offset_seconds < -0.05 and deriv(node_timex_offset_seconds[5m]) <= 0)) * on(instance) group_left (nodename) node_uname_info{nodename=~".+"}'
        for: 10m
      - alert: node_exporter_time_not_synchronising
        expr: '(min_over_time(node_timex_sync_status[1m]) == 0 and node_timex_maxerror_seconds >= 16) * on(instance) group_left (nodename) node_uname_info{nodename=~".+"}'
        for: 2m
      - alert: node_exporter_reboot_required
        expr: '(node_reboot_required > 0) * on(instance) group_left (nodename) node_uname_info{nodename=~".+"}'
        for: 4h
  - name: prometheus
    rules:
      - alert: prometheus_configuration_reload_failure
        expr: 'prometheus_config_last_reload_successful != 1'
        for: 0m
      - alert: prometheus_too_many_restarts
        expr: 'changes(process_start_time_seconds{job="prometheus"}[15m]) > 2'
        for: 0m
      - alert: prometheus_timeseries_cardinality_high
        expr: 'label_replace(count by(__name__) ({__name__=~".+"}), "name", "$1", "__name__", "(.+)") > 10000'
        for: 0m
      - alert: prometheus_notifications_queue_length
        expr: 'min_over_time(prometheus_notifications_queue_length[10m]) > 0'
        for: 0m
      - alert: prometheus_notifications_alertmanagers_discovered
        expr: 'prometheus_notifications_alertmanagers_discovered < 1'
        for: 0m
      - alert: prometheus_template_text_expansion_failures
        expr: 'increase(prometheus_template_text_expansion_failures_total[3m]) > 0'
        for: 0m
      - alert: prometheus_rule_evaluation_failures
        expr: 'increase(prometheus_rule_evaluation_failures_total[3m]) > 0'
        for: 0m
      - alert: prometheus_rule_evaluation_slow
        expr: 'prometheus_rule_group_last_duration_seconds > prometheus_rule_group_interval_seconds'
        for: 5m
      - alert: prometheus_target_missing
        expr: 'up == 0'
        for: 0m
      - alert: prometheus_target_scrape_slow
        expr: 'prometheus_target_interval_length_seconds{quantile="0.9"} / on (interval, instance, job) prometheus_target_interval_length_seconds{quantile="0.5"} > 1.05'
        for: 5m
      - alert: prometheus_target_scrape_large
        expr: 'increase(prometheus_target_scrapes_exceeded_sample_limit_total[10m]) > 10'
        for: 5m
      - alert: prometheus_target_scrape_duplicate
        expr: 'increase(prometheus_target_scrapes_sample_duplicate_timestamp_total[5m]) > 0'
        for: 0m
      - alert: prometheus_tsdb_checkpoint_creation_failed
        expr: 'increase(prometheus_tsdb_checkpoint_creations_failed_total[1m]) > 0'
        for: 0m
      - alert: prometheus_tsdb_checkpoint_deletion_failed
        expr: 'increase(prometheus_tsdb_checkpoint_deletions_failed_total[1m]) > 0'
        for: 0m
      - alert: prometheus_tsdb_compactions_failed
        expr: 'increase(prometheus_tsdb_compactions_failed_total[1m]) > 0'
        for: 0m
      - alert: prometheus_tsdb_head_truncations_failed
        expr: 'increase(prometheus_tsdb_head_truncations_failed_total[1m]) > 0'
        for: 0m
      - alert: prometheus_tsdb_reload_failures
        expr: 'increase(prometheus_tsdb_reloads_failures_total[1m]) > 0'
        for: 0m
      - alert: prometheus_tsdb_wal_corruptions
        expr: 'increase(prometheus_tsdb_wal_corruptions_total[1m]) > 0'
        for: 0m
      - alert: prometheus_tsdb_wal_truncations_failed
        expr: 'increase(prometheus_tsdb_wal_truncations_failed_total[1m]) > 0'
        for: 0m
  - name: pushgateway
    rules:
      - alert: pushgateway_too_many_restarts
        expr: 'changes(process_start_time_seconds{job="pushgateway"}[15m]) > 2'
        for: 0m
  - name: watchdog
    rules:
      - alert: watchdog
        expr: 'vector(1)'
        for: 0m
EOF

cat << 'EOF' > /etc/prometheus/rules/recording.yaml
groups:
  - name: prometheus
    interval: 30s
    rules:
      - record: prometheus:http_requests:rate5m
        expr: rate(prometheus_http_requests_total[5m])
        labels:
          aggregation: rate5m
EOF

install -m 0755 -o ${APP_SA} -g ${APP_SA} ${TEMP_DIR}/prometheus-${APP_VERSION#v}.linux-${SYSTEM_ARCH}/prometheus /usr/local/bin/prometheus
install -m 0755 -o ${APP_SA} -g ${APP_SA} ${TEMP_DIR}/prometheus-${APP_VERSION#v}.linux-${SYSTEM_ARCH}/promtool /usr/local/bin/promtool
chown -R ${APP_SA}:${APP_SA} /etc/prometheus
chown -R ${APP_SA}:${APP_SA} /var/lib/prometheus

cat << EOF > /etc/systemd/system/prometheus.service
[Unit]
Description=Prometheus
Wants=network-online.target
After=network-online.target

[Service]
Type=simple
Restart=always
User=${APP_SA}
Group=${APP_SA}
ExecStart=/usr/local/bin/prometheus \
--config.file="/etc/prometheus/prometheus.yaml" \
--web.enable-lifecycle \
--web.enable-admin-api \
--web.enable-remote-write-receiver \
--log.level="info" \
--log.format="logfmt" \
--web.listen-address="${APP_LISTEN_ADDRESS:-0.0.0.0}:${APP_LISTEN_PORT:-9090}" \
--storage.tsdb.path="/var/lib/prometheus" \
--storage.tsdb.retention.time="30d" \
--storage.tsdb.retention.size="64GB"

[Install]
WantedBy=multi-user.target
EOF

systemctl --quiet daemon-reload
systemctl --quiet start prometheus.service
systemctl --quiet enable prometheus.service
printf "%sINFO:%s installation succeeded\n" "${GREEN}" "${RESET}"

Alertmanager

The script we will use to install Alertmanager will place all configuration files under the /etc/alertmanager directory. The /etc/alertmanager/alertmanager.yaml file contains the main Alertmanager configuration, including the location of the notification templates, how alerts are routed to the appropriate receivers, and which receivers are used to send notifications.

Note that any change we make to the configuration file will not take effect until we restart the Alertmanager systemd service.

The script will create a minimal configuration that works well for “slow” environments that will route all alerts (except the Watchdog alert) to the webhooks receiver. If you want to receive alerts you can configure a ntfy.sh or a Discord webhook URL there.

The Watchdog alert is a dead man’s switch type of alert designed to always fire. When it stops firing it means that something is wrong with the monitoring system. We will route this alert to a healthchecks.io webhook that will notify us only when it stops firing.

Show alertmanager.sh
#!/bin/bash

# This script installs Alertmanager on Debian based systems.

set -e
set -u
set -o pipefail

### color variables

GRAY=$'\033[0;90m'
RED=$'\033[0;91m'
GREEN=$'\033[0;92m'
YELLOW=$'\033[0;93m'
BLUE=$'\033[0;94m'
MAGENTA=$'\033[0;95m'
CYAN=$'\033[0;96m'
WHITE=$'\033[0;97m'
RESET=$'\033[0m'

### preflight checks

PREFLIGHT_CHECKS_FAIL="false"

if [[ "${EUID}" -ne 0 ]]; then
    printf "%sERROR:%s script not running as root\n" "${RED}" "${RESET}"
    exit 1
fi

BINARIES=(
    curl
    jq
)
for i in "${BINARIES[@]}"; do
    if ! command -v "${i}" > /dev/null 2>&1; then
        PREFLIGHT_CHECKS_FAIL="true"
        printf "%sERROR:%s %s is not installed\n" "${RED}" "${RESET}" "${i}"
    fi
done

if [[ "${PREFLIGHT_CHECKS_FAIL}" == "true" ]]; then
    exit 1
fi

### app variables

APP_SA="alertmanager"
APP_VERSION="$(curl -Ls https://api.github.com/repos/prometheus/alertmanager/releases/latest | jq -r .tag_name)"
SYSTEM_ARCH="$(dpkg --print-architecture)"

APP_UPGRADE=false
if [[ -f /usr/local/bin/alertmanager ]]; then
    APP_UPGRADE=true
fi

TEMP_DIR="$(mktemp -d)"
trap 'rm -rf "$TEMP_DIR"' EXIT

APP_LISTEN_ADDRESS=""
APP_LISTEN_PORT=""

DISCORD_WEBHOOK_URL=""
NTFY_WEBHOOK_URL=""
HEALTHCHECKS_WEBHOOK_URL=""

### download

printf "%sINFO:%s downloading alertmanager %s for %s architecture\n" "${GREEN}" "${RESET}" "${APP_VERSION}" "${SYSTEM_ARCH}"
curl -sLo ${TEMP_DIR}/alertmanager-${APP_VERSION#v}.linux-${SYSTEM_ARCH}.tar.gz https://github.com/prometheus/alertmanager/releases/download/${APP_VERSION}/alertmanager-${APP_VERSION#v}.linux-${SYSTEM_ARCH}.tar.gz
tar -xzf ${TEMP_DIR}/alertmanager-${APP_VERSION#v}.linux-${SYSTEM_ARCH}.tar.gz --directory ${TEMP_DIR}

### upgrade

if [[ "${APP_UPGRADE}" == true ]]; then
    printf "%sINFO:%s upgrading the existing installation\n" "${GREEN}" "${RESET}"
    systemctl --quiet stop alertmanager.service
    install -m 0755 -o ${APP_SA} -g ${APP_SA} ${TEMP_DIR}/alertmanager-${APP_VERSION#v}.linux-${SYSTEM_ARCH}/alertmanager /usr/local/bin/alertmanager
    install -m 0755 -o ${APP_SA} -g ${APP_SA} ${TEMP_DIR}/alertmanager-${APP_VERSION#v}.linux-${SYSTEM_ARCH}/amtool /usr/local/bin/amtool
    systemctl --quiet start alertmanager.service
    printf "%sINFO:%s upgrade succeeded\n" "${GREEN}" "${RESET}"
    exit 0
fi

### install

printf "%sINFO:%s starting the installation\n" "${GREEN}" "${RESET}"
useradd --system --no-create-home --shell /bin/false ${APP_SA}
mkdir /etc/alertmanager
mkdir /etc/alertmanager/templates
mkdir /var/lib/alertmanager

cat << EOF > /etc/alertmanager/alertmanager.yaml
templates:
  - "/etc/alertmanager/templates/*.tmpl"

route:
  group_by: ['...']
  group_wait: 0s
  group_interval: 15s
  repeat_interval: 1d
  receiver: webhooks
  routes:
    - matchers:
        - alertname="watchdog"
      continue: false
      group_by: ['...']
      group_wait: 0s
      group_interval: 15s
      repeat_interval: 15s
      receiver: healthchecks

receivers:
  - name: webhooks
    discord_configs:
      - send_resolved: true
        webhook_url: "${DISCORD_WEBHOOK_URL:-https://discord.com/api/webhooks/1234567890123456789/aBcDeFgHiJkLmNoPqRsTuVwXyZ0123456789_AbCdEfGhIjKlMnOpQrStUvWxYz012345}"
    webhook_configs:
      - send_resolved: true
        url: "${NTFY_WEBHOOK_URL:-https://ntfy.sh/zlqukzyfvsdfmlkg}?template=alertmanager"
  - name: healthchecks
    webhook_configs:
      - send_resolved: false
        url: "${HEALTHCHECKS_WEBHOOK_URL:-https://hc-ping.com/8e3b7b7e-1c9c-4c22-8f4e-6e3f1e9c8f9d}"
EOF

install -m 0755 -o ${APP_SA} -g ${APP_SA} ${TEMP_DIR}/alertmanager-${APP_VERSION#v}.linux-${SYSTEM_ARCH}/alertmanager /usr/local/bin/alertmanager
install -m 0755 -o ${APP_SA} -g ${APP_SA} ${TEMP_DIR}/alertmanager-${APP_VERSION#v}.linux-${SYSTEM_ARCH}/amtool /usr/local/bin/amtool
chown -R ${APP_SA}:${APP_SA} /etc/alertmanager
chown -R ${APP_SA}:${APP_SA} /var/lib/alertmanager

cat << EOF > /etc/systemd/system/alertmanager.service
[Unit]
Description=Alertmanager
Wants=network-online.target
After=network-online.target

[Service]
Type=simple
Restart=always
User=${APP_SA}
Group=${APP_SA}
ExecStart=/usr/local/bin/alertmanager \
--config.file="/etc/alertmanager/alertmanager.yaml" \
--cluster.listen-address="" \
--log.level="info" \
--log.format="logfmt" \
--web.listen-address="${APP_LISTEN_ADDRESS:-0.0.0.0}:${APP_LISTEN_PORT:-9093}" \
--storage.path="/var/lib/alertmanager"

[Install]
WantedBy=multi-user.target
EOF

systemctl --quiet daemon-reload
systemctl --quiet start alertmanager.service
systemctl --quiet enable alertmanager.service
printf "%sINFO:%s installation succeeded\n" "${GREEN}" "${RESET}"

Blackbox Exporter

This exporter can be used to expose metrics for a wide range of targets but we mainly use it to monitor HTTP endpoints and collect information about availability, latency and TLS certificate expiration.

Compared to other exporters the Blackbox Exporter works differently. It comes bundled with modules that define different types of checks. When the Prometheus server scrapes the Blackbox Exporter it provides the target and the module to use for the specific check.

Show blackbox-exporter.sh
#!/bin/bash

# This script installs Blackbox Exporter on Debian based systems.

set -e
set -u
set -o pipefail

### color variables

GRAY=$'\033[0;90m'
RED=$'\033[0;91m'
GREEN=$'\033[0;92m'
YELLOW=$'\033[0;93m'
BLUE=$'\033[0;94m'
MAGENTA=$'\033[0;95m'
CYAN=$'\033[0;96m'
WHITE=$'\033[0;97m'
RESET=$'\033[0m'

### preflight checks

PREFLIGHT_CHECKS_FAIL="false"

if [[ "${EUID}" -ne 0 ]]; then
    printf "%sERROR:%s script not running as root\n" "${RED}" "${RESET}"
    exit 1
fi

BINARIES=(
    curl
    jq
)
for i in "${BINARIES[@]}"; do
    if ! command -v "${i}" > /dev/null 2>&1; then
        PREFLIGHT_CHECKS_FAIL="true"
        printf "%sERROR:%s %s is not installed\n" "${RED}" "${RESET}" "${i}"
    fi
done

if [[ "${PREFLIGHT_CHECKS_FAIL}" == "true" ]]; then
    exit 1
fi

### app variables

APP_SA="blackbox_exporter"
APP_VERSION="$(curl -Ls https://api.github.com/repos/prometheus/blackbox_exporter/releases/latest | jq -r .tag_name)"
SYSTEM_ARCH="$(dpkg --print-architecture)"

APP_UPGRADE=false
if [[ -f /usr/local/bin/blackbox_exporter ]]; then
    APP_UPGRADE=true
fi

TEMP_DIR="$(mktemp -d)"
trap 'rm -rf "$TEMP_DIR"' EXIT

APP_LISTEN_ADDRESS=""
APP_LISTEN_PORT=""

### download

printf "%sINFO:%s downloading blackbox exporter %s for %s architecture\n" "${GREEN}" "${RESET}" "${APP_VERSION}" "${SYSTEM_ARCH}"
curl -sLo ${TEMP_DIR}/blackbox_exporter-${APP_VERSION#v}.linux-${SYSTEM_ARCH}.tar.gz https://github.com/prometheus/blackbox_exporter/releases/download/${APP_VERSION}/blackbox_exporter-${APP_VERSION#v}.linux-${SYSTEM_ARCH}.tar.gz
tar -xzf ${TEMP_DIR}/blackbox_exporter-${APP_VERSION#v}.linux-${SYSTEM_ARCH}.tar.gz --directory ${TEMP_DIR}

### upgrade

if [[ "${APP_UPGRADE}" == true ]]; then
    printf "%sINFO:%s upgrading the existing installation\n" "${GREEN}" "${RESET}"
    systemctl --quiet stop blackbox_exporter.service
    install -m 0755 -o ${APP_SA} -g ${APP_SA} ${TEMP_DIR}/blackbox_exporter-${APP_VERSION#v}.linux-${SYSTEM_ARCH}/blackbox_exporter /usr/local/bin/blackbox_exporter
    systemctl --quiet start blackbox_exporter.service
    printf "%sINFO:%s upgrade succeeded\n" "${GREEN}" "${RESET}"
    exit 0
fi

### install

printf "%sINFO:%s starting the installation\n" "${GREEN}" "${RESET}"
useradd --system --no-create-home --shell /bin/false ${APP_SA}
mkdir /etc/blackbox_exporter
cp ${TEMP_DIR}/blackbox_exporter-${APP_VERSION#v}.linux-${SYSTEM_ARCH}/blackbox.yml /etc/blackbox_exporter/blackbox_exporter.yaml
install -m 0755 -o ${APP_SA} -g ${APP_SA} ${TEMP_DIR}/blackbox_exporter-${APP_VERSION#v}.linux-${SYSTEM_ARCH}/blackbox_exporter /usr/local/bin/blackbox_exporter
chown -R ${APP_SA}:${APP_SA} /etc/blackbox_exporter

cat << EOF > /etc/systemd/system/blackbox_exporter.service
[Unit]
Description=Blackbox Exporter
Wants=network-online.target
After=network-online.target

[Service]
Type=simple
Restart=always
User=${APP_SA}
Group=${APP_SA}
ExecStart=/usr/local/bin/blackbox_exporter \
--config.file="/etc/blackbox_exporter/blackbox_exporter.yaml" \
--history.limit="100" \
--log.level="info" \
--log.format="logfmt" \
--web.listen-address="${APP_LISTEN_ADDRESS:-0.0.0.0}:${APP_LISTEN_PORT:-9115}"

[Install]
WantedBy=multi-user.target
EOF

systemctl --quiet daemon-reload
systemctl --quiet start blackbox_exporter.service
systemctl --quiet enable blackbox_exporter.service
printf "%sINFO:%s installation succeeded\n" "${GREEN}" "${RESET}"

Node Exporter

This exporter collects and exposes system-level metrics from the underlying host. It monitors key resources such as CPU, memory, disk usage, filesystem health, and network activity.

Show node-exporter.sh
#!/bin/bash

# This script installs Node Exporter on Debian based systems.

set -e
set -u
set -o pipefail

### color variables

GRAY=$'\033[0;90m'
RED=$'\033[0;91m'
GREEN=$'\033[0;92m'
YELLOW=$'\033[0;93m'
BLUE=$'\033[0;94m'
MAGENTA=$'\033[0;95m'
CYAN=$'\033[0;96m'
WHITE=$'\033[0;97m'
RESET=$'\033[0m'

### preflight checks

PREFLIGHT_CHECKS_FAIL="false"

if [[ "${EUID}" -ne 0 ]]; then
    printf "%sERROR:%s script not running as root\n" "${RED}" "${RESET}"
    exit 1
fi

BINARIES=(
    curl
    jq
)
for i in "${BINARIES[@]}"; do
    if ! command -v "${i}" > /dev/null 2>&1; then
        PREFLIGHT_CHECKS_FAIL="true"
        printf "%sERROR:%s %s is not installed\n" "${RED}" "${RESET}" "${i}"
    fi
done

if [[ "${PREFLIGHT_CHECKS_FAIL}" == "true" ]]; then
    exit 1
fi

### app variables

APP_SA="node_exporter"
APP_VERSION="$(curl -Ls https://api.github.com/repos/prometheus/node_exporter/releases/latest | jq -r .tag_name)"
SYSTEM_ARCH="$(dpkg --print-architecture)"

APP_UPGRADE=false
if [[ -f /usr/local/bin/node_exporter ]]; then
    APP_UPGRADE=true
fi

TEMP_DIR="$(mktemp -d)"
trap 'rm -rf "$TEMP_DIR"' EXIT

APP_LISTEN_ADDRESS=""
APP_LISTEN_PORT=""

### download

printf "%sINFO:%s downloading node exporter %s for %s architecture\n" "${GREEN}" "${RESET}" "${APP_VERSION}" "${SYSTEM_ARCH}"
curl -sLo ${TEMP_DIR}/node_exporter-${APP_VERSION#v}.linux-${SYSTEM_ARCH}.tar.gz https://github.com/prometheus/node_exporter/releases/download/${APP_VERSION}/node_exporter-${APP_VERSION#v}.linux-${SYSTEM_ARCH}.tar.gz
tar -xzf ${TEMP_DIR}/node_exporter-${APP_VERSION#v}.linux-${SYSTEM_ARCH}.tar.gz --directory ${TEMP_DIR}

### upgrade

if [[ "${APP_UPGRADE}" == true ]]; then
    printf "%sINFO:%s upgrading the existing installation\n" "${GREEN}" "${RESET}"
    systemctl --quiet stop node_exporter.service
    install -m 0755 -o ${APP_SA} -g ${APP_SA} ${TEMP_DIR}/node_exporter-${APP_VERSION#v}.linux-${SYSTEM_ARCH}/node_exporter /usr/local/bin/node_exporter
    systemctl --quiet start node_exporter.service
    printf "%sINFO:%s upgrade succeeded\n" "${GREEN}" "${RESET}"
    exit 0
fi

### install

printf "%sINFO:%s starting the installation\n" "${GREEN}" "${RESET}"
useradd --system --no-create-home --shell /bin/false ${APP_SA}
install -m 0755 -o ${APP_SA} -g ${APP_SA} ${TEMP_DIR}/node_exporter-${APP_VERSION#v}.linux-${SYSTEM_ARCH}/node_exporter /usr/local/bin/node_exporter

cat << EOF > /etc/systemd/system/node_exporter.service
[Unit]
Description=Node Exporter
Wants=network-online.target
After=network-online.target

[Service]
Type=simple
Restart=always
User=${APP_SA}
Group=${APP_SA}
ExecStart=/usr/local/bin/node_exporter \
--log.level="info" \
--log.format="logfmt" \
--web.listen-address="${APP_LISTEN_ADDRESS:-0.0.0.0}:${APP_LISTEN_PORT:-9100}"

[Install]
WantedBy=multi-user.target
EOF

systemctl --quiet daemon-reload
systemctl --quiet start node_exporter.service
systemctl --quiet enable node_exporter.service
printf "%sINFO:%s installation succeeded\n" "${GREEN}" "${RESET}"

cAdvisor

This exporter exposes metrics for all containers running on a system. We could already expose metrics for the Docker engine by adding the metrics-addr option in the /etc/docker/daemon.json configuration file but with cAdvisor we can expose metrics for the actual containers.

Show cadvisor.sh
#!/bin/bash

# This script installs cAdvisor on Debian based systems.

set -e
set -u
set -o pipefail

### color variables

GRAY=$'\033[0;90m'
RED=$'\033[0;91m'
GREEN=$'\033[0;92m'
YELLOW=$'\033[0;93m'
BLUE=$'\033[0;94m'
MAGENTA=$'\033[0;95m'
CYAN=$'\033[0;96m'
WHITE=$'\033[0;97m'
RESET=$'\033[0m'

### preflight checks

PREFLIGHT_CHECKS_FAIL="false"

if [[ "${EUID}" -ne 0 ]]; then
    printf "%sERROR:%s script not running as root\n" "${RED}" "${RESET}"
    exit 1
fi

BINARIES=(
    curl
    jq
)
for i in "${BINARIES[@]}"; do
    if ! command -v "${i}" > /dev/null 2>&1; then
        PREFLIGHT_CHECKS_FAIL="true"
        printf "%sERROR:%s %s is not installed\n" "${RED}" "${RESET}" "${i}"
    fi
done

if [[ "${PREFLIGHT_CHECKS_FAIL}" == "true" ]]; then
    exit 1
fi

### app variables

APP_SA="root"
APP_VERSION="$(curl -Ls https://api.github.com/repos/google/cadvisor/releases/latest | jq -r .tag_name)"
SYSTEM_ARCH="$(dpkg --print-architecture)"

APP_UPGRADE=false
if [[ -f /usr/local/bin/cadvisor ]]; then
    APP_UPGRADE=true
fi

TEMP_DIR="$(mktemp -d)"
trap 'rm -rf "$TEMP_DIR"' EXIT

APP_LISTEN_ADDRESS=""
APP_LISTEN_PORT=""

### download

printf "%sINFO:%s downloading cadvisor %s for %s architecture\n" "${GREEN}" "${RESET}" "${APP_VERSION}" "${SYSTEM_ARCH}"
curl -sLo ${TEMP_DIR}/cadvisor-${APP_VERSION}-linux-${SYSTEM_ARCH} https://github.com/google/cadvisor/releases/download/${APP_VERSION}/cadvisor-${APP_VERSION}-linux-${SYSTEM_ARCH}

### upgrade

if [[ "${APP_UPGRADE}" == true ]]; then
    printf "%sINFO:%s upgrading the existing installation\n" "${GREEN}" "${RESET}"
    systemctl --quiet stop cadvisor.service
    install -m 0755 -o ${APP_SA} -g ${APP_SA} ${TEMP_DIR}/cadvisor-${APP_VERSION}-linux-${SYSTEM_ARCH} /usr/local/bin/cadvisor
    systemctl --quiet start cadvisor.service
    printf "%sINFO:%s upgrade succeeded\n" "${GREEN}" "${RESET}"
    exit 0
fi

### install

printf "%sINFO:%s starting the installation\n" "${GREEN}" "${RESET}"
install -m 0755 -o ${APP_SA} -g ${APP_SA} ${TEMP_DIR}/cadvisor-${APP_VERSION}-linux-${SYSTEM_ARCH} /usr/local/bin/cadvisor

cat << EOF > /etc/systemd/system/cadvisor.service
[Unit]
Description=cAdvisor
Wants=network-online.target
After=network-online.target

[Service]
Type=simple
Restart=always
User=${APP_SA}
Group=${APP_SA}
ExecStart=/usr/local/bin/cadvisor \
--docker_only=true \
--housekeeping_interval="10s" \
--docker="unix:///var/run/docker.sock" \
--listen_ip="${APP_LISTEN_ADDRESS:-0.0.0.0}" \
--port="${APP_LISTEN_PORT:-8080}"

[Install]
WantedBy=multi-user.target
EOF

systemctl --quiet daemon-reload
systemctl --quiet start cadvisor.service
systemctl --quiet enable cadvisor.service
printf "%sINFO:%s installation succeeded\n" "${GREEN}" "${RESET}"

Pushgateway

When scraping the Pushgateway it is important to set honor_labels: true in the Prometheus configuration to preserve the labels provided by the pushed metrics.

Here is a simple example of pushing a metric to the Pushgateway using curl..

echo "batch_job_duration_seconds 21" | \
  curl --data-binary @- \
  http://localhost:9091/metrics/job/batch/instance/server

This pushes the batch_job_duration_seconds metric with a value of 21 for the batch job and server instance.

Show pushgateway.sh
#!/bin/bash

# This script installs Pushgateway on Debian based systems.

set -e
set -u
set -o pipefail

### color variables

GRAY=$'\033[0;90m'
RED=$'\033[0;91m'
GREEN=$'\033[0;92m'
YELLOW=$'\033[0;93m'
BLUE=$'\033[0;94m'
MAGENTA=$'\033[0;95m'
CYAN=$'\033[0;96m'
WHITE=$'\033[0;97m'
RESET=$'\033[0m'

### preflight checks

PREFLIGHT_CHECKS_FAIL="false"

if [[ "${EUID}" -ne 0 ]]; then
    printf "%sERROR:%s script not running as root\n" "${RED}" "${RESET}"
    exit 1
fi

BINARIES=(
    curl
    jq
)
for i in "${BINARIES[@]}"; do
    if ! command -v "${i}" > /dev/null 2>&1; then
        PREFLIGHT_CHECKS_FAIL="true"
        printf "%sERROR:%s %s is not installed\n" "${RED}" "${RESET}" "${i}"
    fi
done

if [[ "${PREFLIGHT_CHECKS_FAIL}" == "true" ]]; then
    exit 1
fi

### app variables

APP_SA="pushgateway"
APP_VERSION="$(curl -Ls https://api.github.com/repos/prometheus/pushgateway/releases/latest | jq -r .tag_name)"
SYSTEM_ARCH="$(dpkg --print-architecture)"

APP_UPGRADE=false
if [[ -f /usr/local/bin/pushgateway ]]; then
    APP_UPGRADE=true
fi

TEMP_DIR="$(mktemp -d)"
trap 'rm -rf "$TEMP_DIR"' EXIT

APP_LISTEN_ADDRESS=""
APP_LISTEN_PORT=""

### download

printf "%sINFO:%s downloading pushgateway %s for %s architecture\n" "${GREEN}" "${RESET}" "${APP_VERSION}" "${SYSTEM_ARCH}"
curl -sLo ${TEMP_DIR}/pushgateway-${APP_VERSION#v}.linux-${SYSTEM_ARCH}.tar.gz https://github.com/prometheus/pushgateway/releases/download/${APP_VERSION}/pushgateway-${APP_VERSION#v}.linux-${SYSTEM_ARCH}.tar.gz
tar -xzf ${TEMP_DIR}/pushgateway-${APP_VERSION#v}.linux-${SYSTEM_ARCH}.tar.gz --directory ${TEMP_DIR}

### upgrade

if [[ "${APP_UPGRADE}" == true ]]; then
    printf "%sINFO:%s upgrading the existing installation\n" "${GREEN}" "${RESET}"
    systemctl --quiet stop pushgateway.service
    install -m 0755 -o ${APP_SA} -g ${APP_SA} ${TEMP_DIR}/pushgateway-${APP_VERSION#v}.linux-${SYSTEM_ARCH}/pushgateway /usr/local/bin/pushgateway
    systemctl --quiet start pushgateway.service
    printf "%sINFO:%s upgrade succeeded\n" "${GREEN}" "${RESET}"
    exit 0
fi

### install

printf "%sINFO:%s starting the installation\n" "${GREEN}" "${RESET}"
useradd --system --no-create-home --shell /bin/false ${APP_SA}
mkdir /var/lib/pushgateway
install -m 0755 -o ${APP_SA} -g ${APP_SA} ${TEMP_DIR}/pushgateway-${APP_VERSION#v}.linux-${SYSTEM_ARCH}/pushgateway /usr/local/bin/pushgateway
chown -R ${APP_SA}:${APP_SA} /var/lib/pushgateway

cat << EOF > /etc/systemd/system/pushgateway.service
[Unit]
Description=Pushgateway
Wants=network-online.target
After=network-online.target

[Service]
Type=simple
Restart=always
User=${APP_SA}
Group=${APP_SA}
ExecStart=/usr/local/bin/pushgateway \
--persistence.file="/var/lib/pushgateway/pushgateway.data" \
--persistence.interval="5m" \
--web.enable-lifecycle \
--web.enable-admin-api \
--log.level="info" \
--log.format="logfmt" \
--web.listen-address="${APP_LISTEN_ADDRESS:-0.0.0.0}:${APP_LISTEN_PORT:-9091}"

[Install]
WantedBy=multi-user.target
EOF

systemctl --quiet daemon-reload
systemctl --quiet start pushgateway.service
systemctl --quiet enable pushgateway.service
printf "%sINFO:%s installation succeeded\n" "${GREEN}" "${RESET}"

Troubleshooting

If you create a target through a file and it does not appear on the Prometheus dashboard at the URL http://${PROMETHEUS_IP}:9090/targets it means that there is an issue with the file you created in /etc/prometheus/targets.

If you create a target and it appears on the Prometheus dashboard but its state is DOWN it means that either Prometheus can’t reach the ${TARGET_IP} or that the metrics are not exposed at the URL http://${TARGET_IP}:${TARGET_PORT}/metrics.

If you create a rule file and it doesn’t appear on the Prometheus dashboard at the URL http://${PROMETHEUS_IP}:9090/rules restart the Prometheus systemd service.

If you see alerts firing at the URL http://${PROMETHEUS_IP}:9090/alerts but you are not receiving notifications, check that..

  • there is no issue with the configuration file of the Alertmanager.. amtool check-config /etc/alertmanager/alertmanager.yaml
  • the Alertmanager service is running.. systemctl status alertmanager
  • in /etc/prometheus/prometheus.yaml under the alerting: section the IP of the Alertmanager is correct and reachable by the system hosting the Prometheus server
  • in /etc/alertmanager/alertmanager.yaml you have configured your webhooks correctly

If cAdvisor is using too much CPU check this GitHub issue.


Ongoing Maintenance

The scripts we used for the installation can also upgrade the components they install. On the first run they perform a full installation, subsequent runs upgrade the components to their latest versions without changing their configuration files.


Closing Thoughts

So we have seen how to install and configure the Prometheus monitoring stack. You might be wondering, why not just run everything in Docker?

Running everything in Docker would definitely make sense, but for my use case, I treat Docker as ephemeral while I want my monitoring stack to be more permanent.

Finally there are two useful tools worth mentioning, pint which is a Prometheus rule linter and sloth which can help you create SLOs.