1
0
Fork 0

Increase *_scrape_duration resolution to ms

May want to clean this up at some point.  Note that Bash doesn't have
floating point arithmetic support in `(())`.
master
Mike Gerwitz 2021-06-15 23:34:17 -04:00
parent 3142db006a
commit 0ec4219d91
Signed by: mikegerwitz
GPG Key ID: 8C917B7F5DC51BA2
2 changed files with 12 additions and 8 deletions

View File

@ -54,7 +54,7 @@ main()
local url="${1?Missing Epson ET-2720 URL}"
url="${url%%/}"
local -ri start=$(date +%s)
local -ri start=$( date +%s%3N )
# printer_ink_level
et-product-status "$url" | awk -f ink.awk | add-host "$url"
@ -62,8 +62,9 @@ main()
# printer_pages_count
et-usage-status "$url" | awk -f usage.awk | add-host "$url"
local -ri end=$(date +%s)
local -ri duration=$((end - start))
local -ri end=$( date +%s%3N )
local -ri duration_s=$(( ( end - start ) / 1000 ))
local -ri duration_ms=$(( ( end - start ) % 1000 ))
echo '# HELP printer_scrape_time_seconds Timestamp of last scrape.'
echo '# TYPE printer_scrape_time_seconds counter'
@ -71,7 +72,7 @@ main()
echo '# HELP printer_scrape_duration_seconds Number of seconds spent scraping data from web interface.'
echo '# TYPE printer_scrape_duration_seconds gauge'
echo "printer_scrape_duration_seconds $duration"
printf 'printer_scrape_duration_seconds %0.3f\n' "$duration_s.$duration_ms"
}
main "$@"

View File

@ -32,7 +32,7 @@ main()
local host="${1?Missing domain}"
local -i port="${2?Missing port}"
local -ri start=$(date +%s)
local -ri start=$( date +%s%3N )
local expire_date expire_ts=0 ok=0
expire_date=$( openssl s_client -showcerts \
@ -47,8 +47,9 @@ main()
(( ok == 1 )) && expire_ts=$( date --date="$expire_date" +%s )
local -i expire_in=$(( expire_ts - EPOCHSECONDS ))
local -ri end=$(date +%s)
local -ri duration=$(( end - start ))
local -ri end=$( date +%s%3N )
local -ri duration_s=$(( ( end - start ) / 1000 ))
local -ri duration_ms=$(( ( end - start ) % 1000 ))
# Note that this does not perform any escaping; it assumes trusted input.
local labels=$( printf 'domain="%s", port="%d"' "$host" "$port" )
@ -68,7 +69,9 @@ main()
echo -n '# HELP x509_expire_scrape_duration_seconds '
echo 'Number of seconds spent retrieving and parsing certificate expiry data.'
echo '# TYPE x509_expire_scrape_duration_seconds gauge'
printf 'x509_expire_scrape_duration_seconds{%s} %d\n' "$labels" "$duration"
printf 'x509_expire_scrape_duration_seconds{%s} %0.3f\n' \
"$labels" \
"$duration_s.$duration_ms"
}
main "$@"