Skip to content
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

refact: gather-monitoring by Prometheus replica #22

Open
wants to merge 1 commit into
base: master-upstream
Choose a base branch
from
Open
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
48 changes: 27 additions & 21 deletions collection-scripts/gather_monitoring
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@ declare -r CA_BUNDLE="${MONITORING_PATH}/ca-bundle.crt"
init() {
mkdir -p "${MONITORING_PATH}"

PROMETHEUS_ROUTE="$(oc get routes \
-n openshift-monitoring prometheus-k8s \
-o jsonpath='{.status.ingress[0].host}')"

ALERT_MANAGER_ROUTE="$(oc get routes \
-n openshift-monitoring alertmanager-main \
-o jsonpath='{.status.ingress[0].host}')"
Expand All @@ -34,20 +30,36 @@ cleanup() {
rm "$CA_BUNDLE"
}

prom_get() {
prom_get_by_replica() {
local replica="$1"; shift
local object="$1"; shift
local path="$1"; shift

local result_path="$MONITORING_PATH/prometheus/$path"
mkdir -p "$(dirname "$result_path")"
local result_path="${MONITORING_PATH}/prometheus/${path}"
mkdir -p "$(dirname "${result_path}")"

oc get \
--certificate-authority="$CA_BUNDLE" \
--token="${SA_TOKEN}" \
--server="https://$PROMETHEUS_ROUTE" \
--raw="/api/v1/$object" \
> "$result_path.json" \
2> "$result_path.stderr"
oc --insecure-skip-tls-verify exec pod/${replica} \
-c prometheus \
-n openshift-monitoring \
-- /bin/bash -c "curl -sG http://localhost:9090/api/v1/${object}" \
> "${result_path}.json" \
2> "${result_path}.stderr"
}

prometheus_gather_by_replica(){
echo "Collecting metrics for each replica..."
local pods="$(oc get pods -n openshift-monitoring -l prometheus=k8s -o jsonpath='{.items[*].metadata.name}')"

echo "Replicas found: $pods"
for POD in ${pods}; do
prom_get_by_replica ${POD} rules ${POD}/rules || true
prom_get_by_replica ${POD} alertmanagers ${POD}/alertmanagers || true
prom_get_by_replica ${POD} status/config ${POD}/status/config || true
prom_get_by_replica ${POD} status/flags ${POD}/status/flags || true
prom_get_by_replica ${POD} status/runtimeinfo ${POD}/status/runtimeinfo || true
prom_get_by_replica ${POD} status/buildinfo ${POD}/status/buildinfo || true
prom_get_by_replica ${POD} status/tsdb ${POD}/status/tsdb || true
done
}

alertmanager_get() {
Expand All @@ -66,19 +78,13 @@ alertmanager_get() {
2> "$result_path.stderr"
}


monitoring_gather(){
init

# begin gathering
# NOTE || true ignores failures

prom_get rules rules || true
prom_get alertmanagers alertmanagers || true
prom_get status/config status/config || true
prom_get status/flags status/flags || true
prom_get status/runtimeinfo status/runtimeinfo || true
prom_get status/tsdb status/tsdb || true
prometheus_gather_by_replica || true

alertmanager_get status status || true

Expand Down