Score:0

Prometheus Alertmanager - Generating alerts

au flag

When alerts are based on metric data, like CPU or memory utilization, Prometheus is the obvious tool for pushing alerts into Alertmanager. There are other examples where the required alert is based on Boolean conditions, like "is DNS working". In such instances, is there a "best practice" method for generating these alerts?

Using the above DNS example, I could use a script:-

#!/usr/bin/env bash

function alert {
    /usr/local/bin/amtool alert add \
        alertname=resolveFail \
        instance=$(hostname -s) \
        severity=warning \
        --annotation=summary='DNS resolve failure'
}

if ! /usr/bin/host $HOSTNAME 127.0.0.1 &> /dev/null
then
    alert
fi

A slight alternative would be to use curl instead of amtool and push to the Alertmanager API. A third option would be to modify the above script to create a metric for the Node Exporter Textfile Collector:-

#!/usr/bin/env bash

TEXTFILE_COLLECTOR_DIR=/var/lib/node_exporter/textfile_collector/

if /usr/bin/host $HOSTNAME 127.0.0.1 &> /dev/null
then
    STATE=1
else
    STATE=0
fi
echo "node_dns_resolving $STATE" > $TEXTFILE_COLLECTOR_DIR/dns.prom.$$
mv "$TEXTFILE_COLLECTOR_DIR/dns.prom.$$" "$TEXTFILE_COLLECTOR_DIR/dns.prom"

I'd be interested to hear recommendations for these (or maybe other) methods.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.