blob: e0d7c33b761d45653814aa816c6c7e427ac3c435 [file] [log] [blame]
BjornMagnussonXAa79a0432019-07-17 08:26:50 +00001#!/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
7print_usage() {
8 echo "Useage: ./dfc-internal-stats.sh all|internal|jvm [<dfc-port-number>]"
9}
10stat=""
11if [ $# -eq 0 ]; then
12 dfcport=8100
13 stat="all"
14elif [ $# -eq 1 ]; then
15 dfcport=8100
16 stat=$1
17elif [ $# -eq 2 ]; then
18 dfcport=$2
19 stat=$1
20else
21 print_usage
22 exit 1
23fi
24
25heading=1
26
27if [ $stat == "all" ]; then
28 echo "Printing stats for both JVM and DFC using port "$dfcport
29elif [ $stat == "internal" ]; then
30 echo "Printing stats for DFC using port "$dfcport
31elif [ $stat == "jvm" ]; then
32 echo "Printing stats for JVM using port "$dfcport
33else
34 print_usage
35 exit 1
36fi
maximesson69311bf2019-08-30 14:05:15 +000037fileoutput=".tmp_stats.txt"
BjornMagnussonXAa79a0432019-07-17 08:26:50 +000038
39echo "Stats piped to file: "$fileoutput
40
41rm $fileoutput
42
43
44
45floatToInt() {
46 printf "%.0f\n" "$@"
47}
48
49do_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
60do_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
maximesson69311bf2019-08-30 14:05:15 +000078OK=0 # Flag for DFC response (0==no response, 1==reponse ok and logging can start)
BjornMagnussonXAa79a0432019-07-17 08:26:50 +000079
80while [ true ]; do
maximesson69311bf2019-08-30 14:05:15 +000081 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
BjornMagnussonXAa79a0432019-07-17 08:26:50 +0000106
maximesson69311bf2019-08-30 14:05:15 +0000107 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
BjornMagnussonXAa79a0432019-07-17 08:26:50 +0000114 sleep 5
115done