BjornMagnussonXA | a79a043 | 2019-07-17 08:26:50 +0000 | [diff] [blame^] | 1 | #!/bin/bash |
| 2 | |
| 3 | # Script to print internal dfc stats every 5 sec to screen and file |
| 4 | # Default port is 8100 for DFC |
| 5 | # Useage: ./dfc-internal-stats.sh all|internal|jvm [<dfc-port-number>] |
| 6 | |
| 7 | print_usage() { |
| 8 | echo "Useage: ./dfc-internal-stats.sh all|internal|jvm [<dfc-port-number>]" |
| 9 | } |
| 10 | stat="" |
| 11 | if [ $# -eq 0 ]; then |
| 12 | dfcport=8100 |
| 13 | stat="all" |
| 14 | elif [ $# -eq 1 ]; then |
| 15 | dfcport=8100 |
| 16 | stat=$1 |
| 17 | elif [ $# -eq 2 ]; then |
| 18 | dfcport=$2 |
| 19 | stat=$1 |
| 20 | else |
| 21 | print_usage |
| 22 | exit 1 |
| 23 | fi |
| 24 | |
| 25 | heading=1 |
| 26 | |
| 27 | if [ $stat == "all" ]; then |
| 28 | echo "Printing stats for both JVM and DFC using port "$dfcport |
| 29 | elif [ $stat == "internal" ]; then |
| 30 | echo "Printing stats for DFC using port "$dfcport |
| 31 | elif [ $stat == "jvm" ]; then |
| 32 | echo "Printing stats for JVM using port "$dfcport |
| 33 | else |
| 34 | print_usage |
| 35 | exit 1 |
| 36 | fi |
| 37 | fileoutput="./.tmp_stats.txt" |
| 38 | |
| 39 | echo "Stats piped to file: "$fileoutput |
| 40 | |
| 41 | rm $fileoutput |
| 42 | |
| 43 | |
| 44 | |
| 45 | floatToInt() { |
| 46 | printf "%.0f\n" "$@" |
| 47 | } |
| 48 | |
| 49 | do_curl_actuator() { |
| 50 | val=$(curl -s localhost:${dfcport}/actuator/metrics/${1} | grep -o -E "\"value\":[0-9.E]+" | awk -F\: '{print $2}') |
| 51 | val=$(floatToInt $val) |
| 52 | printf "%-20s %+15s\n" $1 $val |
| 53 | if [ $heading -eq 1 ]; then |
| 54 | echo -n "," $1 >> $fileoutput |
| 55 | else |
| 56 | echo -n "," $val >> $fileoutput |
| 57 | fi |
| 58 | } |
| 59 | |
| 60 | do_curl_status() { |
| 61 | curl -s localhost:${dfcport}/status > ./.tmp_curl_res |
| 62 | cat ./.tmp_curl_res |
| 63 | while read line; do |
| 64 | len=${#line} |
| 65 | if [ $len -gt 0 ]; then |
| 66 | val=${line#*:} |
| 67 | id=${line%"$val"} |
| 68 | if [ $heading -eq 1 ]; then |
| 69 | echo -n "," $id >> $fileoutput |
| 70 | else |
| 71 | echo -n "," $val >> $fileoutput |
| 72 | fi |
| 73 | fi |
| 74 | done < ./.tmp_curl_res |
| 75 | |
| 76 | } |
| 77 | |
| 78 | |
| 79 | while [ true ]; do |
| 80 | if [ $heading -eq 1 ]; then |
| 81 | echo -n "date" >> $fileoutput |
| 82 | else |
| 83 | ds=$(date) |
| 84 | echo -n $ds >> $fileoutput |
| 85 | fi |
| 86 | if [ $stat == "all" ] || [ $stat == "jvm" ]; then |
| 87 | echo "========= DFC JVM Stats =========" |
| 88 | do_curl_actuator jvm.threads.live |
| 89 | do_curl_actuator jvm.threads.peak |
| 90 | do_curl_actuator process.files.open |
| 91 | do_curl_actuator process.files.max |
| 92 | do_curl_actuator jvm.memory.used |
| 93 | do_curl_actuator jvm.memory.max |
| 94 | fi |
| 95 | |
| 96 | if [ $stat == "all" ] || [ $stat == "internal" ]; then |
| 97 | echo "========= DFC internal Stats =========" |
| 98 | do_curl_status |
| 99 | fi |
| 100 | echo "" >> $fileoutput |
| 101 | heading=0 |
| 102 | sleep 5 |
| 103 | done |