Mike Gerwitz

Activist for User Freedom

aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMike Gerwitz <mtg@gnu.org>2021-06-24 21:52:32 -0400
committerMike Gerwitz <mtg@gnu.org>2021-06-24 21:53:14 -0400
commit16108f0c2e7daeb006df0610ec189c58955d1bb8 (patch)
tree0e88b4e150585109a0c76117a4f3d9ef908eebe9
parent0ec4219d9102a4f51f89b503b7c75729f22cadc9 (diff)
downloadpromscripts-16108f0c2e7daeb006df0610ec189c58955d1bb8.tar.gz
promscripts-16108f0c2e7daeb006df0610ec189c58955d1bb8.tar.bz2
promscripts-16108f0c2e7daeb006df0610ec189c58955d1bb8.zip
printer/epson/et-2720/metrics: Add serial numberHEADmaster
Distinguish between two printers of the same model without having to rely on URL, which can change over time.
-rwxr-xr-xprinter/epson/et-2720/metrics32
1 files changed, 23 insertions, 9 deletions
diff --git a/printer/epson/et-2720/metrics b/printer/epson/et-2720/metrics
index 58bf807..b9a96f6 100755
--- a/printer/epson/et-2720/metrics
+++ b/printer/epson/et-2720/metrics
@@ -38,14 +38,27 @@ et-usage-status()
}
-# Add host and URL to metric.
+# Printer serial number.
+et-serial()
+{
+ local -r url="${1?Missing URL}"
+
+ et-product-status "$url" \
+ | grep -oP 'Serial Number.*?</div>' \
+ | awk -F'[<>]' '{print $9}'
+}
+
+
+# Add URL and serial number to metric.
#
# WARNING: This does _not_ sanitize the URL; do not include double quotes.
-add-host()
+add-labels()
{
local -r url="${1?Missing URL}"
+ local -r serial="${2?Missing serial number}"
- sed 's|}|, url="'"$url"'", model="ET-2720"}|; s/{, /{/'
+ sed 's|}|, url="'"$url"'", serial="'"$serial"'", model="ET-2720"}|;
+ s/{, /{/'
}
@@ -56,11 +69,10 @@ main()
local -ri start=$( date +%s%3N )
- # printer_ink_level
- et-product-status "$url" | awk -f ink.awk | add-host "$url"
+ local -r serial=$( et-serial "$url" )
- # printer_pages_count
- et-usage-status "$url" | awk -f usage.awk | add-host "$url"
+ et-product-status "$url" | awk -f ink.awk | add-labels "$url" "$serial"
+ et-usage-status "$url" | awk -f usage.awk | add-labels "$url" "$serial"
local -ri end=$( date +%s%3N )
local -ri duration_s=$(( ( end - start ) / 1000 ))
@@ -68,11 +80,13 @@ main()
echo '# HELP printer_scrape_time_seconds Timestamp of last scrape.'
echo '# TYPE printer_scrape_time_seconds counter'
- echo "printer_scrape_time_seconds $(date +%s)"
+ echo "printer_scrape_time_seconds{} $(date +%s)" | add-labels "$url" "$serial"
echo '# HELP printer_scrape_duration_seconds Number of seconds spent scraping data from web interface.'
echo '# TYPE printer_scrape_duration_seconds gauge'
- printf 'printer_scrape_duration_seconds %0.3f\n' "$duration_s.$duration_ms"
+ printf 'printer_scrape_duration_seconds{} %0.3f\n' \
+ "$duration_s.$duration_ms" \
+ | add-labels "$url" "$serial"
}
main "$@"