Last active
May 1, 2018 17:58
-
-
Save grampelberg/089b943ff546baf5b76a0c3a0d8f45f7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# usage: ./graph.bash | dot -Tpng >foo.png && open foo.png | |
function deployments() { | |
conduit stat deployments --all-namespaces \ | |
| awk '{ print $1 "|" $2 }' \ | |
| tail -n+2 | |
} | |
function edges() { | |
conduit stat deployments --all-namespaces --from deploy/$1 --from-namespace $2 2> /dev/null \ | |
| awk '{ print $1 "|" $2 "|" $4 }' \ | |
| tail -n+2 | |
} | |
function color() { | |
if [[ "${1::${#1}-4}" -lt 50 ]]; then | |
echo "red" | |
elif [[ "${1::${#1}-4}" -lt 100 ]]; then | |
echo "yellow" | |
else | |
echo "green" | |
fi | |
} | |
echo "digraph {" | |
OIFS=${IFS} | |
for dep in $(deployments); do | |
IFS="|" | |
depDetails=(${dep}) | |
IFS=${OIFS} | |
for edge in $(edges ${depDetails[1]} ${depDetails[0]}); do | |
IFS="|" | |
edgeDetails=(${edge}) | |
IFS=${OIFS} | |
dest="${edgeDetails[0]}/${edgeDetails[1]}" | |
success=${edgeDetails[2]} | |
echo " \"${depDetails[0]}/${depDetails[1]}\" -> \"${dest}\"[color=$(color $success),label=\"${success}\"]" | |
done | |
done | |
echo "}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment