Skip to content

Instantly share code, notes, and snippets.

@dmc5179
Created September 2, 2022 23:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dmc5179/b132138d42c5c9de9864fa0ce06e6779 to your computer and use it in GitHub Desktop.
Save dmc5179/b132138d42c5c9de9864fa0ce06e6779 to your computer and use it in GitHub Desktop.
OpenShift 4 Prometheus time series query
QUERY="kube_pod_status_phase{phase='Running'}"
HEADER="Authorization: Bearer sha256~....."
API="https://prometheus-k8s-openshift-monitoring.apps.ocp4.something.io/api/v1/query_range?query"
START="2022-09-02T19:10:30.781Z"
END="2022-09-02T19:11:30.781Z"
STEP="15s"
rawurlencode_vladr() {
local LANG=C
local IFS=
while read -n1 -r -d "$(echo -n "\000")" c
do
case "$c" in
[-_.~a-zA-Z0-9])
echo -n "$c"
;;
*)
printf '%%%02x' "'$c"
;;
esac
done
}
ENC_QUERY=$(echo -n "${QUERY}" | rawurlencode_vladr)
curl -k -H "${HEADER}" "${API}=${ENC_QUERY}&start=${START}&end=${END}&step=${STEP}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment