Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide correct FTL stats #1619

Merged
merged 3 commits into from Jul 25, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
42 changes: 23 additions & 19 deletions advanced/Scripts/chronometer.sh
@@ -1,4 +1,5 @@
#!/usr/bin/env bash
# shellcheck disable=SC1090,SC1091
# Pi-hole: A black hole for Internet advertisements
# (c) 2017 Pi-hole, LLC (https://pi-hole.net)
# Network-wide ad blocking via your own hardware.
Expand Down Expand Up @@ -91,10 +92,10 @@ printFunc() {
printf "%s%s$spc" "$title" "$text_main"

if [[ -n "$text_addn" ]]; then
printf "%s(%s)%s\n" "$COL_NC$COL_DARK_GRAY" "$text_addn" "$COL_NC"
printf "%s(%s)%s\\n" "$COL_NC$COL_DARK_GRAY" "$text_addn" "$COL_NC"
else
# Do not print trailing newline on final line
[[ -z "$text_last" ]] && printf "%s\n" "$COL_NC"
[[ -z "$text_last" ]] && printf "%s\\n" "$COL_NC"
fi
}

Expand Down Expand Up @@ -126,7 +127,7 @@ get_init_stats() {
mins=$(( ($1%3600)/60 )); secs=$(( $1%60 ))
[[ "$day" -ge "2" ]] && plu="s"
[[ "$day" -ge "1" ]] && days="$day day${plu}, " || days=""
printf "%s%02d:%02d:%02d\n" "$days" "$hrs" "$mins" "$secs"
printf "%s%02d:%02d:%02d\\n" "$days" "$hrs" "$mins" "$secs"
}

# Set Colour Codes
Expand Down Expand Up @@ -285,6 +286,7 @@ get_sys_stats() {
sys_loadavg=$(cut -d " " -f1,2,3 /proc/loadavg)

# Get CPU usage, only counting processes over 1% as active
# shellcheck disable=SC2009
cpu_raw=$(ps -eo pcpu,rss --no-headers | grep -E -v " 0")
cpu_tasks=$(wc -l <<< "$cpu_raw")
cpu_taskact=$(sed -r "/(^ 0.)/d" <<< "$cpu_raw" | wc -l)
Expand All @@ -306,7 +308,7 @@ get_sys_stats() {
# Determine colour for temperature
if [[ -n "$temp_file" ]]; then
if [[ "$temp_unit" == "C" ]]; then
cpu_temp=$(printf "%.0fc\n" "$(calcFunc "$(< $temp_file) / 1000")")
cpu_temp=$(printf "%.0fc\\n" "$(calcFunc "$(< $temp_file) / 1000")")

case "${cpu_temp::-1}" in
-*|[0-9]|[1-3][0-9]) cpu_col="$COL_LIGHT_BLUE";;
Expand All @@ -320,7 +322,7 @@ get_sys_stats() {
cpu_temp_str=" @ $cpu_col$cpu_temp$COL_NC$COL_DARK_GRAY"

elif [[ "$temp_unit" == "F" ]]; then
cpu_temp=$(printf "%.0ff\n" "$(calcFunc "($(< $temp_file) / 1000) * 9 / 5 + 32")")
cpu_temp=$(printf "%.0ff\\n" "$(calcFunc "($(< $temp_file) / 1000) * 9 / 5 + 32")")

case "${cpu_temp::-1}" in
-*|[0-9]|[0-9][0-9]) cpu_col="$COL_LIGHT_BLUE";;
Expand All @@ -333,7 +335,7 @@ get_sys_stats() {
cpu_temp_str=" @ $cpu_col$cpu_temp$COL_NC$COL_DARK_GRAY"

else
cpu_temp_str=$(printf " @ %.0fk\n" "$(calcFunc "($(< $temp_file) / 1000) + 273.15")")
cpu_temp_str=$(printf " @ %.0fk\\n" "$(calcFunc "($(< $temp_file) / 1000) + 273.15")")
fi
else
cpu_temp_str=""
Expand Down Expand Up @@ -365,24 +367,24 @@ get_ftl_stats() {
local stats_raw

mapfile -t stats_raw < <(pihole-FTL "stats")
domains_being_blocked_raw="${stats_raw[1]#* }"
dns_queries_today_raw="${stats_raw[3]#* }"
ads_blocked_today_raw="${stats_raw[5]#* }"
ads_percentage_today_raw="${stats_raw[7]#* }"
queries_forwarded_raw="${stats_raw[11]#* }"
queries_cached_raw="${stats_raw[13]#* }"
domains_being_blocked_raw="${stats_raw[0]#* }"
dns_queries_today_raw="${stats_raw[1]#* }"
ads_blocked_today_raw="${stats_raw[2]#* }"
ads_percentage_today_raw="${stats_raw[3]#* }"
queries_forwarded_raw="${stats_raw[5]#* }"
queries_cached_raw="${stats_raw[6]#* }"

# Only retrieve these stats when not called from jsonFunc
if [[ -z "$1" ]]; then
local top_ad_raw
local top_domain_raw
local top_client_raw

domains_being_blocked=$(printf "%.0f\n" "${domains_being_blocked_raw}")
dns_queries_today=$(printf "%.0f\n" "${dns_queries_today_raw}")
ads_blocked_today=$(printf "%.0f\n" "${ads_blocked_today_raw}")
ads_percentage_today=$(printf "%'.0f\n" "${ads_percentage_today_raw}")
queries_cached_percentage=$(printf "%.0f\n" "$(calcFunc "$queries_cached_raw * 100 / ( $queries_forwarded_raw + $queries_cached_raw )")")
domains_being_blocked=$(printf "%.0f\\n" "${domains_being_blocked_raw}")
dns_queries_today=$(printf "%.0f\\n" "${dns_queries_today_raw}")
ads_blocked_today=$(printf "%.0f\\n" "${ads_blocked_today_raw}")
ads_percentage_today=$(printf "%'.0f\\n" "${ads_percentage_today_raw}")
queries_cached_percentage=$(printf "%.0f\\n" "$(calcFunc "$queries_cached_raw * 100 / ( $queries_forwarded_raw + $queries_cached_raw )")")
recent_blocked=$(pihole-FTL recentBlocked)
read -r -a top_ad_raw <<< "$(pihole-FTL "top-ads (1)")"
read -r -a top_domain_raw <<< "$(pihole-FTL "top-domains (1)")"
Expand Down Expand Up @@ -412,6 +414,8 @@ get_strings() {
used_str="Used: "
leased_str="Leased: "
domains_being_blocked=$(printf "%'.0f" "$domains_being_blocked")
ads_blocked_today=$(printf "%'.0f" "$ads_blocked_today")
dns_queries_today=$(printf "%'.0f" "$dns_queries_today")
ph_info="Blocking: $domains_being_blocked sites"
total_str="Total: "
else
Expand Down Expand Up @@ -473,8 +477,8 @@ chronoFunc() {
${COL_DARK_GRAY}$scr_line_str${COL_NC}"
else
echo -e "|¯¯¯(¯)_|¯|_ ___|¯|___$phc_ver_str
| ¯_/¯|_| ' \/ _ \ / -_)$lte_ver_str
|_| |_| |_||_\___/_\___|$ftl_ver_str
| ¯_/¯|_| ' \\/ _ \\ / -_)$lte_ver_str
|_| |_| |_||_\\___/_\\___|$ftl_ver_str
${COL_DARK_GRAY}$scr_line_str${COL_NC}"
fi

Expand Down