Mike Gerwitz

Activist for User Freedom

aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMike Gerwitz <mtg@gnu.org>2021-06-15 23:34:17 -0400
committerMike Gerwitz <mtg@gnu.org>2021-06-15 23:48:12 -0400
commit0ec4219d9102a4f51f89b503b7c75729f22cadc9 (patch)
tree921b9cc81a6c083092cb40acf6cb4369bc8f0758
parent3142db006a3cdf6b7a95eb94f7428e5f4cd5fbd5 (diff)
downloadpromscripts-0ec4219d9102a4f51f89b503b7c75729f22cadc9.tar.gz
promscripts-0ec4219d9102a4f51f89b503b7c75729f22cadc9.tar.bz2
promscripts-0ec4219d9102a4f51f89b503b7c75729f22cadc9.zip
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 `(())`.
-rwxr-xr-xprinter/epson/et-2720/metrics9
-rwxr-xr-xx509/expiry/metrics11
2 files changed, 12 insertions, 8 deletions
diff --git a/printer/epson/et-2720/metrics b/printer/epson/et-2720/metrics
index 1d74166..58bf807 100755
--- a/printer/epson/et-2720/metrics
+++ b/printer/epson/et-2720/metrics
@@ -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 "$@"
diff --git a/x509/expiry/metrics b/x509/expiry/metrics
index 5119e44..2f4f45c 100755
--- a/x509/expiry/metrics
+++ b/x509/expiry/metrics
@@ -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 "$@"