Skip to content

Commit 1ceec2f

Browse files
oarribasopenshift-merge-bot[bot]
authored andcommitted
Gathering OpenShift alerts in Logging must-gather
Gathering OpenShift alerts in Logging must-gather, based on the script in "standard" must-gather
1 parent 117d888 commit 1ceec2f

File tree

4 files changed

+89
-1
lines changed

4 files changed

+89
-1
lines changed

must-gather/README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ The `clusterlogging` and `clusterlogforwarder` resources, and also `installplans
4141

4242
The `deployments`, `daemonsets` and `secrets` are also found under `namespaces/[namespace_name]/` and can also be seen using the [`omc`](https://github.com/gmeghnag/omc/) tool.
4343

44+
The cluster alerts are now in the `monitoring/prometheus/` directory, and can be checked with `omc prometheus alertrule` and `oc prometheus alertrule -s firing` (for the firing ones only.
45+
4446
Example must-gather for cluster-logging output (use `tree` for up-to-date structure):
4547
```
4648
├── cluster-logging
@@ -78,7 +80,11 @@ Example must-gather for cluster-logging output (use `tree` for up-to-date struct
7880
├── [...]
7981
├── event-filter.html
8082
├── gather-debug.log
81-
└── namespaces
83+
├── monitoring
84+
│   └── prometheus
85+
│   ├── rules.json
86+
│   └── rules.stderr
87+
├── namespaces
8288
│ ├── [namespace_name] ## including openshift-logging
8389
│ │ ├── apps
8490
│ │ │ ├── daemonsets.yaml

must-gather/collection-scripts/gather

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,10 @@ else
108108
log "UIPlugin not installed" 2>&1 | tee -a "${LOGFILE_PATH}"
109109
fi
110110

111+
log "BEGIN gathering alerts ..." | tee -a "${LOGFILE_PATH}"
112+
${SCRIPT_DIR}/gather_monitoring "$BASE_COLLECTION_PATH" 2>&1 | tee -a "${LOGFILE_PATH}" &
113+
pids+=($!)
114+
111115
default_clo_found="$(oc -n "$LOGGING_NS" get deployment cluster-logging-operator --ignore-not-found --no-headers)"
112116

113117
if [ "$default_clo_found" != "" ] ; then
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
#!/bin/bash
2+
3+
# based on gather_monitoring script from standard must-gather
4+
5+
# safeguards
6+
set -o nounset
7+
set -o errexit
8+
set -o pipefail
9+
10+
# global readonly constants
11+
# expect base collection path as an argument
12+
declare -r BASE_COLLECTION_PATH=$1
13+
declare -r MONITORING_PATH="${BASE_COLLECTION_PATH}/monitoring"
14+
15+
source "$(dirname "$0")"/monitoring_common.sh
16+
17+
# init initializes global variables that need to be computed.
18+
# E.g. get token of the default ServiceAccount
19+
init() {
20+
mkdir -p "${MONITORING_PATH}"
21+
22+
readarray -t PROM_PODS < <(
23+
oc get pods -n openshift-monitoring -l prometheus=k8s \
24+
--no-headers -o custom-columns=":metadata.name"
25+
)
26+
}
27+
28+
# prom_get makes http GET requests to prometheus /api/v1/$object and stores
29+
# the stdout and stderr results
30+
prom_get() {
31+
local object="$1"; shift
32+
local path="${1:-$object}"; shift || true
33+
local pod
34+
pod=$(get_first_ready_prom_pod)
35+
36+
local result_path="$MONITORING_PATH/prometheus/$path"
37+
mkdir -p "$(dirname "$result_path")"
38+
39+
echo "INFO: Getting ${object} from ${pod}"
40+
oc exec "${pod}" \
41+
-c prometheus \
42+
-n openshift-monitoring \
43+
-- /bin/bash -c "curl -sG http://localhost:9090/api/v1/${object}" \
44+
> "${result_path}.json" \
45+
2> "${result_path}.stderr"
46+
}
47+
48+
monitoring_gather(){
49+
init
50+
51+
echo "INFO: Found ${#PROM_PODS[@]} replicas - ${PROM_PODS[*]}"
52+
53+
# begin gathering
54+
# NOTE || true ignores failures
55+
56+
prom_get rules || true
57+
58+
# force disk flush to ensure that all data gathered are written
59+
sync
60+
}
61+
62+
monitoring_gather
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/bin/bash
2+
3+
# based on monitoring_common.sh script from standard must-gather
4+
5+
# safeguards
6+
set -o nounset
7+
set -o errexit
8+
set -o pipefail
9+
10+
get_first_ready_prom_pod() {
11+
readarray -t READY_PROM_PODS < <(
12+
oc get pods -n openshift-monitoring -l prometheus=k8s --field-selector=status.phase==Running \
13+
--no-headers -o custom-columns=":metadata.name"
14+
)
15+
echo "${READY_PROM_PODS[0]}"
16+
}

0 commit comments

Comments
 (0)