Get job stats

6 views
Skip to first unread message

Roger McCarrick

unread,
Sep 5, 2025, 10:06:51 AM (3 days ago) Sep 5
to rundeck-discuss
In the Rundeck GUI, a job shows number of executions and success rate. How do I get those stats? Can I use the rd utility or the API?

thanks

Roger McCarrick

unread,
Sep 5, 2025, 4:25:04 PM (3 days ago) Sep 5
to rundeck-discuss
I got it, this is in bash, using curl and the Rundeck API and paging.

rundeckURL="https://rundeck/api/41"
rdheaders="X-Rundeck-Auth-Token: $token"

 all_executions="[]"
                limit=100
                offset=0
                total=0
                succeeded=0
                pcSucceeded=0

                while :; do
                        url="$rundeckURL/job/$UUID/executions?max=$limit&offset=$offset"

                        # Fetch the page
                        response=$(curl -s -H "$rdheaders" -H "Accept: application/json" "$url")

                        # Get execution count using jq
                        count=$(echo "$response" | jq '.executions | length')

                        # Append executions to accumulator
                        if (( count > 0 )); then
                        # Merge into all_executions
                        all_executions=$(jq -s '.[0] + .[1]' <(echo "$all_executions") <(echo "$response" | jq '.executions'))

                        # Advance offset
                        offset=$((offset + limit))
                else
                        break
                fi

                # Be gentle to API
                sleep 0.2
                done

                total=$(echo "$all_executions" | jq 'length')
                succeeded=$(echo "$all_executions" | jq '[.[] | select(.status=="succeeded")] | length')

                if [ "$total" -gt 0 ]; then
                        pcSucceeded=$(( 100 * succeeded / total ))
                fi

# $total is the total amount of executions of job $UUID
#  $pcSucceeded is the % of the total that have a status of "succeeded"
                echo "  $JNAME $total $pcSucceeded"


Reply all
Reply to author
Forward
0 new messages