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
parent
3142db006a
commit
0ec4219d91
|
@ -54,7 +54,7 @@ main()
|
||||||
local url="${1?Missing Epson ET-2720 URL}"
|
local url="${1?Missing Epson ET-2720 URL}"
|
||||||
url="${url%%/}"
|
url="${url%%/}"
|
||||||
|
|
||||||
local -ri start=$(date +%s)
|
local -ri start=$( date +%s%3N )
|
||||||
|
|
||||||
# printer_ink_level
|
# printer_ink_level
|
||||||
et-product-status "$url" | awk -f ink.awk | add-host "$url"
|
et-product-status "$url" | awk -f ink.awk | add-host "$url"
|
||||||
|
@ -62,8 +62,9 @@ main()
|
||||||
# printer_pages_count
|
# printer_pages_count
|
||||||
et-usage-status "$url" | awk -f usage.awk | add-host "$url"
|
et-usage-status "$url" | awk -f usage.awk | add-host "$url"
|
||||||
|
|
||||||
local -ri end=$(date +%s)
|
local -ri end=$( date +%s%3N )
|
||||||
local -ri duration=$((end - start))
|
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 '# HELP printer_scrape_time_seconds Timestamp of last scrape.'
|
||||||
echo '# TYPE printer_scrape_time_seconds counter'
|
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 '# HELP printer_scrape_duration_seconds Number of seconds spent scraping data from web interface.'
|
||||||
echo '# TYPE printer_scrape_duration_seconds gauge'
|
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 "$@"
|
main "$@"
|
||||||
|
|
|
@ -32,7 +32,7 @@ main()
|
||||||
local host="${1?Missing domain}"
|
local host="${1?Missing domain}"
|
||||||
local -i port="${2?Missing port}"
|
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
|
local expire_date expire_ts=0 ok=0
|
||||||
expire_date=$( openssl s_client -showcerts \
|
expire_date=$( openssl s_client -showcerts \
|
||||||
|
@ -47,8 +47,9 @@ main()
|
||||||
(( ok == 1 )) && expire_ts=$( date --date="$expire_date" +%s )
|
(( ok == 1 )) && expire_ts=$( date --date="$expire_date" +%s )
|
||||||
local -i expire_in=$(( expire_ts - EPOCHSECONDS ))
|
local -i expire_in=$(( expire_ts - EPOCHSECONDS ))
|
||||||
|
|
||||||
local -ri end=$(date +%s)
|
local -ri end=$( date +%s%3N )
|
||||||
local -ri duration=$(( end - start ))
|
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.
|
# Note that this does not perform any escaping; it assumes trusted input.
|
||||||
local labels=$( printf 'domain="%s", port="%d"' "$host" "$port" )
|
local labels=$( printf 'domain="%s", port="%d"' "$host" "$port" )
|
||||||
|
@ -68,7 +69,9 @@ main()
|
||||||
echo -n '# HELP x509_expire_scrape_duration_seconds '
|
echo -n '# HELP x509_expire_scrape_duration_seconds '
|
||||||
echo 'Number of seconds spent retrieving and parsing certificate expiry data.'
|
echo 'Number of seconds spent retrieving and parsing certificate expiry data.'
|
||||||
echo '# TYPE x509_expire_scrape_duration_seconds gauge'
|
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 "$@"
|
main "$@"
|
||||||
|
|
Loading…
Reference in New Issue