Skip to content

Add rule for Pod (un)readiness and alarm to Slack #7

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 11 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions alertmanager/alertmanager.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
global:
resolve_timeout: 5m
slack_api_url: ''
route:
group_by: ['alertname', 'cluster', 'service', 'deployment', 'namespace']
group_wait: 30s
group_interval: 5m
repeat_interval: 1h
receiver: default-receiver
routes:
- match:
alertname: DeadMansSwitch
receiver: 'null'
receivers:
- name: 'default-receiver'
slack_configs:
- channel: '#alerts'
title: >-
[{{ .Status | toUpper }}{{ if eq .Status "firing" }}:{{ .Alerts.Firing | len }}{{ end }}]
{{ range .Alerts }}
{{ .Annotations.summary }}
{{ end }}
text: >-
{{ range .Alerts }}
*Alert:* {{ .Annotations.summary }} - `{{ .Labels.severity }}`
*Description:* {{ .Annotations.description }}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like Line 25 has an extra space, as it does in the article you and I both copy pasted it from. 😉

*Graph:* <{{ .GeneratorURL }}|:chart_with_upwards_trend:> *Runbook:* <{{ .Annotations.runbook }}|:spiral_note_pad:>
Copy link

@StevenACoffman StevenACoffman Jun 3, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@solsson Oooo ... nice idea! Are you using SkeltonThatcher's run book template? Do you have any example ones you can share?

*Details:*
{{ range .Labels.SortedPairs }} • *{{ .Name }}:* `{{ .Value }}`
{{ end }}
{{ end }}
send_resolved: true
- name: 'null'
17 changes: 17 additions & 0 deletions alertmanager/update.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash
set -e
set -x
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

if [ -z "${NAMESPACE}" ]; then
NAMESPACE=monitoring
fi

kctl() {
kubectl --namespace "$NAMESPACE" "$@"
}

SECRET=alertmanager-main

kctl create secret generic $SECRET --from-file $DIR/alertmanager.yaml --dry-run -o=yaml \
| kctl replace secret $SECRET -f -

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does replace work if the secret does not already exist?

4 changes: 1 addition & 3 deletions custom-prometheus/config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,4 @@ kctl() {
SECRET=prometheus-custom

kctl create secret generic $SECRET --from-file $DIR/config/prometheus.yaml --dry-run -o=yaml \
| kctl replace secret $SECRET -f - \
&& kctl scale --replicas=0 statefulset prometheus-custom \
&& kctl scale --replicas=1 statefulset prometheus-custom
| kctl replace secret $SECRET -f -
16 changes: 16 additions & 0 deletions k8s-rules-apply.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash
set -e
set -x
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

if [ -z "${NAMESPACE}" ]; then
NAMESPACE=monitoring
fi

kctl() {
kubectl --namespace "$NAMESPACE" "$@"
}

SECRET=prometheus-custom

$DIR/k8s-rules-generate.sh | kctl replace -f -
2 changes: 1 addition & 1 deletion generate-prometheus-rules.sh → k8s-rules-generate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ cd kube-prometheus
. hack/scripts/generate-rules-configmap.sh
cd ..

for f in rules/*.rules.yaml
for f in k8s-yolean-rules/*.y*ml
do
echo " $(basename $f): |+"
cat $f | sed "s/^/ /g"
Expand Down
14 changes: 14 additions & 0 deletions k8s-yolean-rules/pod-unavailable.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
groups:
- name: ./yolean.availability.rules
rules:
- alert: AvailabilityCheckFailed
expr: "(kube_deployment_status_replicas_available / kube_deployment_spec_replicas) * 100 < 100"
# NOTE This seems to be optional, thus missing should equal 0 ?
# for: 5s
# NOTE:
# Both labels and annotations support templates:
# https://prometheus.io/docs/alerting/rules/#templating
labels:
severity: critical
annotations:
summary: "{{ $value }}% of {{ $labels.deployment }}[{{ $labels.namespace }}] available"