From 535473faa3311e2f749059a059b3f66f252b6103 Mon Sep 17 00:00:00 2001 From: Tim Buckley Date: Sat, 27 Feb 2021 16:25:28 -0700 Subject: [PATCH] Fully working exporter and binary release prep Also: * fixed an accidental spin-wait in `wait_for_not_ready_timeout` * updated dependencies, including tokio to v1.2 * various API improvements to custom unit value types * README improvements --- Cargo.lock | 771 ++++++++++++++++------------------- Cargo.toml | 10 +- README.md | 287 +++++++++++++ metriful-exporter.service | 1 - src/bin/metriful_exporter.rs | 233 ++++++++++- src/bin/metriful_tool.rs | 32 +- src/lib.rs | 2 + src/unit.rs | 33 +- 8 files changed, 931 insertions(+), 438 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 0e32804..ee0f641 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,18 +2,18 @@ # It is not intended for manual editing. [[package]] name = "addr2line" -version = "0.14.0" +version = "0.14.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7c0929d69e78dd9bf5408269919fcbcaeb2e35e5d43e5815517cdc6a8e11a423" +checksum = "a55f82cfe485775d02112886f4169bde0c5894d75e79ead7eafe7e40a25e45f7" dependencies = [ "gimli", ] [[package]] name = "adler" -version = "0.2.3" +version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee2a4ec343196209d6594e19543ae87a39f96d5534d7174822a3ad825dd6ed7e" +checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" [[package]] name = "aho-corasick" @@ -30,7 +30,7 @@ version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b" dependencies = [ - "winapi 0.3.9", + "winapi", ] [[package]] @@ -41,15 +41,9 @@ checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" dependencies = [ "hermit-abi", "libc", - "winapi 0.3.9", + "winapi", ] -[[package]] -name = "autocfg" -version = "0.1.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d49d90015b3c36167a20fe2810c5cd875ad504b39cff3d4eae7977e6b7c1cb2" - [[package]] name = "autocfg" version = "1.0.1" @@ -58,9 +52,9 @@ checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a" [[package]] name = "backtrace" -version = "0.3.55" +version = "0.3.56" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ef5140344c85b01f9bbb4d4b7288a8aa4b3287ccef913a14bcc78a1063623598" +checksum = "9d117600f438b1707d4e4ae15d3595657288f8235a0eb593e80ecc98ab34e1bc" dependencies = [ "addr2line", "cfg-if 1.0.0", @@ -72,9 +66,9 @@ dependencies = [ [[package]] name = "base64" -version = "0.12.3" +version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3441f0f7b02788e948e47f457ca01f1d7e6d92c693bc132c22b087d3141c03ff" +checksum = "904dfeac50f3cdaba28fc6f57fdcddb75f49ed61346676a78c4ffe55877802fd" [[package]] name = "bitflags" @@ -130,9 +124,9 @@ checksum = "e3b5ca7a04898ad4bcd41c90c5285445ff5b791899bb1b0abdd2a2aa791211d7" [[package]] name = "byteorder" -version = "1.3.4" +version = "1.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "08c48aae112d48ed9f069b33538ea9e3e90aa263cfa3d1c24309612b1f7472de" +checksum = "ae44d1a3d5a19df61dd0c8beb138458ac2a53a7ac09eba97d55592540004306b" [[package]] name = "bytes" @@ -140,11 +134,17 @@ version = "0.5.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0e4cec68f03f32e44924783795810fa50a7035d8c8ebe78580ad7e6c703fba38" +[[package]] +name = "bytes" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b700ce4376041dcd0a327fd0097c41095743c4c8af8887265942faf1100bd040" + [[package]] name = "cc" -version = "1.0.60" +version = "1.0.67" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ef611cc68ff783f18535d77ddd080185275713d852c4f5cbb6122c462a7a825c" +checksum = "e3c69b077ad434294d3ce9f1f6143a2a4b89a8a2d54ef813d85003a4fd1137fd" [[package]] name = "cfg-if" @@ -160,15 +160,15 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "chrono" -version = "0.4.18" +version = "0.4.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d021fddb7bd3e734370acfa4a83f34095571d8570c039f1420d77540f68d5772" +checksum = "670ad68c9088c2a963aaa298cb369688cf3f9465ce5e2d4ca10e6e0098a1ce73" dependencies = [ "libc", "num-integer", "num-traits", "time", - "winapi 0.3.9", + "winapi", ] [[package]] @@ -186,20 +186,11 @@ dependencies = [ "vec_map", ] -[[package]] -name = "cloudabi" -version = "0.0.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f" -dependencies = [ - "bitflags", -] - [[package]] name = "color-eyre" -version = "0.5.9" +version = "0.5.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4cd93ec975c58d2e669fcfd09bcbb38a9ea4a182dd612e0855a3503b825e393b" +checksum = "7b29030875fd8376e4a28ef497790d5b4a7843d8d1396bf08ce46f5eec562c5c" dependencies = [ "backtrace", "eyre", @@ -232,12 +223,6 @@ dependencies = [ "generic-array 0.14.4", ] -[[package]] -name = "dtoa" -version = "0.4.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "134951f4028bdadb9b84baf4232681efbf277da25144b9b0ad65df75946c422b" - [[package]] name = "env_logger" version = "0.7.1" @@ -267,9 +252,9 @@ dependencies = [ [[package]] name = "eyre" -version = "0.6.3" +version = "0.6.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5f29abf4740a4778632fe27a4f681ef5b7a6f659aeba3330ac66f48e20cfa3b7" +checksum = "221239d1d5ea86bf5d6f91c9d6bc3646ffe471b08ff9b0f91c44f115ac969d2b" dependencies = [ "indenter", "once_cell", @@ -288,32 +273,20 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" [[package]] -name = "fuchsia-cprng" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba" - -[[package]] -name = "fuchsia-zircon" -version = "0.3.3" +name = "form_urlencoded" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2e9763c69ebaae630ba35f74888db465e49e259ba1bc0eda7d06f4a067615d82" +checksum = "5fc25a87fa4fd2094bffb06925852034d90a17f0d1e05197d4956d3555752191" dependencies = [ - "bitflags", - "fuchsia-zircon-sys", + "matches", + "percent-encoding", ] -[[package]] -name = "fuchsia-zircon-sys" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7" - [[package]] name = "futures" -version = "0.3.5" +version = "0.3.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e05b85ec287aac0dc34db7d4a569323df697f9c55b99b15d6b4ef8cde49f613" +checksum = "7f55667319111d593ba876406af7c409c0ebb44dc4be6132a783ccf163ea14c1" dependencies = [ "futures-channel", "futures-core", @@ -325,9 +298,9 @@ dependencies = [ [[package]] name = "futures-channel" -version = "0.3.5" +version = "0.3.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f366ad74c28cca6ba456d95e6422883cfb4b252a83bed929c83abfdbbf2967d5" +checksum = "8c2dd2df839b57db9ab69c2c9d8f3e8c81984781937fe2807dc6dcf3b2ad2939" dependencies = [ "futures-core", "futures-sink", @@ -335,41 +308,38 @@ dependencies = [ [[package]] name = "futures-core" -version = "0.3.5" +version = "0.3.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "59f5fff90fd5d971f936ad674802482ba441b6f09ba5e15fd8b39145582ca399" +checksum = "15496a72fabf0e62bdc3df11a59a3787429221dd0710ba8ef163d6f7a9112c94" [[package]] name = "futures-io" -version = "0.3.5" +version = "0.3.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "de27142b013a8e869c14957e6d2edeef89e97c289e69d042ee3a49acd8b51789" +checksum = "d71c2c65c57704c32f5241c1223167c2c3294fd34ac020c807ddbe6db287ba59" [[package]] name = "futures-sink" -version = "0.3.5" +version = "0.3.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f2032893cb734c7a05d85ce0cc8b8c4075278e93b24b66f9de99d6eb0fa8acc" +checksum = "85754d98985841b7d4f5e8e6fbfa4a4ac847916893ec511a2917ccd8525b8bb3" [[package]] name = "futures-task" -version = "0.3.5" +version = "0.3.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bdb66b5f09e22019b1ab0830f7785bcea8e7a42148683f99214f73f8ec21a626" -dependencies = [ - "once_cell", -] +checksum = "fa189ef211c15ee602667a6fcfe1c1fd9e07d42250d2156382820fba33c9df80" [[package]] name = "futures-util" -version = "0.3.5" +version = "0.3.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8764574ff08b701a084482c3c7031349104b07ac897393010494beaa18ce32c6" +checksum = "1812c7ab8aedf8d6f2701a43e1243acdbcc2b36ab26e2ad421eb99ac963d96d1" dependencies = [ "futures-core", "futures-sink", "futures-task", - "pin-project", + "pin-project-lite", "pin-utils", "slab", ] @@ -395,15 +365,26 @@ dependencies = [ [[package]] name = "getrandom" -version = "0.1.15" +version = "0.1.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fc587bc0ec293155d5bfa6b9891ec18a1e330c234f896ea47fbada4cadbe47e6" +checksum = "8fc3cb4d91f53b50155bdcfd23f6a4c39ae1969c2ae85982b135750cccaf5fce" dependencies = [ - "cfg-if 0.1.10", + "cfg-if 1.0.0", "libc", "wasi 0.9.0+wasi-snapshot-preview1", ] +[[package]] +name = "getrandom" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c9495705279e7140bf035dde1f6e750c162df8b625267cd52cc44e0b156732c8" +dependencies = [ + "cfg-if 1.0.0", + "libc", + "wasi 0.10.2+wasi-snapshot-preview1", +] + [[package]] name = "gimli" version = "0.23.0" @@ -412,11 +393,11 @@ checksum = "f6503fe142514ca4799d4c26297c4248239fe8838d827db6bd6065c6ed29a6ce" [[package]] name = "h2" -version = "0.2.6" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "993f9e0baeed60001cf565546b0d3dbe6a6ad23f2bd31644a133c641eccf6d53" +checksum = "d832b01df74254fe364568d6ddc294443f61cbec82816b60904303af87efae78" dependencies = [ - "bytes", + "bytes 1.0.1", "fnv", "futures-core", "futures-sink", @@ -437,13 +418,13 @@ checksum = "d7afe4a420e3fe79967a00898cc1f4db7c8a49a9333a29f8a4bd76a253d5cd04" [[package]] name = "headers" -version = "0.3.2" +version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed18eb2459bf1a09ad2d6b1547840c3e5e62882fa09b9a6a20b1de8e3228848f" +checksum = "62689dc57c7456e69712607ffcbd0aa1dfcccf9af73727e9b25bc1825375cac3" dependencies = [ "base64", "bitflags", - "bytes", + "bytes 1.0.1", "headers-core", "http", "mime", @@ -462,48 +443,48 @@ dependencies = [ [[package]] name = "heck" -version = "0.3.1" +version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "20564e78d53d2bb135c343b3f47714a56af2061f1c928fdb541dc7b9fdd94205" +checksum = "87cbf45460356b7deeb5e3415b5563308c0a9b057c85e12b06ad551f98d0a6ac" dependencies = [ "unicode-segmentation", ] [[package]] name = "hermit-abi" -version = "0.1.16" +version = "0.1.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c30f6d0bc6b00693347368a67d41b58f2fb851215ff1da49e90fe2c5c667151" +checksum = "322f4de77956e22ed0e5032c359a0f1273f1f7f0d79bfa3b8ffbc730d7fbcc5c" dependencies = [ "libc", ] [[package]] name = "http" -version = "0.2.1" +version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "28d569972648b2c512421b5f2a405ad6ac9666547189d0c5477a3f200f3e02f9" +checksum = "7245cd7449cc792608c3c8a9eaf69bd4eabbabf802713748fd739c98b82f0747" dependencies = [ - "bytes", + "bytes 1.0.1", "fnv", "itoa", ] [[package]] name = "http-body" -version = "0.3.1" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "13d5ff830006f7646652e057693569bfe0d51760c0085a071769d142a205111b" +checksum = "2861bd27ee074e5ee891e8b539837a9430012e249d7f0ca2d795650f579c1994" dependencies = [ - "bytes", + "bytes 1.0.1", "http", ] [[package]] name = "httparse" -version = "1.3.4" +version = "1.3.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cd179ae861f0c2e53da70d892f5f3029f9594be0c41dc5269cd371691b1dc2f9" +checksum = "615caabe2c3160b313d52ccc905335f4ed5f10881dd63dc5699d47e90be85691" [[package]] name = "httpdate" @@ -522,11 +503,11 @@ dependencies = [ [[package]] name = "hyper" -version = "0.13.8" +version = "0.14.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2f3afcfae8af5ad0576a31e768415edb627824129e8e5a29b8bfccb2f234e835" +checksum = "e8e946c2b1349055e0b72ae281b238baf1a3ea7307c7e9f9d64673bdd9c26ac7" dependencies = [ - "bytes", + "bytes 1.0.1", "futures-channel", "futures-core", "futures-util", @@ -558,9 +539,9 @@ dependencies = [ [[package]] name = "idna" -version = "0.2.0" +version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "02e2673c30ee86b5b96a9cb52ad15718aa1f966f5ab9ad54a8b95d5ca33120a9" +checksum = "89829a5d69c23d348314a7ac337fe39173b61149a9864deabd260983aed48c21" dependencies = [ "matches", "unicode-bidi", @@ -569,53 +550,43 @@ dependencies = [ [[package]] name = "indenter" -version = "0.3.0" +version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e0bd112d44d9d870a6819eb505d04dd92b5e4d94bb8c304924a0872ae7016fb5" +checksum = "ce23b50ad8242c51a442f3ff322d56b02f08852c77e4c0b4d3fd684abc89c683" [[package]] name = "indexmap" -version = "1.6.0" +version = "1.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "55e2e4c765aa53a0424761bf9f41aa7a6ac1efa87238f59560640e27fca028f2" +checksum = "4fb1fa934250de4de8aef298d81c729a7d33d8c239daa3a7575e6b92bfc7313b" dependencies = [ - "autocfg 1.0.1", + "autocfg", "hashbrown", ] [[package]] name = "input_buffer" -version = "0.3.1" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19a8a95243d5a0398cae618ec29477c6e3cb631152be5c19481f80bc71559754" +checksum = "f97967975f448f1a7ddb12b0bc41069d09ed6a1c161a92687e057325db35d413" dependencies = [ - "bytes", + "bytes 1.0.1", ] [[package]] -name = "iovec" -version = "0.1.4" +name = "instant" +version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b2b3ea6ff95e175473f8ffe6a7eb7c00d054240321b84c57051175fe3c1e075e" +checksum = "61124eeebbd69b8190558df225adf7e4caafce0d743919e5d6b19652314ec5ec" dependencies = [ - "libc", + "cfg-if 1.0.0", ] [[package]] name = "itoa" -version = "0.4.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc6f3ad7b9d11a0c00842ff8de1b60ee58661048eb8049ed33c73594f359d7e6" - -[[package]] -name = "kernel32-sys" -version = "0.2.2" +version = "0.4.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d" -dependencies = [ - "winapi 0.2.8", - "winapi-build", -] +checksum = "dd25036021b0de88a0aff6b850051563c6516d0bf53f8638938edbb9de732736" [[package]] name = "lazy_static" @@ -625,17 +596,26 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "libc" -version = "0.2.77" +version = "0.2.86" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f2f96b10ec2560088a8e76961b00d47107b3a625fecb76dedb29ee7ccbf98235" +checksum = "b7282d924be3275cec7f6756ff4121987bc6481325397dde6ba3e7802b1a8b1c" + +[[package]] +name = "lock_api" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dd96ffd135b2fd7b973ac026d28085defbe8983df057ced3eb4f2130b0831312" +dependencies = [ + "scopeguard", +] [[package]] name = "log" -version = "0.4.11" +version = "0.4.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4fabed175da42fed1fa0746b0ea71f412aa9d35e76e95e59b192c64b9dc2bf8b" +checksum = "51b9bbe6c47d51fc3e1a9b945965946b4c44142ab8792c50835a980d362c2710" dependencies = [ - "cfg-if 0.1.10", + "cfg-if 1.0.0", ] [[package]] @@ -646,15 +626,15 @@ checksum = "7ffc5c5338469d4d3ea17d269fa8ea3512ad247247c30bd2df69e68309ed0a08" [[package]] name = "memchr" -version = "2.3.3" +version = "2.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3728d817d99e5ac407411fa471ff9800a778d88a24685968b36824eaf4bee400" +checksum = "0ee1c47aaa256ecabcaea351eae4a9b01ef39ed810004e298d2511ed284b1525" [[package]] name = "metriful" version = "0.1.0" dependencies = [ - "bytes", + "bytes 0.5.6", "chrono", "color-eyre", "env_logger", @@ -667,8 +647,9 @@ dependencies = [ "simple-prometheus-exporter", "structopt", "sysfs_gpio", - "textwrap 0.13.0", + "textwrap 0.13.4", "tokio", + "tokio-stream", "warp", ] @@ -690,50 +671,42 @@ dependencies = [ [[package]] name = "miniz_oxide" -version = "0.4.3" +version = "0.4.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f2d26ec3309788e423cfbf68ad1800f061638098d76a83681af979dc4eda19d" +checksum = "a92518e98c078586bc6c934028adcca4c92a53d6a958196de835170a01d84e4b" dependencies = [ "adler", - "autocfg 1.0.1", + "autocfg", ] [[package]] name = "mio" -version = "0.6.22" +version = "0.7.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fce347092656428bc8eaf6201042cb551b8d67855af7374542a92a0fbfcac430" +checksum = "a5dede4e2065b3842b8b0af444119f3aa331cc7cc2dd20388bfb0f5d5a38823a" dependencies = [ - "cfg-if 0.1.10", - "fuchsia-zircon", - "fuchsia-zircon-sys", - "iovec", - "kernel32-sys", "libc", "log", "miow", - "net2", - "slab", - "winapi 0.2.8", + "ntapi", + "winapi", ] [[package]] name = "miow" -version = "0.2.1" +version = "0.3.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8c1f2f3b1cf331de6896aabf6e9d55dca90356cc9960cca7eaaf408a355ae919" +checksum = "5a33c1b55807fbed163481b5ba66db4b2fa6cde694a5027be10fb724206c5897" dependencies = [ - "kernel32-sys", - "net2", - "winapi 0.2.8", - "ws2_32-sys", + "socket2", + "winapi", ] [[package]] name = "multipart" -version = "0.17.0" +version = "0.17.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8209c33c951f07387a8497841122fc6f712165e3f9bda3e6be4645b58188f676" +checksum = "d050aeedc89243f5347c3e237e3e13dc76fbe4ae3742a57b94dc14f69acf76d4" dependencies = [ "buf_redux", "httparse", @@ -741,23 +714,12 @@ dependencies = [ "mime", "mime_guess", "quick-error", - "rand 0.6.5", + "rand 0.7.3", "safemem", "tempfile", "twoway", ] -[[package]] -name = "net2" -version = "0.2.35" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3ebc3ec692ed7c9a255596c67808dee269f64655d8baf7b4f0638e51ba1d6853" -dependencies = [ - "cfg-if 0.1.10", - "libc", - "winapi 0.3.9", -] - [[package]] name = "nix" version = "0.14.1" @@ -771,36 +733,55 @@ dependencies = [ "void", ] +[[package]] +name = "ntapi" +version = "0.3.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f6bb902e437b6d86e03cce10a7e2af662292c5dfef23b65899ea3ac9354ad44" +dependencies = [ + "winapi", +] + [[package]] name = "num-integer" -version = "0.1.43" +version = "0.1.44" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8d59457e662d541ba17869cf51cf177c0b5f0cbf476c66bdc90bf1edac4f875b" +checksum = "d2cc698a63b549a70bc047073d2949cce27cd1c7b0a4a862d08a8031bc2801db" dependencies = [ - "autocfg 1.0.1", + "autocfg", "num-traits", ] [[package]] name = "num-traits" -version = "0.2.12" +version = "0.2.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac267bcc07f48ee5f8935ab0d24f316fb722d7a1292e2913f0cc196b29ffd611" +checksum = "9a64b1ec5cda2586e284722486d802acf1f7dbdc623e2bfc57e65ca1cd099290" dependencies = [ - "autocfg 1.0.1", + "autocfg", +] + +[[package]] +name = "num_cpus" +version = "1.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05499f3756671c15885fee9034446956fff3f243d6077b91e5767df161f766b3" +dependencies = [ + "hermit-abi", + "libc", ] [[package]] name = "object" -version = "0.22.0" +version = "0.23.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8d3b63360ec3cb337817c2dbd47ab4a0f170d285d8e5a2064600f3def1402397" +checksum = "a9a7ab5d64814df0fe4a4b5ead45ed6c5f181ee3ff04ba344313a6c80446c5d4" [[package]] name = "once_cell" -version = "1.4.1" +version = "1.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "260e51e7efe62b592207e9e13a68e43692a7a279171d6ba57abd208bf23645ad" +checksum = "10acf907b94fc1b1a152d08ef97e7759650268cf986bf127f387e602b02c7e5a" [[package]] name = "opaque-debug" @@ -816,9 +797,34 @@ checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" [[package]] name = "owo-colors" -version = "1.2.0" +version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "25ac891a7415905f6cc1b61909772d1a975c0281da8b455f269daa0b6e56f9cb" +checksum = "2386b4ebe91c2f7f51082d4cefa145d030e33a1842a96b12e4885cc3c01f7a55" + +[[package]] +name = "parking_lot" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6d7744ac029df22dca6284efe4e898991d28e3085c706c972bcd7da4a27a15eb" +dependencies = [ + "instant", + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa7a782938e745763fe6907fc6ba86946d72f49fe7e21de074e08128a99fb018" +dependencies = [ + "cfg-if 1.0.0", + "instant", + "libc", + "redox_syscall", + "smallvec", + "winapi", +] [[package]] name = "percent-encoding" @@ -828,18 +834,18 @@ checksum = "d4fd5641d01c8f18a23da7b6fe29298ff4b55afcccdf78973b24cf3175fee32e" [[package]] name = "pin-project" -version = "0.4.24" +version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f48fad7cfbff853437be7cf54d7b993af21f53be7f0988cbfe4a51535aa77205" +checksum = "96fa8ebb90271c4477f144354485b8068bd8f6b78b428b01ba892ca26caf0b63" dependencies = [ "pin-project-internal", ] [[package]] name = "pin-project-internal" -version = "0.4.24" +version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "24c6d293bdd3ca5a1697997854c6cf7855e43fb6a0ba1c47af57a5bcafd158ae" +checksum = "758669ae3558c6f74bd2a18b41f7ac0b5a195aea6639d6a9b5e5d1ad5ba24c0b" dependencies = [ "proc-macro2", "quote", @@ -848,9 +854,9 @@ dependencies = [ [[package]] name = "pin-project-lite" -version = "0.1.9" +version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4fe74897791e156a0cd8cce0db31b9b2198e67877316bf3086c3acd187f719f0" +checksum = "439697af366c49a6d0a010c56a0d97685bc140ce0d377b13a2ea2aa42d64a827" [[package]] name = "pin-utils" @@ -860,9 +866,9 @@ checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" [[package]] name = "ppv-lite86" -version = "0.2.9" +version = "0.2.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c36fa947111f5c62a733b652544dd0016a43ce89619538a8ef92724a6f501a20" +checksum = "ac74c624d6b2d21f425f752262f42188365d7b8ff1aff74c82e45136510a4857" [[package]] name = "proc-macro-error" @@ -890,9 +896,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.23" +version = "1.0.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "51ef7cd2518ead700af67bf9d1a658d90b6037d77110fd9c0445429d0ba1c6c9" +checksum = "1e0704ee1a7e00d7bb417d0770ea303c1bccbabf0ef1667dae92b5967f5f8a71" dependencies = [ "unicode-xid", ] @@ -905,39 +911,20 @@ checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0" [[package]] name = "quote" -version = "1.0.7" +version = "1.0.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aa563d17ecb180e500da1cfd2b028310ac758de548efdd203e18f283af693f37" +checksum = "c3d0b9745dc2debf507c8422de05d7226cc1f0644216dfdfead988f9b1ab32a7" dependencies = [ "proc-macro2", ] -[[package]] -name = "rand" -version = "0.6.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6d71dacdc3c88c1fde3885a3be3fbab9f35724e6ce99467f7d9c5026132184ca" -dependencies = [ - "autocfg 0.1.7", - "libc", - "rand_chacha 0.1.1", - "rand_core 0.4.2", - "rand_hc 0.1.0", - "rand_isaac", - "rand_jitter", - "rand_os", - "rand_pcg", - "rand_xorshift", - "winapi 0.3.9", -] - [[package]] name = "rand" version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6a6b1679d49b24bbfe0c803429aa1874472f50d9b363131f0e89fc356b544d03" dependencies = [ - "getrandom", + "getrandom 0.1.16", "libc", "rand_chacha 0.2.2", "rand_core 0.5.1", @@ -945,13 +932,15 @@ dependencies = [ ] [[package]] -name = "rand_chacha" -version = "0.1.1" +name = "rand" +version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "556d3a1ca6600bfcbab7c7c91ccb085ac7fbbcd70e008a98742e7847f4f7bcef" +checksum = "0ef9e7e66b4468674bfcb0c81af8b7fa0bb154fa9f28eb840da5c447baeb8d7e" dependencies = [ - "autocfg 0.1.7", - "rand_core 0.3.1", + "libc", + "rand_chacha 0.3.0", + "rand_core 0.6.2", + "rand_hc 0.3.0", ] [[package]] @@ -965,36 +954,31 @@ dependencies = [ ] [[package]] -name = "rand_core" -version = "0.3.1" +name = "rand_chacha" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a6fdeb83b075e8266dcc8762c22776f6877a63111121f5f8c7411e5be7eed4b" +checksum = "e12735cf05c9e10bf21534da50a147b924d555dc7a547c42e6bb2d5b6017ae0d" dependencies = [ - "rand_core 0.4.2", + "ppv-lite86", + "rand_core 0.6.2", ] -[[package]] -name = "rand_core" -version = "0.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c33a3c44ca05fa6f1807d8e6743f3824e8509beca625669633be0acbdf509dc" - [[package]] name = "rand_core" version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19" dependencies = [ - "getrandom", + "getrandom 0.1.16", ] [[package]] -name = "rand_hc" -version = "0.1.0" +name = "rand_core" +version = "0.6.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b40677c7be09ae76218dc623efbf7b18e34bced3f38883af07bb75630a21bc4" +checksum = "34cf66eb183df1c5876e2dcf6b13d57340741e8dc255b48e40a26de954d06ae7" dependencies = [ - "rand_core 0.3.1", + "getrandom 0.2.2", ] [[package]] @@ -1007,78 +991,28 @@ dependencies = [ ] [[package]] -name = "rand_isaac" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ded997c9d5f13925be2a6fd7e66bf1872597f759fd9dd93513dd7e92e5a5ee08" -dependencies = [ - "rand_core 0.3.1", -] - -[[package]] -name = "rand_jitter" -version = "0.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1166d5c91dc97b88d1decc3285bb0a99ed84b05cfd0bc2341bdf2d43fc41e39b" -dependencies = [ - "libc", - "rand_core 0.4.2", - "winapi 0.3.9", -] - -[[package]] -name = "rand_os" -version = "0.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b75f676a1e053fc562eafbb47838d67c84801e38fc1ba459e8f180deabd5071" -dependencies = [ - "cloudabi", - "fuchsia-cprng", - "libc", - "rand_core 0.4.2", - "rdrand", - "winapi 0.3.9", -] - -[[package]] -name = "rand_pcg" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "abf9b09b01790cfe0364f52bf32995ea3c39f4d2dd011eac241d2914146d0b44" -dependencies = [ - "autocfg 0.1.7", - "rand_core 0.4.2", -] - -[[package]] -name = "rand_xorshift" -version = "0.1.1" +name = "rand_hc" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cbf7e9e623549b0e21f6e97cf8ecf247c1a8fd2e8a992ae265314300b2455d5c" +checksum = "3190ef7066a446f2e7f42e239d161e905420ccab01eb967c9eb27d21b2322a73" dependencies = [ - "rand_core 0.3.1", + "rand_core 0.6.2", ] [[package]] -name = "rdrand" -version = "0.4.0" +name = "redox_syscall" +version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "678054eb77286b51581ba43620cc911abf02758c91f93f479767aed0f90458b2" +checksum = "94341e4e44e24f6b591b59e47a8a027df12e008d73fd5672dbea9cc22f4507d9" dependencies = [ - "rand_core 0.3.1", + "bitflags", ] -[[package]] -name = "redox_syscall" -version = "0.1.57" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "41cc0f7e4d5d4544e8861606a285bb08d3e70712ccc7d2b84d7c0ccfaf4b05ce" - [[package]] name = "regex" -version = "1.4.2" +version = "1.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38cf2c13ed4745de91a5eb834e11c00bcc3709e773173b2ce4c56c9fbde04b9c" +checksum = "d9251239e129e16308e70d853559389de218ac275b515068abc96829d05b948a" dependencies = [ "aho-corasick", "memchr", @@ -1088,9 +1022,9 @@ dependencies = [ [[package]] name = "regex-syntax" -version = "0.6.21" +version = "0.6.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b181ba2dcf07aaccad5448e8ead58db5b742cf85dfe035e2227f137a539a189" +checksum = "b5eb417147ba9860a96cfe72a0b93bf88fee1744b5636ec99ab20c1aa9376581" [[package]] name = "remove_dir_all" @@ -1098,7 +1032,7 @@ version = "0.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3acd125665422973a33ac9d3dd2df85edad0f4ae9b00dafb1a05e43a9f5ef8e7" dependencies = [ - "winapi 0.3.9", + "winapi", ] [[package]] @@ -1109,14 +1043,9 @@ checksum = "6e3bad0ee36814ca07d7968269dd4b7ec89ec2da10c4bb613928d3077083c232" [[package]] name = "rustversion" -version = "1.0.3" +version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b9bdc5e856e51e685846fb6c13a1f5e5432946c2c90501bdc76a1319f19e29da" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] +checksum = "cb5d2a036dc6d2d8fd16fde3498b04306e29bd193bf306a57427019b823d5acd" [[package]] name = "ryu" @@ -1136,20 +1065,26 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ea6a9290e3c9cf0f18145ef7ffa62d68ee0bf5fcd651017e586dc7fd5da448c2" +[[package]] +name = "scopeguard" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" + [[package]] name = "serde" -version = "1.0.116" +version = "1.0.123" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96fe57af81d28386a513cbc6858332abc6117cfdb5999647c6444b8f43a370a5" +checksum = "92d5161132722baa40d802cc70b15262b98258453e85e5d1d365c757c73869ae" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.116" +version = "1.0.123" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f630a6370fd8e457873b4bd2ffdae75408bc291ba72be773772a4c2a065d9ae8" +checksum = "9391c295d64fc0abb2c556bad848f33cb8296276b1ad2677d1ae1ace4f258f31" dependencies = [ "proc-macro2", "quote", @@ -1158,9 +1093,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.57" +version = "1.0.63" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "164eacbdb13512ec2745fb09d51fd5b22b0d65ed294a1dcf7285a360c80a675c" +checksum = "43535db9747a4ba938c0ce0a98cc631a46ebf943c9e1d604e091df6007620bf6" dependencies = [ "itoa", "ryu", @@ -1169,14 +1104,14 @@ dependencies = [ [[package]] name = "serde_urlencoded" -version = "0.6.1" +version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ec5d77e2d4c73717816afac02670d5c4f534ea95ed430442cad02e7a6e32c97" +checksum = "edfa57a7f8d9c1d260a549e7224100f6c43d43f9103e06dd8b4095a9b2b43ce9" dependencies = [ - "dtoa", + "form_urlencoded", "itoa", + "ryu", "serde", - "url", ] [[package]] @@ -1193,17 +1128,26 @@ dependencies = [ [[package]] name = "sha-1" -version = "0.9.1" +version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "170a36ea86c864a3f16dd2687712dd6646f7019f301e57537c7f4dc9f5916770" +checksum = "dfebf75d25bd900fd1e7d11501efab59bc846dbc76196839663e6637bba9f25f" dependencies = [ "block-buffer 0.9.0", - "cfg-if 0.1.10", + "cfg-if 1.0.0", "cpuid-bool", "digest 0.9.0", "opaque-debug 0.3.0", ] +[[package]] +name = "signal-hook-registry" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "16f1d0fef1604ba8f7a073c7e701f213e056707210e9020af4528e0101ce11a6" +dependencies = [ + "libc", +] + [[package]] name = "simple-prometheus-exporter" version = "0.1.0" @@ -1215,22 +1159,27 @@ version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c111b5bd5695e56cffe5129854aa230b39c93a305372fdbb2668ca2394eea9f8" +[[package]] +name = "smallvec" +version = "1.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fe0f37c9e8f3c5a4a66ad655a93c74daac4ad00c441533bf5c6e7990bb42604e" + [[package]] name = "smawk" -version = "0.3.0" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e1bc737c97d093feb72e67f4926d9b22d717ce8580cd25f0ce86d74e859c466d" +checksum = "f67ad224767faa3c7d8b6d91985b78e70a1324408abcb1cfcc2be4c06bc06043" [[package]] name = "socket2" -version = "0.3.15" +version = "0.3.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1fa70dc5c8104ec096f4fe7ede7a221d35ae13dcd19ba1ad9a81d2cab9a1c44" +checksum = "122e570113d28d773067fab24266b66753f6ea915758651696b6e35e49f88d6e" dependencies = [ - "cfg-if 0.1.10", + "cfg-if 1.0.0", "libc", - "redox_syscall", - "winapi 0.3.9", + "winapi", ] [[package]] @@ -1241,9 +1190,9 @@ checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" [[package]] name = "structopt" -version = "0.3.18" +version = "0.3.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a33f6461027d7f08a13715659b2948e1602c31a3756aeae9378bfe7518c72e82" +checksum = "5277acd7ee46e63e5168a80734c9f6ee81b1367a7d8772a2d765df2a3705d28c" dependencies = [ "clap", "lazy_static", @@ -1252,9 +1201,9 @@ dependencies = [ [[package]] name = "structopt-derive" -version = "0.4.11" +version = "0.4.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c92e775028122a4b3dd55d58f14fc5120289c69bee99df1d117ae30f84b225c9" +checksum = "5ba9cdfda491b814720b6b06e0cac513d922fc407582032e8706e9f137976f90" dependencies = [ "heck", "proc-macro-error", @@ -1265,9 +1214,9 @@ dependencies = [ [[package]] name = "syn" -version = "1.0.42" +version = "1.0.60" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c51d92969d209b54a98397e1b91c8ae82d8c87a7bb87df0b29aa2ad81454228" +checksum = "c700597eca8a5a762beb35753ef6b94df201c81cca676604f547495a0d7f0081" dependencies = [ "proc-macro2", "quote", @@ -1297,16 +1246,16 @@ dependencies = [ [[package]] name = "tempfile" -version = "3.1.0" +version = "3.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a6e24d9338a0a5be79593e2fa15a648add6138caa803e2d5bc782c371732ca9" +checksum = "dac1c663cfc93810f88aed9b8941d48cabf856a1b111c29a40439018d870eb22" dependencies = [ - "cfg-if 0.1.10", + "cfg-if 1.0.0", "libc", - "rand 0.7.3", + "rand 0.8.3", "redox_syscall", "remove_dir_all", - "winapi 0.3.9", + "winapi", ] [[package]] @@ -1329,9 +1278,9 @@ dependencies = [ [[package]] name = "textwrap" -version = "0.13.0" +version = "0.13.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1bca196a5c5a7bc57a5c92809cf5670e16bcbca3bf0d09ef47150bf97221f6f" +checksum = "cd05616119e612a8041ef58f2b578906cc2531a6069047ae092cfb86a325d835" dependencies = [ "smawk", "unicode-width", @@ -1339,64 +1288,85 @@ dependencies = [ [[package]] name = "thread_local" -version = "1.0.1" +version = "1.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d40c6d1b69745a6ec6fb1ca717914848da4b44ae29d9b3080cbee91d72a69b14" +checksum = "8018d24e04c95ac8790716a5987d0fec4f8b27249ffa0f7d33f1369bdfb88cbd" dependencies = [ - "lazy_static", + "once_cell", ] [[package]] name = "time" -version = "0.1.44" +version = "0.1.43" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6db9e6914ab8b1ae1c260a4ae7a49b6c5611b40328a735b21862567685e73255" +checksum = "ca8a50ef2360fbd1eeb0ecd46795a87a19024eb4b53c5dc916ca1fd95fe62438" dependencies = [ "libc", - "wasi 0.10.0+wasi-snapshot-preview1", - "winapi 0.3.9", + "winapi", ] [[package]] name = "tinyvec" -version = "0.3.4" +version = "1.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "317cca572a0e89c3ce0ca1f1bdc9369547fe318a683418e42ac8f59d14701023" +dependencies = [ + "tinyvec_macros", +] + +[[package]] +name = "tinyvec_macros" +version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "238ce071d267c5710f9d31451efec16c5ee22de34df17cc05e56cbc92e967117" +checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c" [[package]] name = "tokio" -version = "0.2.22" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5d34ca54d84bf2b5b4d7d31e901a8464f7b60ac145a284fba25ceb801f2ddccd" +checksum = "e8190d04c665ea9e6b6a0dc45523ade572c088d2e6566244c1122671dbf4ae3a" dependencies = [ - "bytes", - "fnv", - "futures-core", - "iovec", - "lazy_static", + "autocfg", + "bytes 1.0.1", + "libc", "memchr", "mio", + "num_cpus", + "once_cell", + "parking_lot", "pin-project-lite", - "slab", + "signal-hook-registry", "tokio-macros", + "winapi", ] [[package]] name = "tokio-macros" -version = "0.2.5" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0c3acc6aa564495a0f2e1d59fab677cd7f81a19994cfc7f3ad0e64301560389" +checksum = "caf7b11a536f46a809a8a9f0bb4237020f70ecbf115b842360afb127ea2fda57" dependencies = [ "proc-macro2", "quote", "syn", ] +[[package]] +name = "tokio-stream" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1981ad97df782ab506a1f43bf82c967326960d278acf3bf8279809648c3ff3ea" +dependencies = [ + "futures-core", + "pin-project-lite", + "tokio", +] + [[package]] name = "tokio-tungstenite" -version = "0.11.0" +version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6d9e878ad426ca286e4dcae09cbd4e1973a7f8987d97570e2469703dd7f5720c" +checksum = "e1a5f475f1b9d077ea1017ecbc60890fda8e54942d680ca0b1d2b47cfa2d861b" dependencies = [ "futures-util", "log", @@ -1407,11 +1377,11 @@ dependencies = [ [[package]] name = "tokio-util" -version = "0.3.1" +version = "0.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "be8242891f2b6cbef26a2d7e8605133c2c554cd35b3e4948ea892d6d68436499" +checksum = "ebb7cb2f00c5ae8df755b252306272cd1790d39728363936e01827e11f0b017b" dependencies = [ - "bytes", + "bytes 1.0.1", "futures-core", "futures-sink", "log", @@ -1421,17 +1391,17 @@ dependencies = [ [[package]] name = "tower-service" -version = "0.3.0" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e987b6bf443f4b5b3b6f38704195592cca41c5bb7aedd3c3693c7081f8289860" +checksum = "360dfd1d6d30e05fda32ace2c8c70e9c0a9da713275777f5a4dbb8a1893930c6" [[package]] name = "tracing" -version = "0.1.21" +version = "0.1.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b0987850db3733619253fe60e17cb59b82d37c7e6c0236bb81e4d6b87c879f27" +checksum = "01ebdc2bb4498ab1ab5f5b73c5803825e60199229ccba0698170e3be0e7f959f" dependencies = [ - "cfg-if 0.1.10", + "cfg-if 1.0.0", "log", "pin-project-lite", "tracing-core", @@ -1448,9 +1418,9 @@ dependencies = [ [[package]] name = "tracing-futures" -version = "0.2.4" +version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ab7bb6f14721aa00656086e9335d363c5c8747bae02ebe32ea2c7dece5689b4c" +checksum = "97d095ae15e245a057c8e8451bab9b3ee1e1f68e9ba2b4fbc18d0ac5237835f2" dependencies = [ "pin-project", "tracing", @@ -1464,19 +1434,19 @@ checksum = "59547bce71d9c38b83d9c0e92b6066c4253371f15005def0c30d9657f50c7642" [[package]] name = "tungstenite" -version = "0.11.1" +version = "0.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0308d80d86700c5878b9ef6321f020f29b1bb9d5ff3cab25e75e23f3a492a23" +checksum = "8ada8297e8d70872fa9a551d93250a9f407beb9f37ef86494eb20012a2ff7c24" dependencies = [ "base64", "byteorder", - "bytes", + "bytes 1.0.1", "http", "httparse", "input_buffer", "log", - "rand 0.7.3", - "sha-1 0.9.1", + "rand 0.8.3", + "sha-1 0.9.4", "url", "utf-8", ] @@ -1516,18 +1486,18 @@ dependencies = [ [[package]] name = "unicode-normalization" -version = "0.1.13" +version = "0.1.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6fb19cf769fa8c6a80a162df694621ebeb4dafb606470b2b2fce0be40a98a977" +checksum = "07fbfce1c8a97d547e8b5334978438d9d6ec8c20e38f56d4a4374d181493eaef" dependencies = [ "tinyvec", ] [[package]] name = "unicode-segmentation" -version = "1.6.0" +version = "1.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e83e153d1053cbb5a118eeff7fd5be06ed99153f00dbcd8ae310c5fb2b22edc0" +checksum = "bb0d2e7be6ae3a5fa87eed5fb451aff96f2573d2694942e40543ae0bbe19c796" [[package]] name = "unicode-width" @@ -1543,21 +1513,16 @@ checksum = "f7fe0bb3479651439c9112f72b6c505038574c9fbb575ed1bf3b797fa39dd564" [[package]] name = "url" -version = "2.1.1" +version = "2.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "829d4a8476c35c9bf0bbce5a3b23f4106f79728039b726d292bb93bc106787cb" +checksum = "9ccd964113622c8e9322cfac19eb1004a07e636c545f325da085d5cdde6f1f8b" dependencies = [ + "form_urlencoded", "idna", "matches", "percent-encoding", ] -[[package]] -name = "urlencoding" -version = "1.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c9232eb53352b4442e40d7900465dfc534e8cb2dc8f18656fcb2ac16112b5593" - [[package]] name = "utf-8" version = "0.7.5" @@ -1594,11 +1559,11 @@ dependencies = [ [[package]] name = "warp" -version = "0.2.5" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f41be6df54c97904af01aa23e613d4521eed7ab23537cede692d4058f6449407" +checksum = "3dafd0aac2818a94a34df0df1100a7356c493d8ede4393875fd0b5c51bb6bc80" dependencies = [ - "bytes", + "bytes 1.0.1", "futures", "headers", "http", @@ -1607,17 +1572,19 @@ dependencies = [ "mime", "mime_guess", "multipart", + "percent-encoding", "pin-project", "scoped-tls", "serde", "serde_json", "serde_urlencoded", "tokio", + "tokio-stream", "tokio-tungstenite", + "tokio-util", "tower-service", "tracing", "tracing-futures", - "urlencoding", ] [[package]] @@ -1628,15 +1595,9 @@ checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519" [[package]] name = "wasi" -version = "0.10.0+wasi-snapshot-preview1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a143597ca7c7793eff794def352d41792a93c481eb1042423ff7ff72ba2c31f" - -[[package]] -name = "winapi" -version = "0.2.8" +version = "0.10.2+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a" +checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6" [[package]] name = "winapi" @@ -1648,12 +1609,6 @@ dependencies = [ "winapi-x86_64-pc-windows-gnu", ] -[[package]] -name = "winapi-build" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2d315eee3b34aca4797b2da6b13ed88266e6d612562a0c46390af8299fc699bc" - [[package]] name = "winapi-i686-pc-windows-gnu" version = "0.4.0" @@ -1666,7 +1621,7 @@ version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" dependencies = [ - "winapi 0.3.9", + "winapi", ] [[package]] @@ -1674,13 +1629,3 @@ name = "winapi-x86_64-pc-windows-gnu" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" - -[[package]] -name = "ws2_32-sys" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d59cefebd0c892fa2dd6de581e937301d8552cb44489cdff035c6187cb63fa5e" -dependencies = [ - "winapi 0.2.8", - "winapi-build", -] diff --git a/Cargo.toml b/Cargo.toml index dfb942e..a8cd47b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -30,15 +30,16 @@ serde = { version = "1.0", features = ["derive"], optional = true} serde_json = { version = "1.0", optional = true } # requirements for exporter -warp = { version = "0.2", optional = true } -tokio = { version = "0.2", features = ["macros"], optional = true } +warp = { version = "0.3", optional = true } +tokio = { version = "1.2", features = ["full"], optional = true } +tokio-stream = { version = "0.1", optional = true } simple-prometheus-exporter = { git = "https://github.com/timothyb89/simple-prometheus-exporter-rs", tag = "v0.1.0", optional = true } [features] default = [] bin = ["env_logger", "color-eyre", "structopt", "serde", "serde_json"] -exporter = ["warp", "tokio", "simple-prometheus-exporter"] +exporter = ["warp", "tokio", "tokio-stream", "simple-prometheus-exporter"] [[bin]] name = "metriful-exporter" @@ -49,3 +50,6 @@ required-features = ["bin", "exporter"] name = "metriful-tool" path = "src/bin/metriful_tool.rs" required-features = ["bin"] + +[profile.release] +lto = true diff --git a/README.md b/README.md index 6df1709..df6c315 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,293 @@ Requires rustc >= 1.48. [`rust-i2cdev`]: https://github.com/rust-embedded/rust-i2cdev [`rust-sysfs-gpio`]: https://github.com/rust-embedded/rust-sysfs-gpio +## `metriful-exporter` + +`metriful-exporter` serves all Metriful metrics over HTTP as both JSON and +Prometheus metrics. + +### Installation + + 1. Copy the `metriful-exporter` binary into `/usr/local/bin/` + 2. Create a systemd service file for the exporter at + `/etc/systemd/system/metriful-exporter.service`: + + ``` + [Unit] + Description=metriful monitoring service + After=network.target + StartLimitIntervalSec=0 + + [Service] + Type=simple + Restart=always + RestartSec=1 + User=root + ExecStart=/usr/local/bin/metriful-exporter --gpio-ready 17 --interval 100s + + [Install] + WantedBy=multi-user.target + ``` + 3. Enable and start the service: `sudo systemctl enable --now metriful-exporter` + + 4. If desired, add a scrape config to your Prometheus instance: + + ```yaml + - job_name: metriful-office + scrape_interval: 100s + static_configs: + - targets: ['pi.lan:8083'] + labels: + location: Inside + room: Office + ``` + + Make sure the scrape interval matches the exporter's interval (either 3, + 100, or 300 seconds) + +### API examples + +The following examples use [`xh`]. + +Prometheus metrics: `xh get pi.lan:8083/metrics`:
Expand + +```prometheus +metriful_ready 1 +metriful_air_gas_sensor_resistance{unit="ohms"} 479736 +metriful_air_humidity{unit="% relative humidity"} 17.100000381469727 +metriful_air_pressure{unit="pascals"} 84247 +metriful_air_temperature{unit="degrees Celsius"} 22 +metriful_air_quality_aqi{unit="AQI"} 25 +metriful_air_quality_aqi_accuracy{unit="AQI accuracy"} 0 +metriful_air_quality_estimated_co2{unit="parts per million"} 500 +metriful_air_quality_estimated_voc{unit="parts per million"} 5 +metriful_light_illuminance{unit="lux"} 293.5 +metriful_light_white_level{unit="white level"} 8249 +metriful_sound_measurement_stable{unit="sound measurement stability"} 0 +metriful_sound_peak_amplitude{unit="millipascals"} 8489.5 +metriful_sound_weighted_spl{unit="A-weighted sound pressure level"} 37.5 +metriful_sound_spl_b1{unit="decibels",band_midpoint_hz="125",band_lower_hz="88",band_upper_hz="177"} 38.79999923706055 +metriful_sound_spl_b2{unit="decibels",band_midpoint_hz="250",band_lower_hz="177",band_upper_hz="354"} 33.099998474121094 +metriful_sound_spl_b3{unit="decibels",band_midpoint_hz="500",band_lower_hz="354",band_upper_hz="707"} 35.099998474121094 +metriful_sound_spl_b4{unit="decibels",band_midpoint_hz="1000",band_lower_hz="707",band_upper_hz="1414"} 32.29999923706055 +metriful_sound_spl_b5{unit="decibels",band_midpoint_hz="2000",band_lower_hz="1414",band_upper_hz="2828"} 29.399999618530273 +metriful_sound_spl_b6{unit="decibels",band_midpoint_hz="4000",band_lower_hz="2828",band_upper_hz="5657"} 26 +metriful_read_count 2 +metriful_error_count 0 +``` +
+ +JSON metrics: `xh get pi.lan:8083/json`:
Expand + +```json +{ + "error_count": 0, + "initial_status": { + "light_int": { + "status": "disabled" + }, + "mode": { + "mode": "standby" + }, + "particle_sensor": "disabled", + "sound_int": { + "status": "disabled" + } + }, + "options": { + "device": "/dev/i2c-1", + "gpio_ready": 17, + "i2c_address": 113, + "interval": { + "period": "3s" + }, + "port": 8083, + "timeout": null + }, + "read_count": 2, + "reading": { + "formatted_value": "air data:\n temperature: 22 ℃\n pressure: 84247 Pa\n humidity: 17.1 % RH\n gas sensor resistance: 479736 Ω\n\nair quality data:\n air quality index: 25\n estimated CO2: 500 ppm\n estimated VOCs: 5 ppm\n AQI accuracy: invalid\n\nlight data:\n illuminance: 293.5 lx\n white level: 8249\n\nsound data:\n a-weighted SPL: 37.5 dBa\n SPL frequency bands: [38.8, 33.1, 35.1, 32.3, 29.4, 26.0]\n peak amplitude: 8489.5 mPa\n measurement stability: unstable\n\nparticle data:\n duty cycle: 0 %\n concentration: 0\n validity: initializing\n\n", + "timestamp": "2021-02-27T22:57:45Z", + "unit_name": "all combined data", + "unit_symbol": null, + "value": { + "air": { + "formatted_value": "temperature: 22 ℃\npressure: 84247 Pa\nhumidity: 17.1 % RH\ngas sensor resistance: 479736 Ω\n", + "timestamp": "2021-02-27T22:57:45Z", + "unit_name": "combined air data", + "unit_symbol": null, + "value": { + "gas_sensor_resistance": { + "formatted_value": "479736 Ω", + "timestamp": "2021-02-27T22:57:45Z", + "unit_name": "ohms", + "unit_symbol": "Ω", + "value": 479736 + }, + "humidity": { + "formatted_value": "17.1 % RH", + "timestamp": "2021-02-27T22:57:45Z", + "unit_name": "% relative humidity", + "unit_symbol": "% RH", + "value": 17.100000381469727 + }, + "pressure": { + "formatted_value": "84247 Pa", + "timestamp": "2021-02-27T22:57:45Z", + "unit_name": "pascals", + "unit_symbol": "Pa", + "value": 84247 + }, + "temperature": { + "formatted_value": "22 ℃", + "timestamp": "2021-02-27T22:57:45Z", + "unit_name": "degrees Celsius", + "unit_symbol": "℃", + "value": 22.0 + } + } + }, + "air_quality": { + "formatted_value": "air quality index: 25\nestimated CO2: 500 ppm\nestimated VOCs: 5 ppm\nAQI accuracy: invalid\n", + "timestamp": "2021-02-27T22:57:45Z", + "unit_name": "combined air quality data", + "unit_symbol": null, + "value": { + "aqi": { + "formatted_value": "25", + "timestamp": "2021-02-27T22:57:45Z", + "unit_name": "AQI", + "unit_symbol": null, + "value": 25.0 + }, + "aqi_accuracy": { + "formatted_value": "invalid", + "timestamp": "2021-02-27T22:57:45Z", + "unit_name": "AQI accuracy", + "unit_symbol": null, + "value": "invalid" + }, + "estimated_co2": { + "formatted_value": "500 ppm", + "timestamp": "2021-02-27T22:57:45Z", + "unit_name": "parts per million", + "unit_symbol": "ppm", + "value": 500.0 + }, + "estimated_voc": { + "formatted_value": "5 ppm", + "timestamp": "2021-02-27T22:57:45Z", + "unit_name": "parts per million", + "unit_symbol": "ppm", + "value": 5.0 + } + } + }, + "light": { + "formatted_value": "illuminance: 293.5 lx\nwhite level: 8249\n", + "timestamp": "2021-02-27T22:57:45Z", + "unit_name": "combined light data", + "unit_symbol": null, + "value": { + "illuminance": { + "formatted_value": "293.5 lx", + "timestamp": "2021-02-27T22:57:45Z", + "unit_name": "lux", + "unit_symbol": "lx", + "value": 293.5 + }, + "white_level": { + "formatted_value": "8249", + "timestamp": "2021-02-27T22:57:45Z", + "unit_name": "white level", + "unit_symbol": null, + "value": 8249 + } + } + }, + "particle": { + "formatted_value": "duty cycle: 0 %\nconcentration: 0\nvalidity: initializing\n", + "timestamp": "2021-02-27T22:57:45Z", + "unit_name": "combined particle data", + "unit_symbol": null, + "value": { + "concentration": { + "formatted_value": "0", + "timestamp": "2021-02-27T22:57:45Z", + "unit_name": "raw particle concentration", + "unit_symbol": null, + "value": { + "ppd42_value": 0, + "sds011_value": 0.0 + } + }, + "duty_cycle": { + "formatted_value": "0 %", + "timestamp": "2021-02-27T22:57:45Z", + "unit_name": "percent", + "unit_symbol": "%", + "value": 0.0 + }, + "validity": { + "formatted_value": "initializing", + "timestamp": "2021-02-27T22:57:45Z", + "unit_name": "particle data validity", + "unit_symbol": null, + "value": "initializing" + } + } + }, + "sound": { + "formatted_value": "a-weighted SPL: 37.5 dBa\nSPL frequency bands: [38.8, 33.1, 35.1, 32.3, 29.4, 26.0]\npeak amplitude: 8489.5 mPa\nmeasurement stability: unstable\n", + "timestamp": "2021-02-27T22:57:45Z", + "unit_name": "combined sound data", + "unit_symbol": null, + "value": { + "measurement_stability": { + "formatted_value": "unstable", + "timestamp": "2021-02-27T22:57:45Z", + "unit_name": "sound measurement stability", + "unit_symbol": null, + "value": "unstable" + }, + "peak_amplitude": { + "formatted_value": "8489.5 mPa", + "timestamp": "2021-02-27T22:57:45Z", + "unit_name": "millipascals", + "unit_symbol": "mPa", + "value": 8489.5 + }, + "spl_bands": { + "formatted_value": "[38.8, 33.1, 35.1, 32.3, 29.4, 26.0]", + "timestamp": "2021-02-27T22:57:45Z", + "unit_name": "sound pressure level frequency bands", + "unit_symbol": null, + "value": [ + 38.79999923706055, + 33.099998474121094, + 35.099998474121094, + 32.29999923706055, + 29.399999618530273, + 26.0 + ] + }, + "weighted_spl": { + "formatted_value": "37.5 dBa", + "timestamp": "2021-02-27T22:57:45Z", + "unit_name": "A-weighted sound pressure level", + "unit_symbol": "dBa", + "value": 37.5 + } + } + } + } + } +} +``` +
+ +[`xh`]: https://github.com/ducaale/xh + ## `metriful-tool` `metriful-tool` can be used to query and manage Metriful sensors. diff --git a/metriful-exporter.service b/metriful-exporter.service index 40f0842..71c4da2 100644 --- a/metriful-exporter.service +++ b/metriful-exporter.service @@ -1,4 +1,3 @@ - [Unit] Description=metriful monitoring service After=network.target diff --git a/src/bin/metriful_exporter.rs b/src/bin/metriful_exporter.rs index 014ed08..2d005c9 100644 --- a/src/bin/metriful_exporter.rs +++ b/src/bin/metriful_exporter.rs @@ -1,16 +1,18 @@ use std::path::PathBuf; use std::sync::{Arc, RwLock}; use std::sync::atomic::{AtomicUsize, Ordering}; -use std::thread; use std::time::Duration; -use std::sync::mpsc::channel; -use color_eyre::eyre::{Result, Error, Context, eyre}; +use color_eyre::eyre::{Result, Context}; use log::*; -use metriful::{Metriful, CyclePeriod, metric::METRIC_COMBINED_ALL}; +use metriful::unit::{MetrifulUnit, UnitCombinedData}; +use metriful::{Metriful, CyclePeriod, metric::METRIC_COMBINED_ALL, unit::UnitValue}; +use serde::Serialize; use serde_json::{self, json}; use simple_prometheus_exporter::{Exporter, export}; use structopt::StructOpt; +use tokio::task; +use tokio_stream::{self as stream, StreamExt}; use warp::Filter; fn try_from_hex_arg(s: &str) -> Result { @@ -27,7 +29,7 @@ fn parse_duration_secs(s: &str) -> Result { )) } -#[derive(Debug, Clone, StructOpt)] +#[derive(Debug, Clone, StructOpt, Serialize)] #[structopt(name = "metriful-exporter")] struct Options { /// system i2c device, e.g. /dev/i2c-1 @@ -80,24 +82,158 @@ struct Options { port: u16, } +type Reading = Option>; + fn export_reading( exporter: &Exporter, reading: &Reading, + read_count: &Arc, error_count: &Arc, - fatal_error_count: &Arc ) -> String { let mut s = exporter.session(); match reading { Some(r) => { - // TODO - //export!(s, "metriful_temperature", r.temperature.value, unit = "c"); + export!(s, "metriful_ready", 1); + + let air = &r.value.air.value; + export!( + s, "metriful_air_gas_sensor_resistance", air.gas_sensor_resistance.value, + unit = air.gas_sensor_resistance.unit.get_name() + ); + export!( + s, "metriful_air_humidity", air.humidity.value, + unit = air.humidity.unit.get_name() + ); + export!( + s, "metriful_air_pressure", air.pressure.value, + unit = air.pressure.unit.get_name() + ); + export!( + s, "metriful_air_temperature", air.temperature.value, + unit = air.temperature.unit.get_name() + ); + + let air_quality = &r.value.air_quality.value; + export!( + s, "metriful_air_quality_aqi", air_quality.aqi.value, + unit = air_quality.aqi.unit.get_name() + ); + export!( + s, "metriful_air_quality_aqi_accuracy", air_quality.aqi_accuracy.value.to_uint(), + unit = air_quality.aqi_accuracy.unit.get_name() + ); + export!( + s, "metriful_air_quality_estimated_co2", air_quality.estimated_co2.value, + unit = air_quality.estimated_co2.unit.get_name() + ); + export!( + s, "metriful_air_quality_estimated_voc", air_quality.estimated_voc.value, + unit = air_quality.estimated_voc.unit.get_name() + ); + + let light = &r.value.light.value; + export!( + s, "metriful_light_illuminance", light.illuminance.value, + unit = light.illuminance.unit.get_name() + ); + export!( + s, "metriful_light_white_level", light.white_level.value, + unit = light.white_level.unit.get_name() + ); + + // TODO: particle sensors not currently supported as we'd need to + // configure the sensor at startup + // TODO: we could _technically_ still expose the values here if users + // somehow configured it, since we know the initial_status, but this seems + // unlikely. + // let particle = &r.value.particle.value; + // export!( + // s, "metriful_particle_concentration", particle.concentration.value, + // unit = particle.concentration.unit.get_name() + // ); + // TODO: duty_cycle, validity + + let sound = &r.value.sound.value; + export!( + s, "metriful_sound_measurement_stable", + sound.measurement_stability.value.to_uint(), + unit = sound.measurement_stability.unit.get_name() + ); + export!( + s, "metriful_sound_peak_amplitude", + sound.peak_amplitude.value, + unit = sound.peak_amplitude.unit.get_name() + ); + export!( + s, "metriful_sound_weighted_spl", + sound.weighted_spl.value, + unit = sound.weighted_spl.unit.get_name() + ); + + let [b1, b2, b3, b4, b5, b6] = sound.spl_bands.value.0; + export!( + s, "metriful_sound_spl_band", + b1, + unit = "decibels", + band = "1", + band_midpoint_hz = "125", + band_lower_hz = "88", + band_upper_hz = "177" + ); + export!( + s, "metriful_sound_spl_band", + b2, + unit = "decibels", + band = "2", + band_midpoint_hz = "250", + band_lower_hz = "177", + band_upper_hz = "354" + ); + export!( + s, "metriful_sound_spl_band", + b3, + unit = "decibels", + band = "3", + band_midpoint_hz = "500", + band_lower_hz = "354", + band_upper_hz = "707" + ); + export!( + s, "metriful_sound_spl_band", + b4, + unit = "decibels", + band = "4", + band_midpoint_hz = "1000", + band_lower_hz = "707", + band_upper_hz = "1414" + ); + export!( + s, "metriful_sound_spl_band", + b5, + unit = "decibels", + band = "5", + band_midpoint_hz = "2000", + band_lower_hz = "1414", + band_upper_hz = "2828" + ); + export!( + s, "metriful_sound_spl_band", + b6, + unit = "decibels", + band = "6", + band_midpoint_hz = "4000", + band_lower_hz = "2828", + band_upper_hz = "5657" + ); }, - None => () + None => { + export!(s, "metriful_ready", 0); + } }; + export!(s, "metriful_read_count", read_count.load(Ordering::Relaxed) as f64); export!(s, "metriful_error_count", error_count.load(Ordering::Relaxed) as f64); - export!(s, "metriful_fatal_error_count", fatal_error_count.load(Ordering::Relaxed) as f64); s.to_string() } @@ -118,27 +254,96 @@ async fn main() -> Result<()> { let port = opts.port; let latest_reading_lock = Arc::new(RwLock::new(None)); + let read_count = Arc::new(AtomicUsize::new(0)); let error_count = Arc::new(AtomicUsize::new(0)); - let fatal_error_count = Arc::new(AtomicUsize::new(0)); + // initialize the sensor and start the async read thread + let sensor_opts = opts.clone(); + let res: Result<_> = task::spawn_blocking(move || { + let mut metriful = Metriful::try_new( + sensor_opts.gpio_ready, + sensor_opts.device, + sensor_opts.i2c_address + ).wrap_err("could not initialize sensor")?; + + metriful.wait_for_ready_timeout(sensor_opts.timeout) + .wrap_err("sensor did not become ready in time")?; + + metriful.reset().wrap_err("sensor reset failed")?; + + // fetch the initial status while we're here - we need it to determine the + // particle sensor type, if any + let status = metriful.read_status() + .wrap_err("could not read sensor status")?; + + info!("sensor is ready, status: {:?}", &status); + + let handles = metriful.async_cycle_read_timeout( + *METRIC_COMBINED_ALL, + sensor_opts.interval, + sensor_opts.timeout + ); + + Ok((status, handles)) + }).await?; + + // unpack the channel + handle (separate for type inference reasons) + let (initial_status, (_tx, rx, _handle)) = res?; + + // spawn a task to continuously move the latest reading into latest_reading_lock + let data_lock = Arc::clone(&latest_reading_lock); + let data_read_count = Arc::clone(&read_count); + let data_error_count = Arc::clone(&error_count); + task::spawn(async move { + let mut s = stream::iter(rx); + while let Some(reading) = s.next().await { + match reading { + Ok(reading) => match data_lock.try_write() { + Ok(mut r) => { + *r = Some(reading); + data_read_count.fetch_add(1, Ordering::Relaxed); + }, + Err(e) => { + error!("could not acquire write lock, reading will be dropped: {}", e); + data_error_count.fetch_add(1, Ordering::Relaxed); + } + }, + Err(e) => { + error!("error in sensor read: {}", e); + data_error_count.fetch_add(1, Ordering::Relaxed); + } + } + } + }); + + // json endpoint let json_lock = Arc::clone(&latest_reading_lock); + let json_read_count = Arc::clone(&read_count); + let json_error_count = Arc::clone(&error_count); + let json_opts = opts.clone(); let r_json = warp::path("json").map(move || { match *json_lock.read().unwrap() { - Some(ref r) => warp::reply::json()), + Some(ref r) => warp::reply::json(&json!({ + "initial_status": &initial_status, + "reading": r, + "options": json_opts, + "error_count": json_error_count.load(Ordering::Relaxed), + "read_count": json_read_count.load(Ordering::Relaxed), + })), None => warp::reply::json(&json!(null)) } }); let exporter = Arc::new(Exporter::new()); let metrics_lock = Arc::clone(&latest_reading_lock); + let metrics_read_count = Arc::clone(&read_count); let metrics_error_count = Arc::clone(&error_count); - let metrics_fatal_error_count = Arc::clone(&fatal_error_count); let r_metrics = warp::path("metrics").map(move || { export_reading( &exporter, &*metrics_lock.read().unwrap(), + &metrics_read_count, &metrics_error_count, - &metrics_fatal_error_count ) }); diff --git a/src/bin/metriful_tool.rs b/src/bin/metriful_tool.rs index f4ea6c0..d3ea85e 100644 --- a/src/bin/metriful_tool.rs +++ b/src/bin/metriful_tool.rs @@ -81,7 +81,7 @@ struct CycleWatchAction { output: OutputMode, /// Cycle period, one of: 0 (3s), 1 (100s), 2 (300s) - #[structopt(long, short, default_value = "3s")] + #[structopt(long, short, default_value = "3s", env = "METRIFUL_INTERVAL")] interval: CyclePeriod } @@ -115,22 +115,44 @@ fn parse_duration_secs(s: &str) -> Result { #[structopt(name = "metriful-tool")] struct Options { /// system i2c device, e.g. /dev/i2c-1 - #[structopt(long, short, parse(from_os_str), default_value = "/dev/i2c-1", global = true)] + #[structopt( + long, short, + parse(from_os_str), + default_value = "/dev/i2c-1", + global = true, + env = "METRIFUL_I2C_DEVICE" + )] device: PathBuf, /// Metriful device i2c address; usually 0x71, or 0x71 if the solder bridge is /// closed. Can specify a plain base-10 int or hex with a `0x` prefix. - #[structopt(long, parse(try_from_str = try_from_hex_arg), default_value = "0x71", global = true)] + #[structopt( + long, + parse(try_from_str = try_from_hex_arg), + default_value = "0x71", + global = true, + env = "METRIFUL_I2C_ADDRESS" + )] i2c_address: u16, /// GPIO number for the ready signal. Note that this is a GPIO number, not a /// physical pin number - the mapping between the two numbers varies by /// device. - #[structopt(long, default_value = "11", env = "GPIO_READY", global = true)] + #[structopt( + long, + default_value = "11", + env = "METRIFUL_GPIO_READY", + global = true + )] gpio_ready: u64, /// Global timeout for any individual sensor command in seconds. - #[structopt(long, parse(try_from_str = parse_duration_secs), global = true)] + #[structopt( + long, + parse(try_from_str = parse_duration_secs), + global = true, + env = "METRIFUL_TIMEOUT" + )] timeout: Option, #[structopt(subcommand)] diff --git a/src/lib.rs b/src/lib.rs index 3b99454..819ae32 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -399,6 +399,8 @@ impl Metriful { } else { thread::sleep(Duration::from_millis(READY_POLL_INTERVAL)); } + } else { + thread::sleep(Duration::from_millis(READY_POLL_INTERVAL)); } } } diff --git a/src/unit.rs b/src/unit.rs index bbc1e11..46e5aea 100644 --- a/src/unit.rs +++ b/src/unit.rs @@ -99,9 +99,19 @@ pub trait MetrifulUnit: Sized + Default + fmt::Debug + Copy + Clone + Send + Syn /// The human-readable name of the unit fn name() -> &'static str; + /// Instance-accessible `name()` + fn get_name(&self) -> &'static str { + Self::name() + } + /// The human-readable symbol for this unit fn symbol() -> Option<&'static str>; + /// Instance-accessible `symbol()` + fn get_symbol(&self) -> Option<&'static str> { + Self::symbol() + } + fn format_value(value: &Self::Output) -> String { if let Some(symbol) = Self::symbol() { format!("{} {}", value, symbol) @@ -212,7 +222,7 @@ impl MetrifulUnit for UnitResistance { type Output = u32; fn name() -> &'static str { - "resistance" + "ohms" } fn symbol() -> Option<&'static str> { @@ -352,6 +362,15 @@ impl AQIAccuracy { _ => Err(MetrifulError::InvalidAQIAccuracy(byte)) } } + + pub fn to_uint(&self) -> u8 { + match self { + AQIAccuracy::Invalid => 0, + AQIAccuracy::Low => 1, + AQIAccuracy::Medium => 2, + AQIAccuracy::High => 3 + } + } } impl fmt::Display for AQIAccuracy { @@ -563,7 +582,7 @@ impl MetrifulUnit for UnitAWeightedSPL { #[derive(Debug, Clone)] #[cfg_attr(feature = "serde", derive(Serialize))] -pub struct SPLFrequencyBands([f32; 6]); +pub struct SPLFrequencyBands(pub [f32; 6]); impl fmt::Display for SPLFrequencyBands { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { @@ -641,6 +660,16 @@ pub enum SoundMeasurementStability { Unstable } +impl SoundMeasurementStability { + /// Converts this value to an int: 0 (unstable), 1 (stable) + pub fn to_uint(&self) -> u8 { + match self { + SoundMeasurementStability::Stable => 1, + SoundMeasurementStability::Unstable => 0 + } + } +} + impl fmt::Display for SoundMeasurementStability { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "{}", match self {