Skip to content

Commit

Permalink
Merge pull request #305 from vprashar2929/mon-gather
Browse files Browse the repository at this point in the history
feat: enable must-gather for uwm
  • Loading branch information
sthaha authored Nov 10, 2023
2 parents 87de2ca + 6902902 commit d6abc5e
Show file tree
Hide file tree
Showing 2 changed files with 106 additions and 2 deletions.
10 changes: 8 additions & 2 deletions must-gather/gather
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ print_usage() {
get_kepler_instance() {
log "getting kepler instance(s)"
KEPLERS=$(oc get keplers.kepler.system.sustainable.computing.io -oname)
if [ ! -z "$KEPLERS" ]; then
run oc get $KEPLERS -oyaml "$BASE_COLLECTION_PATH/keplers.yaml"
if [ -n "$KEPLERS" ]; then
run oc get "$KEPLERS" -oyaml "$BASE_COLLECTION_PATH/keplers.yaml"
else
echo "no keplers found" >>"$BASE_COLLECTION_PATH/keplers.yaml"
fi
Expand Down Expand Up @@ -83,6 +83,11 @@ gather_kepler_operator_info() {
"$SCRIPT_DIR"/gather-kepler-operator-info "$BASE_COLLECTION_PATH"
}

gather_monitoring_info() {
log "getting monitoring info"
"$SCRIPT_DIR"/gather-monitoring-info "$BASE_COLLECTION_PATH"
}

main() {
case ${1-} in
--help | -h)
Expand Down Expand Up @@ -113,6 +118,7 @@ main() {
gather_kepler_exporter_info
gather_olm_info
gather_kepler_operator_info
gather_monitoring_info

echo "powermon must-gather completed"
}
Expand Down
98 changes: 98 additions & 0 deletions must-gather/gather-monitoring-info
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
#!/usr/bin/env bash

# copyright 2023.
#
# licensed under the apache license, version 2.0 (the "license");
# you may not use this file except in compliance with the license.
# you may obtain a copy of the license at
#
# http://www.apache.org/licenses/license-2.0
#
# unless required by applicable law or agreed to in writing, software
# distributed under the license is distributed on an "as is" basis,
# without warranties or conditions of any kind, either express or implied.
# see the license for the specific language governing permissions and
# limitations under the license.
#

set -eu -o pipefail

trap cleanup EXIT

SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd)

# constants
declare -r BASE_COLLECTION_PATH=$1
declare -r UWM_NS="openshift-user-workload-monitoring"
declare -r UWM_INFO_DIR="${BASE_COLLECTION_PATH}/uwm-info"
declare -r CA_BUNDLE="${UWM_INFO_DIR}/ca-bundle.crt"

source "${SCRIPT_DIR}/common"

init() {
mkdir -p "${UWM_INFO_DIR}"

THANOS_RULER_ROUTE="$(oc get routes -n $UWM_NS thanos-ruler -o jsonpath='{.status.ingress[0].host}')" || return 1
SA_TOKEN="$(oc create token default)" || return 1
PROM_PODS="$(oc -n $UWM_NS get pods -l app.kubernetes.io/component=prometheus -oname)" || return 1

return 0
}

cleanup() {
log "Cleaning up..."
rm "${CA_BUNDLE}"
}

get_rules() {
log "getting prometheus rules"
run oc -n openshift-config-managed get cm default-ingress-cert -o jsonpath='{.data.ca-bundle\.crt}' "${CA_BUNDLE}"
run oc get --certificate-authority="${CA_BUNDLE}" \
--token="${SA_TOKEN}" --server="https://${THANOS_RULER_ROUTE}" \
--raw="/api/v1/rules" "${UWM_INFO_DIR}/rules.json"
}

get_from_prom_replica() {
local replica="$1"
shift
local object="$1"
shift
local path="${1:-$object}"
shift || true

local result_path="${UWM_INFO_DIR}/${path}"
mkdir -p "$(dirname "${result_path}")"
run oc exec "${replica}" \
-c prometheus \
-n $UWM_NS \
-- curl -sG "http://localhost:9090/api/v1/${object}" \
"${result_path}.json"
}

get_from_prom_replicas() {
local object="$1"
shift
local path="${1:-$object}"
shift || true

for pod in ${PROM_PODS}; do
pod=$(echo "$pod" | awk -F '/' '{print $2}')
log "getting ${object} from prometheus pod: ${pod}"
get_from_prom_replica "${pod}" "${object}" "${pod}/${path}" || true
done
}

main() {
init || {
log "cannot gather UWM details"
return 0
}

get_rules || true
get_from_prom_replicas status/runtimeinfo || true
get_from_prom_replicas status/config || true
get_from_prom_replicas 'targets?state=active' active-targets || true
get_from_prom_replicas status/tsdb || true
}

main "$@"

0 comments on commit d6abc5e

Please sign in to comment.