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 |
maximesson | 69311bf | 2019-08-30 14:05:15 +0000 | [diff] [blame] | 37 | fileoutput=".tmp_stats.txt" |
BjornMagnussonXA | a79a043 | 2019-07-17 08:26:50 +0000 | [diff] [blame] | 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 | |
maximesson | 69311bf | 2019-08-30 14:05:15 +0000 | [diff] [blame] | 78 | OK=0 # Flag for DFC response (0==no response, 1==reponse ok and logging can start) |
BjornMagnussonXA | a79a043 | 2019-07-17 08:26:50 +0000 | [diff] [blame] | 79 | |
| 80 | while [ true ]; do |
maximesson | 69311bf | 2019-08-30 14:05:15 +0000 | [diff] [blame] | 81 | if [ $OK -eq 0 ]; then |
| 82 | test=$(curl -s localhost:${dfcport}/status) |
| 83 | if [ -z "$test" ] && [ $heading -eq 1 ]; then |
| 84 | echo "No response from dfc on port: ${dfcport}. Retrying..." |
| 85 | else |
| 86 | echo "Response from dfc on port: ${dfcport}. Starts logging." |
| 87 | OK=1 |
| 88 | fi |
| 89 | fi |
| 90 | if [ $OK -eq 1 ]; then |
| 91 | if [ $heading -eq 1 ]; then |
| 92 | echo -n "date" >> $fileoutput |
| 93 | else |
| 94 | ds=$(date) |
| 95 | echo -n $ds >> $fileoutput |
| 96 | fi |
| 97 | if [ $stat == "all" ] || [ $stat == "jvm" ]; then |
| 98 | echo "========= DFC JVM Stats =========" |
| 99 | do_curl_actuator jvm.threads.live |
| 100 | do_curl_actuator jvm.threads.peak |
| 101 | do_curl_actuator process.files.open |
| 102 | do_curl_actuator process.files.max |
| 103 | do_curl_actuator jvm.memory.used |
| 104 | do_curl_actuator jvm.memory.max |
| 105 | fi |
BjornMagnussonXA | a79a043 | 2019-07-17 08:26:50 +0000 | [diff] [blame] | 106 | |
maximesson | 69311bf | 2019-08-30 14:05:15 +0000 | [diff] [blame] | 107 | if [ $stat == "all" ] || [ $stat == "internal" ]; then |
| 108 | echo "========= DFC internal Stats =========" |
| 109 | do_curl_status |
| 110 | fi |
| 111 | echo "" >> $fileoutput |
| 112 | heading=0 |
| 113 | fi |
BjornMagnussonXA | a79a043 | 2019-07-17 08:26:50 +0000 | [diff] [blame] | 114 | sleep 5 |
| 115 | done |