├── .github ├── ISSUE_TEMPLATE │ ├── bug_report.md │ └── feature_request.md ├── PULL_REQUEST_TEMPLATE.md └── workflows │ ├── master.yml │ └── release.yml ├── .gitignore ├── .rustfmt.toml ├── CHANGELOG.md ├── Cargo.lock ├── Cargo.toml ├── LICENSE ├── README.md ├── example_output ├── dump_json ├── dump_normal └── graph.gif └── src ├── cli.rs ├── cmd ├── common.rs ├── dump.rs ├── get.rs ├── mod.rs ├── show │ ├── common │ │ ├── data.rs │ │ ├── display.rs │ │ ├── mod.rs │ │ ├── monitor.rs │ │ ├── rxtx.rs │ │ ├── screen.rs │ │ └── widget.rs │ ├── cpu │ │ ├── frequency.rs │ │ ├── mod.rs │ │ └── usage.rs │ ├── events.rs │ ├── mod.rs │ ├── net.rs │ ├── ps.rs │ └── storage.rs └── watch.rs ├── main.rs └── util.rs /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | --- 5 | 6 | 7 | 8 | 9 | - Crate version: 10 | - OS: 11 | - Output of running `docker version` on the command line: 12 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | --- 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | 6 | 7 | ## What did you implement: 8 | 9 | 12 | 13 | Closes: #xxx 14 | 15 | ## How did you verify your change: 16 | 17 | ## What (if anything) would need to be called out in the CHANGELOG for the next release: -------------------------------------------------------------------------------- /.github/workflows/master.yml: -------------------------------------------------------------------------------- 1 | name: master 2 | 3 | on: 4 | workflow_dispatch: 5 | push: 6 | paths-ignore: 7 | - "*.md" 8 | - "LICENSE" 9 | branches: 10 | - master 11 | pull_request: 12 | paths-ignore: 13 | - "*.md" 14 | - "LICENSE" 15 | branches: 16 | - master 17 | 18 | env: 19 | CARGO_TERM_COLOR: always 20 | 21 | jobs: 22 | codestyle: 23 | runs-on: ubuntu-latest 24 | steps: 25 | - name: Set up Rust 26 | uses: hecrj/setup-rust-action@v1 27 | with: 28 | components: rustfmt 29 | rust-version: stable 30 | - uses: actions/checkout@v1 31 | - run: cargo fmt --all -- --check 32 | 33 | lint: 34 | runs-on: ubuntu-latest 35 | steps: 36 | - name: Set up Rust 37 | uses: hecrj/setup-rust-action@v1 38 | with: 39 | components: clippy 40 | - uses: actions/checkout@v1 41 | - run: cargo clippy --all-targets -- -D clippy::all 42 | 43 | compile: 44 | runs-on: ubuntu-latest 45 | steps: 46 | - name: Set up Rust 47 | uses: hecrj/setup-rust-action@v1 48 | - uses: actions/checkout@master 49 | - run: cargo check --all 50 | 51 | test: 52 | needs: [codestyle, lint, compile] 53 | strategy: 54 | matrix: 55 | os: 56 | - ubuntu-latest 57 | - macos-latest 58 | runs-on: ${{ matrix.os }} 59 | 60 | steps: 61 | - name: Setup Rust 62 | uses: hecrj/setup-rust-action@v1 63 | with: 64 | rust-version: ${{ matrix.rust }} 65 | - name: Checkout 66 | uses: actions/checkout@v1 67 | - name: Test 68 | run: cargo test 69 | -------------------------------------------------------------------------------- /.github/workflows/release.yml: -------------------------------------------------------------------------------- 1 | name: release 2 | 3 | on: 4 | push: 5 | branches: 6 | - "!*" 7 | tags: 8 | - "**" 9 | jobs: 10 | codestyle: 11 | strategy: 12 | matrix: 13 | os: 14 | - ubuntu-latest 15 | - macos-latest 16 | runs-on: ${{ matrix.os }} 17 | steps: 18 | - name: Set up Rust 19 | uses: hecrj/setup-rust-action@v1 20 | with: 21 | components: rustfmt 22 | rust-version: stable 23 | - uses: actions/checkout@v1 24 | - run: cargo fmt --all -- --check 25 | 26 | lint: 27 | strategy: 28 | matrix: 29 | os: 30 | - ubuntu-latest 31 | - macos-latest 32 | runs-on: ${{ matrix.os }} 33 | steps: 34 | - name: Set up Rust 35 | uses: hecrj/setup-rust-action@v1 36 | with: 37 | components: clippy 38 | - uses: actions/checkout@v1 39 | - run: cargo clippy --all-targets -- -D clippy::all 40 | 41 | compile: 42 | strategy: 43 | matrix: 44 | os: 45 | - ubuntu-latest 46 | - macos-latest 47 | runs-on: ${{ matrix.os }} 48 | steps: 49 | - name: Set up Rust 50 | uses: hecrj/setup-rust-action@v1 51 | - uses: actions/checkout@master 52 | - run: cargo check --all 53 | 54 | test: 55 | needs: [codestyle, lint, compile] 56 | strategy: 57 | matrix: 58 | os: 59 | - ubuntu-latest 60 | - macos-latest 61 | runs-on: ${{ matrix.os }} 62 | 63 | steps: 64 | - name: Setup Rust 65 | uses: hecrj/setup-rust-action@v1 66 | with: 67 | rust-version: ${{ matrix.rust }} 68 | - name: Checkout 69 | uses: actions/checkout@v1 70 | - name: Test 71 | run: cargo test 72 | 73 | build_and_upload_artifacts: 74 | name: Upload Artifacts 75 | needs: [test] 76 | runs-on: ${{ matrix.os }} 77 | strategy: 78 | matrix: 79 | build: [linux, macos] 80 | include: 81 | - build: linux 82 | os: ubuntu-latest 83 | target: x86_64-unknown-linux 84 | - build: macos 85 | os: macos-latest 86 | target: x86_64-apple-darwin 87 | 88 | steps: 89 | - name: Set up Rust 90 | uses: hecrj/setup-rust-action@v1 91 | - uses: actions/checkout@master 92 | - name: Set version 93 | id: set_version 94 | run: echo ::set-output name=RSYS_VERSION::${GITHUB_REF/refs\/tags\//} 95 | - name: Set archive name 96 | id: set_name 97 | run: echo ::set-output name=RSYS_ARCHIVE::rsys-${{steps.set_version.outputs.RSYS_VERSION}}-${{ matrix.target}} 98 | - run: cargo build --release 99 | name: Release build 100 | - name: Install help2man mac 101 | if: matrix.os == 'macos-latest' 102 | run: brew install help2man 103 | - name: Install help2man ubuntu 104 | if: matrix.os == 'ubuntu-latest' 105 | run: | 106 | sudo apt -y update 107 | sudo apt -y install help2man 108 | - name: Prepare archive directory 109 | run: mkdir rsys 110 | - name: Generate manual 111 | run: | 112 | help2man target/release/rsys > rsys/rsys.1 113 | - name: Move release files 114 | run: | 115 | mv target/release/rsys rsys/ 116 | mv README.md rsys/ 117 | mv LICENSE rsys/ 118 | - name: Create archives 119 | run: | 120 | tar -zcvf ${{ steps.set_name.outputs.RSYS_ARCHIVE }}.tar.gz rsys 121 | tar -Jcvf ${{ steps.set_name.outputs.RSYS_ARCHIVE }}.tar.xz rsys 122 | - name: Upload gz 123 | uses: svenstaro/upload-release-action@v2 124 | with: 125 | repo_name: wojciechkepka/rsys-cli 126 | repo_token: ${{ secrets.GITHUB_TOKEN }} 127 | file: ${{ steps.set_name.outputs.RSYS_ARCHIVE }}.tar.gz 128 | asset_name: ${{ steps.set_name.outputs.RSYS_ARCHIVE }}.tar.gz 129 | tag: ${{ steps.set_version.outputs.RSYS_VERSION }} 130 | overwrite: true 131 | - name: Upload xz 132 | uses: svenstaro/upload-release-action@v2 133 | with: 134 | repo_name: wojciechkepka/rsys-cli 135 | repo_token: ${{ secrets.GITHUB_TOKEN }} 136 | file: ${{ steps.set_name.outputs.RSYS_ARCHIVE }}.tar.xz 137 | asset_name: ${{ steps.set_name.outputs.RSYS_ARCHIVE }}.tar.xz 138 | tag: ${{ steps.set_version.outputs.RSYS_VERSION }} 139 | overwrite: true 140 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | target -------------------------------------------------------------------------------- /.rustfmt.toml: -------------------------------------------------------------------------------- 1 | max_width = 120 2 | edition = "2018" 3 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vv9k/rsys-cli/08bf0bc2fb24e53be0abfc54957e0c1fc7227a6e/CHANGELOG.md -------------------------------------------------------------------------------- /Cargo.lock: -------------------------------------------------------------------------------- 1 | # This file is automatically @generated by Cargo. 2 | # It is not intended for manual editing. 3 | [[package]] 4 | name = "anyhow" 5 | version = "1.0.33" 6 | source = "registry+https://github.com/rust-lang/crates.io-index" 7 | checksum = "a1fd36ffbb1fb7c834eac128ea8d0e310c5aeb635548f9d58861e1308d46e71c" 8 | 9 | [[package]] 10 | name = "arrayref" 11 | version = "0.3.6" 12 | source = "registry+https://github.com/rust-lang/crates.io-index" 13 | checksum = "a4c527152e37cf757a3f78aae5a06fbeefdb07ccc535c980a3208ee3060dd544" 14 | 15 | [[package]] 16 | name = "arrayvec" 17 | version = "0.5.1" 18 | source = "registry+https://github.com/rust-lang/crates.io-index" 19 | checksum = "cff77d8686867eceff3105329d4698d96c2391c176d5d03adc90c7389162b5b8" 20 | 21 | [[package]] 22 | name = "atty" 23 | version = "0.2.14" 24 | source = "registry+https://github.com/rust-lang/crates.io-index" 25 | checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" 26 | dependencies = [ 27 | "hermit-abi", 28 | "libc", 29 | "winapi", 30 | ] 31 | 32 | [[package]] 33 | name = "autocfg" 34 | version = "1.0.1" 35 | source = "registry+https://github.com/rust-lang/crates.io-index" 36 | checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a" 37 | 38 | [[package]] 39 | name = "base64" 40 | version = "0.12.3" 41 | source = "registry+https://github.com/rust-lang/crates.io-index" 42 | checksum = "3441f0f7b02788e948e47f457ca01f1d7e6d92c693bc132c22b087d3141c03ff" 43 | 44 | [[package]] 45 | name = "bitflags" 46 | version = "1.2.1" 47 | source = "registry+https://github.com/rust-lang/crates.io-index" 48 | checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" 49 | 50 | [[package]] 51 | name = "blake2b_simd" 52 | version = "0.5.10" 53 | source = "registry+https://github.com/rust-lang/crates.io-index" 54 | checksum = "d8fb2d74254a3a0b5cac33ac9f8ed0e44aa50378d9dbb2e5d83bd21ed1dc2c8a" 55 | dependencies = [ 56 | "arrayref", 57 | "arrayvec", 58 | "constant_time_eq", 59 | ] 60 | 61 | [[package]] 62 | name = "bstr" 63 | version = "0.2.13" 64 | source = "registry+https://github.com/rust-lang/crates.io-index" 65 | checksum = "31accafdb70df7871592c058eca3985b71104e15ac32f64706022c58867da931" 66 | dependencies = [ 67 | "lazy_static", 68 | "memchr", 69 | "regex-automata", 70 | "serde", 71 | ] 72 | 73 | [[package]] 74 | name = "byteorder" 75 | version = "1.3.4" 76 | source = "registry+https://github.com/rust-lang/crates.io-index" 77 | checksum = "08c48aae112d48ed9f069b33538ea9e3e90aa263cfa3d1c24309612b1f7472de" 78 | 79 | [[package]] 80 | name = "cassowary" 81 | version = "0.3.0" 82 | source = "registry+https://github.com/rust-lang/crates.io-index" 83 | checksum = "df8670b8c7b9dae1793364eafadf7239c40d669904660c5960d74cfd80b46a53" 84 | 85 | [[package]] 86 | name = "cc" 87 | version = "1.0.61" 88 | source = "registry+https://github.com/rust-lang/crates.io-index" 89 | checksum = "ed67cbde08356238e75fc4656be4749481eeffb09e19f320a25237d5221c985d" 90 | 91 | [[package]] 92 | name = "cfg-if" 93 | version = "0.1.10" 94 | source = "registry+https://github.com/rust-lang/crates.io-index" 95 | checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" 96 | 97 | [[package]] 98 | name = "clap" 99 | version = "2.33.3" 100 | source = "registry+https://github.com/rust-lang/crates.io-index" 101 | checksum = "37e58ac78573c40708d45522f0d80fa2f01cc4f9b4e2bf749807255454312002" 102 | dependencies = [ 103 | "bitflags", 104 | "textwrap", 105 | "unicode-width", 106 | ] 107 | 108 | [[package]] 109 | name = "constant_time_eq" 110 | version = "0.1.5" 111 | source = "registry+https://github.com/rust-lang/crates.io-index" 112 | checksum = "245097e9a4535ee1e3e3931fcfcd55a796a44c643e8596ff6566d68f09b87bbc" 113 | 114 | [[package]] 115 | name = "crossbeam-utils" 116 | version = "0.7.2" 117 | source = "registry+https://github.com/rust-lang/crates.io-index" 118 | checksum = "c3c7c73a2d1e9fc0886a08b93e98eb643461230d5f1925e4036204d5f2e261a8" 119 | dependencies = [ 120 | "autocfg", 121 | "cfg-if", 122 | "lazy_static", 123 | ] 124 | 125 | [[package]] 126 | name = "csv" 127 | version = "1.1.3" 128 | source = "registry+https://github.com/rust-lang/crates.io-index" 129 | checksum = "00affe7f6ab566df61b4be3ce8cf16bc2576bca0963ceb0955e45d514bf9a279" 130 | dependencies = [ 131 | "bstr", 132 | "csv-core", 133 | "itoa", 134 | "ryu", 135 | "serde", 136 | ] 137 | 138 | [[package]] 139 | name = "csv-core" 140 | version = "0.1.10" 141 | source = "registry+https://github.com/rust-lang/crates.io-index" 142 | checksum = "2b2466559f260f48ad25fe6317b3c8dac77b5bdb5763ac7d9d6103530663bc90" 143 | dependencies = [ 144 | "memchr", 145 | ] 146 | 147 | [[package]] 148 | name = "dirs" 149 | version = "1.0.5" 150 | source = "registry+https://github.com/rust-lang/crates.io-index" 151 | checksum = "3fd78930633bd1c6e35c4b42b1df7b0cbc6bc191146e512bb3bedf243fcc3901" 152 | dependencies = [ 153 | "libc", 154 | "redox_users", 155 | "winapi", 156 | ] 157 | 158 | [[package]] 159 | name = "dtoa" 160 | version = "0.4.6" 161 | source = "registry+https://github.com/rust-lang/crates.io-index" 162 | checksum = "134951f4028bdadb9b84baf4232681efbf277da25144b9b0ad65df75946c422b" 163 | 164 | [[package]] 165 | name = "encode_unicode" 166 | version = "0.3.6" 167 | source = "registry+https://github.com/rust-lang/crates.io-index" 168 | checksum = "a357d28ed41a50f9c765dbfe56cbc04a64e53e5fc58ba79fbc34c10ef3df831f" 169 | 170 | [[package]] 171 | name = "getrandom" 172 | version = "0.1.15" 173 | source = "registry+https://github.com/rust-lang/crates.io-index" 174 | checksum = "fc587bc0ec293155d5bfa6b9891ec18a1e330c234f896ea47fbada4cadbe47e6" 175 | dependencies = [ 176 | "cfg-if", 177 | "libc", 178 | "wasi", 179 | ] 180 | 181 | [[package]] 182 | name = "heck" 183 | version = "0.3.1" 184 | source = "registry+https://github.com/rust-lang/crates.io-index" 185 | checksum = "20564e78d53d2bb135c343b3f47714a56af2061f1c928fdb541dc7b9fdd94205" 186 | dependencies = [ 187 | "unicode-segmentation", 188 | ] 189 | 190 | [[package]] 191 | name = "hermit-abi" 192 | version = "0.1.17" 193 | source = "registry+https://github.com/rust-lang/crates.io-index" 194 | checksum = "5aca5565f760fb5b220e499d72710ed156fdb74e631659e99377d9ebfbd13ae8" 195 | dependencies = [ 196 | "libc", 197 | ] 198 | 199 | [[package]] 200 | name = "itoa" 201 | version = "0.4.6" 202 | source = "registry+https://github.com/rust-lang/crates.io-index" 203 | checksum = "dc6f3ad7b9d11a0c00842ff8de1b60ee58661048eb8049ed33c73594f359d7e6" 204 | 205 | [[package]] 206 | name = "lazy_static" 207 | version = "1.4.0" 208 | source = "registry+https://github.com/rust-lang/crates.io-index" 209 | checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" 210 | 211 | [[package]] 212 | name = "libc" 213 | version = "0.2.79" 214 | source = "registry+https://github.com/rust-lang/crates.io-index" 215 | checksum = "2448f6066e80e3bfc792e9c98bf705b4b0fc6e8ef5b43e5889aff0eaa9c58743" 216 | 217 | [[package]] 218 | name = "linked-hash-map" 219 | version = "0.5.3" 220 | source = "registry+https://github.com/rust-lang/crates.io-index" 221 | checksum = "8dd5a6d5999d9907cda8ed67bbd137d3af8085216c2ac62de5be860bd41f304a" 222 | 223 | [[package]] 224 | name = "memchr" 225 | version = "2.3.3" 226 | source = "registry+https://github.com/rust-lang/crates.io-index" 227 | checksum = "3728d817d99e5ac407411fa471ff9800a778d88a24685968b36824eaf4bee400" 228 | 229 | [[package]] 230 | name = "nix" 231 | version = "0.18.0" 232 | source = "registry+https://github.com/rust-lang/crates.io-index" 233 | checksum = "83450fe6a6142ddd95fb064b746083fc4ef1705fe81f64a64e1d4b39f54a1055" 234 | dependencies = [ 235 | "bitflags", 236 | "cc", 237 | "cfg-if", 238 | "libc", 239 | ] 240 | 241 | [[package]] 242 | name = "numtoa" 243 | version = "0.1.0" 244 | source = "registry+https://github.com/rust-lang/crates.io-index" 245 | checksum = "b8f8bdf33df195859076e54ab11ee78a1b208382d3a26ec40d142ffc1ecc49ef" 246 | 247 | [[package]] 248 | name = "ppv-lite86" 249 | version = "0.2.9" 250 | source = "registry+https://github.com/rust-lang/crates.io-index" 251 | checksum = "c36fa947111f5c62a733b652544dd0016a43ce89619538a8ef92724a6f501a20" 252 | 253 | [[package]] 254 | name = "prettytable-rs" 255 | version = "0.8.0" 256 | source = "registry+https://github.com/rust-lang/crates.io-index" 257 | checksum = "0fd04b170004fa2daccf418a7f8253aaf033c27760b5f225889024cf66d7ac2e" 258 | dependencies = [ 259 | "atty", 260 | "csv", 261 | "encode_unicode", 262 | "lazy_static", 263 | "term", 264 | "unicode-width", 265 | ] 266 | 267 | [[package]] 268 | name = "proc-macro-error" 269 | version = "1.0.4" 270 | source = "registry+https://github.com/rust-lang/crates.io-index" 271 | checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c" 272 | dependencies = [ 273 | "proc-macro-error-attr", 274 | "proc-macro2", 275 | "quote", 276 | "syn", 277 | "version_check", 278 | ] 279 | 280 | [[package]] 281 | name = "proc-macro-error-attr" 282 | version = "1.0.4" 283 | source = "registry+https://github.com/rust-lang/crates.io-index" 284 | checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869" 285 | dependencies = [ 286 | "proc-macro2", 287 | "quote", 288 | "version_check", 289 | ] 290 | 291 | [[package]] 292 | name = "proc-macro2" 293 | version = "1.0.24" 294 | source = "registry+https://github.com/rust-lang/crates.io-index" 295 | checksum = "1e0704ee1a7e00d7bb417d0770ea303c1bccbabf0ef1667dae92b5967f5f8a71" 296 | dependencies = [ 297 | "unicode-xid", 298 | ] 299 | 300 | [[package]] 301 | name = "quote" 302 | version = "1.0.7" 303 | source = "registry+https://github.com/rust-lang/crates.io-index" 304 | checksum = "aa563d17ecb180e500da1cfd2b028310ac758de548efdd203e18f283af693f37" 305 | dependencies = [ 306 | "proc-macro2", 307 | ] 308 | 309 | [[package]] 310 | name = "rand" 311 | version = "0.7.3" 312 | source = "registry+https://github.com/rust-lang/crates.io-index" 313 | checksum = "6a6b1679d49b24bbfe0c803429aa1874472f50d9b363131f0e89fc356b544d03" 314 | dependencies = [ 315 | "getrandom", 316 | "libc", 317 | "rand_chacha", 318 | "rand_core", 319 | "rand_hc", 320 | ] 321 | 322 | [[package]] 323 | name = "rand_chacha" 324 | version = "0.2.2" 325 | source = "registry+https://github.com/rust-lang/crates.io-index" 326 | checksum = "f4c8ed856279c9737206bf725bf36935d8666ead7aa69b52be55af369d193402" 327 | dependencies = [ 328 | "ppv-lite86", 329 | "rand_core", 330 | ] 331 | 332 | [[package]] 333 | name = "rand_core" 334 | version = "0.5.1" 335 | source = "registry+https://github.com/rust-lang/crates.io-index" 336 | checksum = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19" 337 | dependencies = [ 338 | "getrandom", 339 | ] 340 | 341 | [[package]] 342 | name = "rand_hc" 343 | version = "0.2.0" 344 | source = "registry+https://github.com/rust-lang/crates.io-index" 345 | checksum = "ca3129af7b92a17112d59ad498c6f81eaf463253766b90396d39ea7a39d6613c" 346 | dependencies = [ 347 | "rand_core", 348 | ] 349 | 350 | [[package]] 351 | name = "redox_syscall" 352 | version = "0.1.57" 353 | source = "registry+https://github.com/rust-lang/crates.io-index" 354 | checksum = "41cc0f7e4d5d4544e8861606a285bb08d3e70712ccc7d2b84d7c0ccfaf4b05ce" 355 | 356 | [[package]] 357 | name = "redox_termios" 358 | version = "0.1.1" 359 | source = "registry+https://github.com/rust-lang/crates.io-index" 360 | checksum = "7e891cfe48e9100a70a3b6eb652fef28920c117d366339687bd5576160db0f76" 361 | dependencies = [ 362 | "redox_syscall", 363 | ] 364 | 365 | [[package]] 366 | name = "redox_users" 367 | version = "0.3.5" 368 | source = "registry+https://github.com/rust-lang/crates.io-index" 369 | checksum = "de0737333e7a9502c789a36d7c7fa6092a49895d4faa31ca5df163857ded2e9d" 370 | dependencies = [ 371 | "getrandom", 372 | "redox_syscall", 373 | "rust-argon2", 374 | ] 375 | 376 | [[package]] 377 | name = "regex-automata" 378 | version = "0.1.9" 379 | source = "registry+https://github.com/rust-lang/crates.io-index" 380 | checksum = "ae1ded71d66a4a97f5e961fd0cb25a5f366a42a41570d16a763a69c092c26ae4" 381 | dependencies = [ 382 | "byteorder", 383 | ] 384 | 385 | [[package]] 386 | name = "rsys" 387 | version = "0.5.5" 388 | source = "git+https://github.com/wojciechkepka/rsys?branch=master#237bec04a428aaae7149ea41cb2c092c3bdbb738" 389 | dependencies = [ 390 | "cfg-if", 391 | "nix", 392 | "rsys_macro", 393 | "serde", 394 | "thiserror", 395 | "winapi", 396 | ] 397 | 398 | [[package]] 399 | name = "rsys-cli" 400 | version = "0.1.0" 401 | dependencies = [ 402 | "anyhow", 403 | "prettytable-rs", 404 | "rand", 405 | "rsys", 406 | "serde", 407 | "serde_json", 408 | "serde_yaml", 409 | "structopt", 410 | "termion", 411 | "tui", 412 | ] 413 | 414 | [[package]] 415 | name = "rsys_macro" 416 | version = "0.1.2" 417 | source = "git+https://github.com/wojciechkepka/rsys?branch=master#237bec04a428aaae7149ea41cb2c092c3bdbb738" 418 | dependencies = [ 419 | "proc-macro2", 420 | ] 421 | 422 | [[package]] 423 | name = "rust-argon2" 424 | version = "0.8.2" 425 | source = "registry+https://github.com/rust-lang/crates.io-index" 426 | checksum = "9dab61250775933275e84053ac235621dfb739556d5c54a2f2e9313b7cf43a19" 427 | dependencies = [ 428 | "base64", 429 | "blake2b_simd", 430 | "constant_time_eq", 431 | "crossbeam-utils", 432 | ] 433 | 434 | [[package]] 435 | name = "ryu" 436 | version = "1.0.5" 437 | source = "registry+https://github.com/rust-lang/crates.io-index" 438 | checksum = "71d301d4193d031abdd79ff7e3dd721168a9572ef3fe51a1517aba235bd8f86e" 439 | 440 | [[package]] 441 | name = "serde" 442 | version = "1.0.116" 443 | source = "registry+https://github.com/rust-lang/crates.io-index" 444 | checksum = "96fe57af81d28386a513cbc6858332abc6117cfdb5999647c6444b8f43a370a5" 445 | dependencies = [ 446 | "serde_derive", 447 | ] 448 | 449 | [[package]] 450 | name = "serde_derive" 451 | version = "1.0.116" 452 | source = "registry+https://github.com/rust-lang/crates.io-index" 453 | checksum = "f630a6370fd8e457873b4bd2ffdae75408bc291ba72be773772a4c2a065d9ae8" 454 | dependencies = [ 455 | "proc-macro2", 456 | "quote", 457 | "syn", 458 | ] 459 | 460 | [[package]] 461 | name = "serde_json" 462 | version = "1.0.58" 463 | source = "registry+https://github.com/rust-lang/crates.io-index" 464 | checksum = "a230ea9107ca2220eea9d46de97eddcb04cd00e92d13dda78e478dd33fa82bd4" 465 | dependencies = [ 466 | "itoa", 467 | "ryu", 468 | "serde", 469 | ] 470 | 471 | [[package]] 472 | name = "serde_yaml" 473 | version = "0.8.13" 474 | source = "registry+https://github.com/rust-lang/crates.io-index" 475 | checksum = "ae3e2dd40a7cdc18ca80db804b7f461a39bb721160a85c9a1fa30134bf3c02a5" 476 | dependencies = [ 477 | "dtoa", 478 | "linked-hash-map", 479 | "serde", 480 | "yaml-rust", 481 | ] 482 | 483 | [[package]] 484 | name = "structopt" 485 | version = "0.3.19" 486 | source = "registry+https://github.com/rust-lang/crates.io-index" 487 | checksum = "a7a7159e7d0dbcab6f9c980d7971ef50f3ff5753081461eeda120d5974a4ee95" 488 | dependencies = [ 489 | "clap", 490 | "lazy_static", 491 | "structopt-derive", 492 | ] 493 | 494 | [[package]] 495 | name = "structopt-derive" 496 | version = "0.4.12" 497 | source = "registry+https://github.com/rust-lang/crates.io-index" 498 | checksum = "8fc47de4dfba76248d1e9169ccff240eea2a4dc1e34e309b95b2393109b4b383" 499 | dependencies = [ 500 | "heck", 501 | "proc-macro-error", 502 | "proc-macro2", 503 | "quote", 504 | "syn", 505 | ] 506 | 507 | [[package]] 508 | name = "syn" 509 | version = "1.0.43" 510 | source = "registry+https://github.com/rust-lang/crates.io-index" 511 | checksum = "1e2e59c50ed8f6b050b071aa7b6865293957a9af6b58b94f97c1c9434ad440ea" 512 | dependencies = [ 513 | "proc-macro2", 514 | "quote", 515 | "unicode-xid", 516 | ] 517 | 518 | [[package]] 519 | name = "term" 520 | version = "0.5.2" 521 | source = "registry+https://github.com/rust-lang/crates.io-index" 522 | checksum = "edd106a334b7657c10b7c540a0106114feadeb4dc314513e97df481d5d966f42" 523 | dependencies = [ 524 | "byteorder", 525 | "dirs", 526 | "winapi", 527 | ] 528 | 529 | [[package]] 530 | name = "termion" 531 | version = "1.5.5" 532 | source = "registry+https://github.com/rust-lang/crates.io-index" 533 | checksum = "c22cec9d8978d906be5ac94bceb5a010d885c626c4c8855721a4dbd20e3ac905" 534 | dependencies = [ 535 | "libc", 536 | "numtoa", 537 | "redox_syscall", 538 | "redox_termios", 539 | ] 540 | 541 | [[package]] 542 | name = "textwrap" 543 | version = "0.11.0" 544 | source = "registry+https://github.com/rust-lang/crates.io-index" 545 | checksum = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060" 546 | dependencies = [ 547 | "unicode-width", 548 | ] 549 | 550 | [[package]] 551 | name = "thiserror" 552 | version = "1.0.21" 553 | source = "registry+https://github.com/rust-lang/crates.io-index" 554 | checksum = "318234ffa22e0920fe9a40d7b8369b5f649d490980cf7aadcf1eb91594869b42" 555 | dependencies = [ 556 | "thiserror-impl", 557 | ] 558 | 559 | [[package]] 560 | name = "thiserror-impl" 561 | version = "1.0.21" 562 | source = "registry+https://github.com/rust-lang/crates.io-index" 563 | checksum = "cae2447b6282786c3493999f40a9be2a6ad20cb8bd268b0a0dbf5a065535c0ab" 564 | dependencies = [ 565 | "proc-macro2", 566 | "quote", 567 | "syn", 568 | ] 569 | 570 | [[package]] 571 | name = "tui" 572 | version = "0.12.0" 573 | source = "registry+https://github.com/rust-lang/crates.io-index" 574 | checksum = "c2eaeee894a1e9b90f80aa466fe59154fdb471980b5e104d8836fcea309ae17e" 575 | dependencies = [ 576 | "bitflags", 577 | "cassowary", 578 | "termion", 579 | "unicode-segmentation", 580 | "unicode-width", 581 | ] 582 | 583 | [[package]] 584 | name = "unicode-segmentation" 585 | version = "1.6.0" 586 | source = "registry+https://github.com/rust-lang/crates.io-index" 587 | checksum = "e83e153d1053cbb5a118eeff7fd5be06ed99153f00dbcd8ae310c5fb2b22edc0" 588 | 589 | [[package]] 590 | name = "unicode-width" 591 | version = "0.1.8" 592 | source = "registry+https://github.com/rust-lang/crates.io-index" 593 | checksum = "9337591893a19b88d8d87f2cec1e73fad5cdfd10e5a6f349f498ad6ea2ffb1e3" 594 | 595 | [[package]] 596 | name = "unicode-xid" 597 | version = "0.2.1" 598 | source = "registry+https://github.com/rust-lang/crates.io-index" 599 | checksum = "f7fe0bb3479651439c9112f72b6c505038574c9fbb575ed1bf3b797fa39dd564" 600 | 601 | [[package]] 602 | name = "version_check" 603 | version = "0.9.2" 604 | source = "registry+https://github.com/rust-lang/crates.io-index" 605 | checksum = "b5a972e5669d67ba988ce3dc826706fb0a8b01471c088cb0b6110b805cc36aed" 606 | 607 | [[package]] 608 | name = "wasi" 609 | version = "0.9.0+wasi-snapshot-preview1" 610 | source = "registry+https://github.com/rust-lang/crates.io-index" 611 | checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519" 612 | 613 | [[package]] 614 | name = "winapi" 615 | version = "0.3.9" 616 | source = "registry+https://github.com/rust-lang/crates.io-index" 617 | checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" 618 | dependencies = [ 619 | "winapi-i686-pc-windows-gnu", 620 | "winapi-x86_64-pc-windows-gnu", 621 | ] 622 | 623 | [[package]] 624 | name = "winapi-i686-pc-windows-gnu" 625 | version = "0.4.0" 626 | source = "registry+https://github.com/rust-lang/crates.io-index" 627 | checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" 628 | 629 | [[package]] 630 | name = "winapi-x86_64-pc-windows-gnu" 631 | version = "0.4.0" 632 | source = "registry+https://github.com/rust-lang/crates.io-index" 633 | checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" 634 | 635 | [[package]] 636 | name = "yaml-rust" 637 | version = "0.4.4" 638 | source = "registry+https://github.com/rust-lang/crates.io-index" 639 | checksum = "39f0c922f1a334134dc2f7a8b67dc5d25f0735263feec974345ff706bcf20b0d" 640 | dependencies = [ 641 | "linked-hash-map", 642 | ] 643 | -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "rsys-cli" 3 | version = "0.1.0" 4 | authors = ["wojciechkepka "] 5 | edition = "2018" 6 | 7 | [dependencies] 8 | rsys = { git = "https://github.com/wojciechkepka/rsys", branch = "master", features = ["serialize", "display"] } 9 | #rsys = { path = "../rsys", features = ["serialize", "display"] } 10 | structopt = { version = "0.3", default-features = false } 11 | serde_json = "1" 12 | serde_yaml = "0.8" 13 | serde = { version = "1", features = ["derive"] } 14 | prettytable-rs = "^0.8" 15 | termion = "1" 16 | tui = "0.12" 17 | anyhow = "1" 18 | rand = "0.7.3" 19 | 20 | 21 | [[bin]] 22 | name = "rsys" 23 | path = "./src/main.rs" 24 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License 2 | 3 | Copyright (c) 2020 Wojciech Kępka 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # rsys-cli 2 | [![master](https://github.com/wojciechkepka/rsys-cli/actions/workflows/master.yml/badge.svg)](https://github.com/wojciechkepka/rsys-cli/actions/workflows/master.yml) 3 | CLI tool for quick access to system information. For now Linux only. 4 | 5 | ## Install 6 | 7 | You can get the prebuilt binaries from [here](https://github.com/wojciechkepka/rsys-cli/releases). 8 | 9 | To build manually you'll need latest `rust` and `cargo`. Build with: 10 | - `cargo build --release` 11 | 12 | ## Available commands 13 | ### `show` 14 | ``` 15 | USAGE: 16 | rsys show 17 | 18 | FLAGS: 19 | -h, --help Prints help information 20 | -V, --version Prints version information 21 | 22 | SUBCOMMANDS: 23 | all Display all graphs at once 24 | cpu Draw core frequencies 25 | help Prints this message or the help of the given subcommand(s) 26 | interface Draw interface rx/tx speed 27 | storage Display I/O stats for storage devices 28 | ``` 29 | ![Example graph](https://github.com/wojciechkepka/rsys-cli/blob/master/example_output/graph.gif) 30 | 31 | ### `get` 32 | Gets a specified parameter. 33 | ``` 34 | USAGE: 35 | rsys get [FLAGS] 36 | 37 | FLAGS: 38 | -h, --help Prints help information 39 | -j, --json Print output as JSON 40 | -p, --pretty Make the output pretty 41 | -V, --version Prints version information 42 | -y, --yaml Print output as YAML 43 | 44 | SUBCOMMANDS: 45 | arch Cpu architecture 46 | cpu All cpu stats and cores 47 | cpu-clock 48 | cpu-cores 49 | cpu-model 50 | domain 51 | help Prints this message or the help of the given subcommand(s) 52 | hostname 53 | interface Lookup statistics and information about network interface 54 | interfaces 55 | kernel 56 | logical-cores 57 | memory All memory statistics 58 | memory-free 59 | memory-total 60 | mounts Mountpoints from /etc/mounts 61 | os 62 | process 63 | storage Storage device info 64 | swap-free 65 | swap-total 66 | uptime 67 | ``` 68 | ### `watch` 69 | ``` 70 | Monitor specified parameters. Default parameters are hostname and uptime. To monitor more parameters use flags like 71 | `cpu`, `memory` or `storage`. This command runs indefinitely unless a `duration` parameter is specified and by default 72 | prints JSON with parameters each second. To change how often there is a snapshot of data adjust `interval` parameter 73 | 74 | USAGE: 75 | rsys watch [FLAGS] [OPTIONS] 76 | 77 | FLAGS: 78 | -a, --all Shortcut for `--cpu --memory --storage --network --mounts` 79 | --cpu Include CPU info with cores 80 | -h, --help Prints help information 81 | --memory Include memory statistics 82 | --network Adds network interfaces to the output 83 | -p, --pretty Make the output pretty 84 | --stats Whether to parse stats for all storage devices or just the main ones. Only functional with 85 | `--storage` flag 86 | --storage Adds info about storage devices, device mappers, multiple device arrays 87 | -V, --version Prints version information 88 | 89 | OPTIONS: 90 | -d, --duration Duration in seconds for which to collect data. Default is 18_446_744_073_709_551_615 91 | seconds 92 | -i, --interval How long to wait between runs in milliseconds. Default is 1000 93 | ``` 94 | 95 | ### `dump` 96 | Dumps all data in specified format. By default only basic info like 97 | hostname, uptime, cpu architecture are dumped. To enable more information 98 | use `--memory`, `--mounts`, `--storage`, `--network` flags 99 | ``` 100 | USAGE: 101 | rsys dump [FLAGS] 102 | 103 | FLAGS: 104 | -a, --all Shortcut for `--cpu --memory --storage --network --mounts` 105 | --cpu Include CPU info with cores 106 | -h, --help Prints help information 107 | -j, --json Print output as JSON 108 | --memory Include memory statistics 109 | --mounts Adds information about mountpoints on host os 110 | --network Adds network interfaces to the output 111 | -p, --pretty Make the output pretty 112 | --stats Whether to parse stats for all storage devices or just the main ones. Only functional with 113 | `--storage` flag 114 | --storage Adds info about storage devices, device mappers, multiple device arrays 115 | -V, --version Prints version information 116 | -y, --yaml Print output as YAML 117 | ``` 118 | 119 | ### Example usage and output 120 | #### Get information about memory as pretty printed JSON 121 | `rsys get -jp memory` 122 | ``` 123 | { 124 | "total": 16712667136, 125 | "free": 6789361664, 126 | "available": 12793421824, 127 | "buffers": 263999488, 128 | "cached": 5953527808, 129 | "active": 5261893632, 130 | "inactive": 3771269120, 131 | "shared": 232402944 132 | } 133 | ``` 134 | #### Get network interface stats pretty printed 135 | ``` 136 | $ rsys get -p interface enp8s0 137 | Interface { 138 | name: "enp8s0", 139 | ipv4: "192.168.0.1", 140 | stat: IfaceStat { 141 | rx_bytes: 1263128140, 142 | rx_packets: 929371, 143 | rx_errs: 0, 144 | rx_drop: 0, 145 | rx_fifo: 0, 146 | rx_frame: 0, 147 | rx_compressed: 0, 148 | rx_multicast: 15519, 149 | tx_bytes: 47660514, 150 | tx_packets: 555310, 151 | tx_errs: 0, 152 | tx_drop: 0, 153 | tx_fifo: 0, 154 | tx_frame: 0, 155 | tx_compressed: 0, 156 | tx_multicast: 0, 157 | }, 158 | mtu: 1500, 159 | mac_address: "70:85:c2:f9:9b:2a", 160 | speed: 1000, 161 | } 162 | ``` 163 | #### Basic dump in YAML 164 | ``` 165 | $ rsys dump -y 166 | --- 167 | arch: x86_64 168 | hostname: arch 169 | domain: (none) 170 | uptime: 4861 171 | os: linux 172 | kernel: 5.8.12-arch1-1 173 | ``` 174 | 175 | ## License 176 | [**MIT**](https://github.com/wojciechkepka/rsys-cli/blob/master/LICENSE) 177 | -------------------------------------------------------------------------------- /example_output/dump_json: -------------------------------------------------------------------------------- 1 | { 2 | "arch": "x86_64", 3 | "hostname": "arch", 4 | "domain": "(none)", 5 | "uptime": 51252, 6 | "os": "linux", 7 | "cpu": { 8 | "cores": [ 9 | { 10 | "id": 11, 11 | "min_freq": 2200000, 12 | "cur_freq": 2195899, 13 | "max_freq": 3600000 14 | }, 15 | { 16 | "id": 9, 17 | "min_freq": 2200000, 18 | "cur_freq": 2193702, 19 | "max_freq": 3600000 20 | }, 21 | { 22 | "id": 7, 23 | "min_freq": 2200000, 24 | "cur_freq": 2138400, 25 | "max_freq": 3600000 26 | }, 27 | { 28 | "id": 5, 29 | "min_freq": 2200000, 30 | "cur_freq": 2194193, 31 | "max_freq": 3600000 32 | }, 33 | { 34 | "id": 3, 35 | "min_freq": 2200000, 36 | "cur_freq": 2196514, 37 | "max_freq": 3600000 38 | }, 39 | { 40 | "id": 1, 41 | "min_freq": 2200000, 42 | "cur_freq": 1938574, 43 | "max_freq": 3600000 44 | }, 45 | { 46 | "id": 10, 47 | "min_freq": 2200000, 48 | "cur_freq": 2195306, 49 | "max_freq": 3600000 50 | }, 51 | { 52 | "id": 8, 53 | "min_freq": 2200000, 54 | "cur_freq": 2095843, 55 | "max_freq": 3600000 56 | }, 57 | { 58 | "id": 6, 59 | "min_freq": 2200000, 60 | "cur_freq": 2719822, 61 | "max_freq": 3600000 62 | }, 63 | { 64 | "id": 4, 65 | "min_freq": 2200000, 66 | "cur_freq": 2195029, 67 | "max_freq": 3600000 68 | }, 69 | { 70 | "id": 2, 71 | "min_freq": 2200000, 72 | "cur_freq": 2085114, 73 | "max_freq": 3600000 74 | }, 75 | { 76 | "id": 0, 77 | "min_freq": 2200000, 78 | "cur_freq": 2316508, 79 | "max_freq": 3600000 80 | } 81 | ], 82 | "model": "AMD Ryzen 5 3600 6-Core Processor", 83 | "cache_size": 524288, 84 | "bogomips": 0.0 85 | }, 86 | "kernel": "5.8.12-arch1-1\n", 87 | "memory": { 88 | "total": 16712667136, 89 | "free": 6606864384, 90 | "available": 12663083008, 91 | "buffers": 269496320, 92 | "cached": 6081789952, 93 | "active": 5315641344, 94 | "inactive": 3897569280, 95 | "shared": 322441216 96 | }, 97 | "mounts": [ 98 | { 99 | "volume": "proc", 100 | "path": "/proc", 101 | "voltype": "proc", 102 | "options": "rw,nosuid,nodev,noexec,relatime" 103 | }, 104 | { 105 | "volume": "sys", 106 | "path": "/sys", 107 | "voltype": "sysfs", 108 | "options": "rw,nosuid,nodev,noexec,relatime" 109 | }, 110 | { 111 | "volume": "dev", 112 | "path": "/dev", 113 | "voltype": "devtmpfs", 114 | "options": "rw,nosuid,relatime,size=8148476k,nr_inodes=2037119,mode=755" 115 | }, 116 | { 117 | "volume": "run", 118 | "path": "/run", 119 | "voltype": "tmpfs", 120 | "options": "rw,nosuid,nodev,relatime,mode=755" 121 | }, 122 | { 123 | "volume": "efivarfs", 124 | "path": "/sys/firmware/efi/efivars", 125 | "voltype": "efivarfs", 126 | "options": "rw,nosuid,nodev,noexec,relatime" 127 | }, 128 | { 129 | "volume": "/dev/mapper/vgmain-root", 130 | "path": "/", 131 | "voltype": "ext4", 132 | "options": "rw,relatime" 133 | }, 134 | { 135 | "volume": "securityfs", 136 | "path": "/sys/kernel/security", 137 | "voltype": "securityfs", 138 | "options": "rw,nosuid,nodev,noexec,relatime" 139 | }, 140 | { 141 | "volume": "tmpfs", 142 | "path": "/dev/shm", 143 | "voltype": "tmpfs", 144 | "options": "rw,nosuid,nodev" 145 | }, 146 | { 147 | "volume": "devpts", 148 | "path": "/dev/pts", 149 | "voltype": "devpts", 150 | "options": "rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=000" 151 | }, 152 | { 153 | "volume": "tmpfs", 154 | "path": "/sys/fs/cgroup", 155 | "voltype": "tmpfs", 156 | "options": "ro,nosuid,nodev,noexec,size=4096k,nr_inodes=1024,mode=755" 157 | }, 158 | { 159 | "volume": "cgroup2", 160 | "path": "/sys/fs/cgroup/unified", 161 | "voltype": "cgroup2", 162 | "options": "rw,nosuid,nodev,noexec,relatime,nsdelegate" 163 | }, 164 | { 165 | "volume": "cgroup", 166 | "path": "/sys/fs/cgroup/systemd", 167 | "voltype": "cgroup", 168 | "options": "rw,nosuid,nodev,noexec,relatime,xattr,name=systemd" 169 | }, 170 | { 171 | "volume": "pstore", 172 | "path": "/sys/fs/pstore", 173 | "voltype": "pstore", 174 | "options": "rw,nosuid,nodev,noexec,relatime" 175 | }, 176 | { 177 | "volume": "none", 178 | "path": "/sys/fs/bpf", 179 | "voltype": "bpf", 180 | "options": "rw,nosuid,nodev,noexec,relatime,mode=700" 181 | }, 182 | { 183 | "volume": "cgroup", 184 | "path": "/sys/fs/cgroup/blkio", 185 | "voltype": "cgroup", 186 | "options": "rw,nosuid,nodev,noexec,relatime,blkio" 187 | }, 188 | { 189 | "volume": "cgroup", 190 | "path": "/sys/fs/cgroup/rdma", 191 | "voltype": "cgroup", 192 | "options": "rw,nosuid,nodev,noexec,relatime,rdma" 193 | }, 194 | { 195 | "volume": "cgroup", 196 | "path": "/sys/fs/cgroup/perf_event", 197 | "voltype": "cgroup", 198 | "options": "rw,nosuid,nodev,noexec,relatime,perf_event" 199 | }, 200 | { 201 | "volume": "cgroup", 202 | "path": "/sys/fs/cgroup/cpu,cpuacct", 203 | "voltype": "cgroup", 204 | "options": "rw,nosuid,nodev,noexec,relatime,cpu,cpuacct" 205 | }, 206 | { 207 | "volume": "cgroup", 208 | "path": "/sys/fs/cgroup/hugetlb", 209 | "voltype": "cgroup", 210 | "options": "rw,nosuid,nodev,noexec,relatime,hugetlb" 211 | }, 212 | { 213 | "volume": "cgroup", 214 | "path": "/sys/fs/cgroup/memory", 215 | "voltype": "cgroup", 216 | "options": "rw,nosuid,nodev,noexec,relatime,memory" 217 | }, 218 | { 219 | "volume": "cgroup", 220 | "path": "/sys/fs/cgroup/freezer", 221 | "voltype": "cgroup", 222 | "options": "rw,nosuid,nodev,noexec,relatime,freezer" 223 | }, 224 | { 225 | "volume": "cgroup", 226 | "path": "/sys/fs/cgroup/devices", 227 | "voltype": "cgroup", 228 | "options": "rw,nosuid,nodev,noexec,relatime,devices" 229 | }, 230 | { 231 | "volume": "cgroup", 232 | "path": "/sys/fs/cgroup/cpuset", 233 | "voltype": "cgroup", 234 | "options": "rw,nosuid,nodev,noexec,relatime,cpuset" 235 | }, 236 | { 237 | "volume": "cgroup", 238 | "path": "/sys/fs/cgroup/pids", 239 | "voltype": "cgroup", 240 | "options": "rw,nosuid,nodev,noexec,relatime,pids" 241 | }, 242 | { 243 | "volume": "cgroup", 244 | "path": "/sys/fs/cgroup/net_cls,net_prio", 245 | "voltype": "cgroup", 246 | "options": "rw,nosuid,nodev,noexec,relatime,net_cls,net_prio" 247 | }, 248 | { 249 | "volume": "systemd-1", 250 | "path": "/proc/sys/fs/binfmt_misc", 251 | "voltype": "autofs", 252 | "options": "rw,relatime,fd=29,pgrp=1,timeout=0,minproto=5,maxproto=5,direct,pipe_ino=3281" 253 | }, 254 | { 255 | "volume": "debugfs", 256 | "path": "/sys/kernel/debug", 257 | "voltype": "debugfs", 258 | "options": "rw,nosuid,nodev,noexec,relatime" 259 | }, 260 | { 261 | "volume": "tracefs", 262 | "path": "/sys/kernel/tracing", 263 | "voltype": "tracefs", 264 | "options": "rw,nosuid,nodev,noexec,relatime" 265 | }, 266 | { 267 | "volume": "mqueue", 268 | "path": "/dev/mqueue", 269 | "voltype": "mqueue", 270 | "options": "rw,nosuid,nodev,noexec,relatime" 271 | }, 272 | { 273 | "volume": "hugetlbfs", 274 | "path": "/dev/hugepages", 275 | "voltype": "hugetlbfs", 276 | "options": "rw,relatime,pagesize=2M" 277 | }, 278 | { 279 | "volume": "tmpfs", 280 | "path": "/tmp", 281 | "voltype": "tmpfs", 282 | "options": "rw,nosuid,nodev,size=8160484k,nr_inodes=409600" 283 | }, 284 | { 285 | "volume": "configfs", 286 | "path": "/sys/kernel/config", 287 | "voltype": "configfs", 288 | "options": "rw,nosuid,nodev,noexec,relatime" 289 | }, 290 | { 291 | "volume": "/dev/mapper/vgvol-games", 292 | "path": "/home/wojtek/games", 293 | "voltype": "ext4", 294 | "options": "rw,relatime" 295 | }, 296 | { 297 | "volume": "/dev/sde1", 298 | "path": "/boot", 299 | "voltype": "vfat", 300 | "options": "rw,relatime,fmask=0022,dmask=0022,codepage=437,iocharset=iso8859-1,shortname=mixed,utf8,errors=remount-ro" 301 | }, 302 | { 303 | "volume": "/dev/mapper/vgstor-media", 304 | "path": "/mnt/media", 305 | "voltype": "ext4", 306 | "options": "rw,relatime" 307 | }, 308 | { 309 | "volume": "/dev/mapper/vgstor-docs", 310 | "path": "/mnt/docs", 311 | "voltype": "ext4", 312 | "options": "rw,relatime" 313 | }, 314 | { 315 | "volume": "/dev/mapper/vgstor-rand", 316 | "path": "/mnt/rand", 317 | "voltype": "ext4", 318 | "options": "rw,relatime" 319 | }, 320 | { 321 | "volume": "/dev/mapper/vgstor-photos", 322 | "path": "/mnt/photos", 323 | "voltype": "ext4", 324 | "options": "rw,relatime" 325 | }, 326 | { 327 | "volume": "fusectl", 328 | "path": "/sys/fs/fuse/connections", 329 | "voltype": "fusectl", 330 | "options": "rw,nosuid,nodev,noexec,relatime" 331 | }, 332 | { 333 | "volume": "tmpfs", 334 | "path": "/run/user/1000", 335 | "voltype": "tmpfs", 336 | "options": "rw,nosuid,nodev,relatime,size=1632096k,nr_inodes=408024,mode=700,uid=1000,gid=1001" 337 | }, 338 | { 339 | "volume": "gvfsd-fuse", 340 | "path": "/run/user/1000/gvfs", 341 | "voltype": "fuse.gvfsd-fuse", 342 | "options": "rw,nosuid,nodev,relatime,user_id=1000,group_id=1001" 343 | } 344 | ], 345 | "interaces": [ 346 | { 347 | "name": "enp8s0", 348 | "ipv4": "192.168.0.1", 349 | "stat": { 350 | "rx_bytes": 1269591817, 351 | "rx_packets": 939218, 352 | "rx_errs": 0, 353 | "rx_drop": 0, 354 | "rx_fifo": 0, 355 | "rx_frame": 0, 356 | "rx_compressed": 0, 357 | "rx_multicast": 16616, 358 | "tx_bytes": 49752973, 359 | "tx_packets": 572721, 360 | "tx_errs": 0, 361 | "tx_drop": 0, 362 | "tx_fifo": 0, 363 | "tx_frame": 0, 364 | "tx_compressed": 0, 365 | "tx_multicast": 0 366 | }, 367 | "mtu": 1500, 368 | "mac_address": "70:85:c2:f9:9b:2a", 369 | "speed": 1000 370 | }, 371 | { 372 | "name": "lo", 373 | "ipv4": "127.0.0.1", 374 | "stat": { 375 | "rx_bytes": 432689, 376 | "rx_packets": 1402, 377 | "rx_errs": 0, 378 | "rx_drop": 0, 379 | "rx_fifo": 0, 380 | "rx_frame": 0, 381 | "rx_compressed": 0, 382 | "rx_multicast": 0, 383 | "tx_bytes": 432689, 384 | "tx_packets": 1402, 385 | "tx_errs": 0, 386 | "tx_drop": 0, 387 | "tx_fifo": 0, 388 | "tx_frame": 0, 389 | "tx_compressed": 0, 390 | "tx_multicast": 0 391 | }, 392 | "mtu": 65536, 393 | "mac_address": "00:00:00:00:00:00", 394 | "speed": 0 395 | } 396 | ], 397 | "storage_devices": [ 398 | { 399 | "info": { 400 | "dev": "sdd", 401 | "size": 3907029168, 402 | "maj": 8, 403 | "min": 48, 404 | "block_size": 4096, 405 | "stat": { 406 | "read_ios": 319, 407 | "read_merges": 69, 408 | "read_sectors": 6662, 409 | "read_ticks": 1761, 410 | "write_ios": 81, 411 | "write_merges": 3, 412 | "write_sectors": 454, 413 | "write_ticks": 3492, 414 | "in_flight": 0, 415 | "io_ticks": 3954, 416 | "time_in_queue": 8540, 417 | "discard_ios": 0, 418 | "discard_merges": 0, 419 | "discard_sectors": 0, 420 | "discard_ticks": 0 421 | } 422 | }, 423 | "model": "ST2000DM008-2FR1", 424 | "vendor": "ATA", 425 | "state": "running", 426 | "partitions": [ 427 | { 428 | "info": { 429 | "dev": "sdd1", 430 | "size": 3907027087, 431 | "maj": 8, 432 | "min": 49, 433 | "block_size": 512, 434 | "stat": { 435 | "read_ios": 189, 436 | "read_merges": 69, 437 | "read_sectors": 3888, 438 | "read_ticks": 1327, 439 | "write_ios": 66, 440 | "write_merges": 3, 441 | "write_sectors": 454, 442 | "write_ticks": 2782, 443 | "in_flight": 0, 444 | "io_ticks": 2897, 445 | "time_in_queue": 4109, 446 | "discard_ios": 0, 447 | "discard_merges": 0, 448 | "discard_sectors": 0, 449 | "discard_ticks": 0 450 | } 451 | }, 452 | "holder_mds": null, 453 | "holder_dms": null 454 | } 455 | ] 456 | }, 457 | { 458 | "info": { 459 | "dev": "sdb", 460 | "size": 234441648, 461 | "maj": 8, 462 | "min": 16, 463 | "block_size": 4096, 464 | "stat": { 465 | "read_ios": 547, 466 | "read_merges": 0, 467 | "read_sectors": 10556, 468 | "read_ticks": 5143, 469 | "write_ios": 0, 470 | "write_merges": 0, 471 | "write_sectors": 0, 472 | "write_ticks": 0, 473 | "in_flight": 0, 474 | "io_ticks": 5390, 475 | "time_in_queue": 5143, 476 | "discard_ios": 0, 477 | "discard_merges": 0, 478 | "discard_sectors": 0, 479 | "discard_ticks": 0 480 | } 481 | }, 482 | "model": "KINGSTON SV300S3", 483 | "vendor": "ATA", 484 | "state": "running", 485 | "partitions": [ 486 | { 487 | "info": { 488 | "dev": "sdb2", 489 | "size": 234405888, 490 | "maj": 8, 491 | "min": 18, 492 | "block_size": 4096, 493 | "stat": { 494 | "read_ios": 68, 495 | "read_merges": 0, 496 | "read_sectors": 4752, 497 | "read_ticks": 26, 498 | "write_ios": 0, 499 | "write_merges": 0, 500 | "write_sectors": 0, 501 | "write_ticks": 0, 502 | "in_flight": 0, 503 | "io_ticks": 40, 504 | "time_in_queue": 26, 505 | "discard_ios": 0, 506 | "discard_merges": 0, 507 | "discard_sectors": 0, 508 | "discard_ticks": 0 509 | } 510 | }, 511 | "holder_mds": null, 512 | "holder_dms": null 513 | }, 514 | { 515 | "info": { 516 | "dev": "sdb1", 517 | "size": 32768, 518 | "maj": 8, 519 | "min": 17, 520 | "block_size": 4096, 521 | "stat": { 522 | "read_ios": 54, 523 | "read_merges": 0, 524 | "read_sectors": 1728, 525 | "read_ticks": 13, 526 | "write_ios": 0, 527 | "write_merges": 0, 528 | "write_sectors": 0, 529 | "write_ticks": 0, 530 | "in_flight": 0, 531 | "io_ticks": 27, 532 | "time_in_queue": 13, 533 | "discard_ios": 0, 534 | "discard_merges": 0, 535 | "discard_sectors": 0, 536 | "discard_ticks": 0 537 | } 538 | }, 539 | "holder_mds": null, 540 | "holder_dms": null 541 | } 542 | ] 543 | }, 544 | { 545 | "info": { 546 | "dev": "sde", 547 | "size": 234441648, 548 | "maj": 8, 549 | "min": 64, 550 | "block_size": 4096, 551 | "stat": { 552 | "read_ios": 47668, 553 | "read_merges": 24948, 554 | "read_sectors": 4255605, 555 | "read_ticks": 29998, 556 | "write_ios": 848203, 557 | "write_merges": 252941, 558 | "write_sectors": 27185833, 559 | "write_ticks": 629558, 560 | "in_flight": 0, 561 | "io_ticks": 231890, 562 | "time_in_queue": 673612, 563 | "discard_ios": 0, 564 | "discard_merges": 0, 565 | "discard_sectors": 0, 566 | "discard_ticks": 0 567 | } 568 | }, 569 | "model": "KINGSTON SV300S3", 570 | "vendor": "ATA", 571 | "state": "running", 572 | "partitions": [ 573 | { 574 | "info": { 575 | "dev": "sde2", 576 | "size": 233415567, 577 | "maj": 8, 578 | "min": 66, 579 | "block_size": 512, 580 | "stat": { 581 | "read_ios": 46946, 582 | "read_merges": 24700, 583 | "read_sectors": 4238608, 584 | "read_ticks": 25508, 585 | "write_ios": 831951, 586 | "write_merges": 252941, 587 | "write_sectors": 27185832, 588 | "write_ticks": 617000, 589 | "in_flight": 0, 590 | "io_ticks": 227080, 591 | "time_in_queue": 642508, 592 | "discard_ios": 0, 593 | "discard_merges": 0, 594 | "discard_sectors": 0, 595 | "discard_ticks": 0 596 | } 597 | }, 598 | "holder_mds": null, 599 | "holder_dms": null 600 | }, 601 | { 602 | "info": { 603 | "dev": "sde1", 604 | "size": 1024000, 605 | "maj": 8, 606 | "min": 65, 607 | "block_size": 512, 608 | "stat": { 609 | "read_ios": 331, 610 | "read_merges": 248, 611 | "read_sectors": 14105, 612 | "read_ticks": 144, 613 | "write_ios": 1, 614 | "write_merges": 0, 615 | "write_sectors": 1, 616 | "write_ticks": 0, 617 | "in_flight": 0, 618 | "io_ticks": 147, 619 | "time_in_queue": 144, 620 | "discard_ios": 0, 621 | "discard_merges": 0, 622 | "discard_sectors": 0, 623 | "discard_ticks": 0 624 | } 625 | }, 626 | "holder_mds": null, 627 | "holder_dms": null 628 | } 629 | ] 630 | }, 631 | { 632 | "info": { 633 | "dev": "sdc", 634 | "size": 3907029168, 635 | "maj": 8, 636 | "min": 32, 637 | "block_size": 4096, 638 | "stat": { 639 | "read_ios": 737, 640 | "read_merges": 0, 641 | "read_sectors": 19654, 642 | "read_ticks": 35465, 643 | "write_ios": 11, 644 | "write_merges": 1, 645 | "write_sectors": 48, 646 | "write_ticks": 78, 647 | "in_flight": 0, 648 | "io_ticks": 33897, 649 | "time_in_queue": 35620, 650 | "discard_ios": 0, 651 | "discard_merges": 0, 652 | "discard_sectors": 0, 653 | "discard_ticks": 0 654 | } 655 | }, 656 | "model": "WDC WD20EARX-00P", 657 | "vendor": "ATA", 658 | "state": "running", 659 | "partitions": [ 660 | { 661 | "info": { 662 | "dev": "sdc2", 663 | "size": 2648735920, 664 | "maj": 8, 665 | "min": 34, 666 | "block_size": 4096, 667 | "stat": { 668 | "read_ios": 291, 669 | "read_merges": 0, 670 | "read_sectors": 12130, 671 | "read_ticks": 3428, 672 | "write_ios": 5, 673 | "write_merges": 1, 674 | "write_sectors": 48, 675 | "write_ticks": 29, 676 | "in_flight": 0, 677 | "io_ticks": 1644, 678 | "time_in_queue": 3457, 679 | "discard_ios": 0, 680 | "discard_merges": 0, 681 | "discard_sectors": 0, 682 | "discard_ticks": 0 683 | } 684 | }, 685 | "holder_mds": null, 686 | "holder_dms": null 687 | }, 688 | { 689 | "info": { 690 | "dev": "sdc1", 691 | "size": 1258289152, 692 | "maj": 8, 693 | "min": 33, 694 | "block_size": 4096, 695 | "stat": { 696 | "read_ios": 66, 697 | "read_merges": 0, 698 | "read_sectors": 4736, 699 | "read_ticks": 135, 700 | "write_ios": 0, 701 | "write_merges": 0, 702 | "write_sectors": 0, 703 | "write_ticks": 0, 704 | "in_flight": 0, 705 | "io_ticks": 150, 706 | "time_in_queue": 135, 707 | "discard_ios": 0, 708 | "discard_merges": 0, 709 | "discard_sectors": 0, 710 | "discard_ticks": 0 711 | } 712 | }, 713 | "holder_mds": null, 714 | "holder_dms": null 715 | } 716 | ] 717 | }, 718 | { 719 | "info": { 720 | "dev": "sda", 721 | "size": 3907029168, 722 | "maj": 8, 723 | "min": 0, 724 | "block_size": 4096, 725 | "stat": { 726 | "read_ios": 401, 727 | "read_merges": 48, 728 | "read_sectors": 10367, 729 | "read_ticks": 3787, 730 | "write_ios": 81, 731 | "write_merges": 3, 732 | "write_sectors": 454, 733 | "write_ticks": 4048, 734 | "in_flight": 0, 735 | "io_ticks": 5284, 736 | "time_in_queue": 10973, 737 | "discard_ios": 0, 738 | "discard_merges": 0, 739 | "discard_sectors": 0, 740 | "discard_ticks": 0 741 | } 742 | }, 743 | "model": "ST2000DM008-2FR1", 744 | "vendor": "ATA", 745 | "state": "running", 746 | "partitions": [ 747 | { 748 | "info": { 749 | "dev": "sda1", 750 | "size": 3907027087, 751 | "maj": 8, 752 | "min": 1, 753 | "block_size": 512, 754 | "stat": { 755 | "read_ios": 271, 756 | "read_merges": 48, 757 | "read_sectors": 7593, 758 | "read_ticks": 3322, 759 | "write_ios": 66, 760 | "write_merges": 3, 761 | "write_sectors": 454, 762 | "write_ticks": 3696, 763 | "in_flight": 0, 764 | "io_ticks": 4520, 765 | "time_in_queue": 7018, 766 | "discard_ios": 0, 767 | "discard_merges": 0, 768 | "discard_sectors": 0, 769 | "discard_ticks": 0 770 | } 771 | }, 772 | "holder_mds": null, 773 | "holder_dms": null 774 | } 775 | ] 776 | } 777 | ], 778 | "multiple_device_storages": [ 779 | { 780 | "info": { 781 | "dev": "md0", 782 | "size": 3906762880, 783 | "maj": 9, 784 | "min": 0, 785 | "block_size": 4096, 786 | "stat": { 787 | "read_ios": 413, 788 | "read_merges": 0, 789 | "read_sectors": 10400, 790 | "read_ticks": 0, 791 | "write_ios": 32, 792 | "write_merges": 0, 793 | "write_sectors": 136, 794 | "write_ticks": 0, 795 | "in_flight": 0, 796 | "io_ticks": 0, 797 | "time_in_queue": 0, 798 | "discard_ios": 0, 799 | "discard_merges": 0, 800 | "discard_sectors": 0, 801 | "discard_ticks": 0 802 | } 803 | }, 804 | "level": "raid1", 805 | "slave_parts": [ 806 | { 807 | "info": { 808 | "dev": "sdd1", 809 | "size": 3907027087, 810 | "maj": 8, 811 | "min": 49, 812 | "block_size": 512, 813 | "stat": { 814 | "read_ios": 189, 815 | "read_merges": 69, 816 | "read_sectors": 3888, 817 | "read_ticks": 1327, 818 | "write_ios": 66, 819 | "write_merges": 3, 820 | "write_sectors": 454, 821 | "write_ticks": 2782, 822 | "in_flight": 0, 823 | "io_ticks": 2897, 824 | "time_in_queue": 4109, 825 | "discard_ios": 0, 826 | "discard_merges": 0, 827 | "discard_sectors": 0, 828 | "discard_ticks": 0 829 | } 830 | }, 831 | "holder_mds": null, 832 | "holder_dms": null 833 | }, 834 | { 835 | "info": { 836 | "dev": "sda1", 837 | "size": 3907027087, 838 | "maj": 8, 839 | "min": 1, 840 | "block_size": 512, 841 | "stat": { 842 | "read_ios": 271, 843 | "read_merges": 48, 844 | "read_sectors": 7593, 845 | "read_ticks": 3322, 846 | "write_ios": 66, 847 | "write_merges": 3, 848 | "write_sectors": 454, 849 | "write_ticks": 3696, 850 | "in_flight": 0, 851 | "io_ticks": 4520, 852 | "time_in_queue": 7018, 853 | "discard_ios": 0, 854 | "discard_merges": 0, 855 | "discard_sectors": 0, 856 | "discard_ticks": 0 857 | } 858 | }, 859 | "holder_mds": null, 860 | "holder_dms": null 861 | } 862 | ], 863 | "holder_devices": [ 864 | { 865 | "info": { 866 | "dev": "dm-6", 867 | "size": 209715200, 868 | "maj": 254, 869 | "min": 6, 870 | "block_size": 4096, 871 | "stat": { 872 | "read_ios": 66, 873 | "read_merges": 0, 874 | "read_sectors": 2226, 875 | "read_ticks": 1986, 876 | "write_ios": 4, 877 | "write_merges": 0, 878 | "write_sectors": 8, 879 | "write_ticks": 356, 880 | "in_flight": 0, 881 | "io_ticks": 1047, 882 | "time_in_queue": 2343, 883 | "discard_ios": 0, 884 | "discard_merges": 0, 885 | "discard_sectors": 0, 886 | "discard_ticks": 0 887 | } 888 | }, 889 | "name": "vgstor-rand", 890 | "uuid": "LVM-3Wn54nieFFkISN2T3YodfGJV2jkG95EGYieQNcZKKxZHkPIoA25iUAGm0hfo0IW9", 891 | "slave_parts": null, 892 | "slave_mds": null 893 | }, 894 | { 895 | "info": { 896 | "dev": "dm-4", 897 | "size": 629145600, 898 | "maj": 254, 899 | "min": 4, 900 | "block_size": 4096, 901 | "stat": { 902 | "read_ios": 107, 903 | "read_merges": 0, 904 | "read_sectors": 2610, 905 | "read_ticks": 3966, 906 | "write_ios": 20, 907 | "write_merges": 0, 908 | "write_sectors": 136, 909 | "write_ticks": 2433, 910 | "in_flight": 0, 911 | "io_ticks": 2297, 912 | "time_in_queue": 6399, 913 | "discard_ios": 0, 914 | "discard_merges": 0, 915 | "discard_sectors": 0, 916 | "discard_ticks": 0 917 | } 918 | }, 919 | "name": "vgstor-photos", 920 | "uuid": "LVM-3Wn54nieFFkISN2T3YodfGJV2jkG95EGFS3UxLCTMNcHyjP3KaYPAmcByH9cdqxL", 921 | "slave_parts": null, 922 | "slave_mds": null 923 | }, 924 | { 925 | "info": { 926 | "dev": "dm-5", 927 | "size": 209715200, 928 | "maj": 254, 929 | "min": 5, 930 | "block_size": 4096, 931 | "stat": { 932 | "read_ios": 66, 933 | "read_merges": 0, 934 | "read_sectors": 2226, 935 | "read_ticks": 749, 936 | "write_ios": 4, 937 | "write_merges": 0, 938 | "write_sectors": 8, 939 | "write_ticks": 629, 940 | "in_flight": 0, 941 | "io_ticks": 1327, 942 | "time_in_queue": 1379, 943 | "discard_ios": 0, 944 | "discard_merges": 0, 945 | "discard_sectors": 0, 946 | "discard_ticks": 0 947 | } 948 | }, 949 | "name": "vgstor-docs", 950 | "uuid": "LVM-3Wn54nieFFkISN2T3YodfGJV2jkG95EGsh5G3o5enDMpks44ILBRayoGTjbiFzfp", 951 | "slave_parts": null, 952 | "slave_mds": null 953 | }, 954 | { 955 | "info": { 956 | "dev": "dm-3", 957 | "size": 1677721600, 958 | "maj": 254, 959 | "min": 3, 960 | "block_size": 4096, 961 | "stat": { 962 | "read_ios": 154, 963 | "read_merges": 0, 964 | "read_sectors": 2930, 965 | "read_ticks": 1219, 966 | "write_ios": 4, 967 | "write_merges": 0, 968 | "write_sectors": 8, 969 | "write_ticks": 553, 970 | "in_flight": 0, 971 | "io_ticks": 1347, 972 | "time_in_queue": 1773, 973 | "discard_ios": 0, 974 | "discard_merges": 0, 975 | "discard_sectors": 0, 976 | "discard_ticks": 0 977 | } 978 | }, 979 | "name": "vgstor-media", 980 | "uuid": "LVM-3Wn54nieFFkISN2T3YodfGJV2jkG95EGj23hIRRpNbd2YUuOLxrJpDEMldcjZhaR", 981 | "slave_parts": null, 982 | "slave_mds": null 983 | } 984 | ] 985 | } 986 | ], 987 | "device_mappers": [ 988 | { 989 | "info": { 990 | "dev": "dm-1", 991 | "size": 419430400, 992 | "maj": 254, 993 | "min": 1, 994 | "block_size": 4096, 995 | "stat": { 996 | "read_ios": 127, 997 | "read_merges": 0, 998 | "read_sectors": 4418, 999 | "read_ticks": 1236, 1000 | "write_ios": 10, 1001 | "write_merges": 0, 1002 | "write_sectors": 56, 1003 | "write_ticks": 76, 1004 | "in_flight": 0, 1005 | "io_ticks": 900, 1006 | "time_in_queue": 1313, 1007 | "discard_ios": 0, 1008 | "discard_merges": 0, 1009 | "discard_sectors": 0, 1010 | "discard_ticks": 0 1011 | } 1012 | }, 1013 | "name": "vgvol-games", 1014 | "uuid": "LVM-D0J4mWtV7c3vTbjLQkTcCp3ltYxfuIXGFrvgLvv3ZK8VxVvrZ2dsaqfk2necCd2M", 1015 | "slave_parts": [ 1016 | { 1017 | "info": { 1018 | "dev": "sdc2", 1019 | "size": 2648735920, 1020 | "maj": 8, 1021 | "min": 34, 1022 | "block_size": 4096, 1023 | "stat": { 1024 | "read_ios": 291, 1025 | "read_merges": 0, 1026 | "read_sectors": 12130, 1027 | "read_ticks": 3428, 1028 | "write_ios": 5, 1029 | "write_merges": 1, 1030 | "write_sectors": 48, 1031 | "write_ticks": 29, 1032 | "in_flight": 0, 1033 | "io_ticks": 1644, 1034 | "time_in_queue": 3457, 1035 | "discard_ios": 0, 1036 | "discard_merges": 0, 1037 | "discard_sectors": 0, 1038 | "discard_ticks": 0 1039 | } 1040 | }, 1041 | "holder_mds": null, 1042 | "holder_dms": null 1043 | } 1044 | ], 1045 | "slave_mds": null 1046 | }, 1047 | { 1048 | "info": { 1049 | "dev": "dm-6", 1050 | "size": 209715200, 1051 | "maj": 254, 1052 | "min": 6, 1053 | "block_size": 4096, 1054 | "stat": { 1055 | "read_ios": 66, 1056 | "read_merges": 0, 1057 | "read_sectors": 2226, 1058 | "read_ticks": 1986, 1059 | "write_ios": 4, 1060 | "write_merges": 0, 1061 | "write_sectors": 8, 1062 | "write_ticks": 356, 1063 | "in_flight": 0, 1064 | "io_ticks": 1047, 1065 | "time_in_queue": 2343, 1066 | "discard_ios": 0, 1067 | "discard_merges": 0, 1068 | "discard_sectors": 0, 1069 | "discard_ticks": 0 1070 | } 1071 | }, 1072 | "name": "vgstor-rand", 1073 | "uuid": "LVM-3Wn54nieFFkISN2T3YodfGJV2jkG95EGYieQNcZKKxZHkPIoA25iUAGm0hfo0IW9", 1074 | "slave_parts": null, 1075 | "slave_mds": [ 1076 | { 1077 | "info": { 1078 | "dev": "md0", 1079 | "size": 3906762880, 1080 | "maj": 9, 1081 | "min": 0, 1082 | "block_size": 4096, 1083 | "stat": { 1084 | "read_ios": 413, 1085 | "read_merges": 0, 1086 | "read_sectors": 10400, 1087 | "read_ticks": 0, 1088 | "write_ios": 32, 1089 | "write_merges": 0, 1090 | "write_sectors": 136, 1091 | "write_ticks": 0, 1092 | "in_flight": 0, 1093 | "io_ticks": 0, 1094 | "time_in_queue": 0, 1095 | "discard_ios": 0, 1096 | "discard_merges": 0, 1097 | "discard_sectors": 0, 1098 | "discard_ticks": 0 1099 | } 1100 | }, 1101 | "level": "raid1", 1102 | "slave_parts": [ 1103 | { 1104 | "info": { 1105 | "dev": "sdd1", 1106 | "size": 3907027087, 1107 | "maj": 8, 1108 | "min": 49, 1109 | "block_size": 512, 1110 | "stat": { 1111 | "read_ios": 189, 1112 | "read_merges": 69, 1113 | "read_sectors": 3888, 1114 | "read_ticks": 1327, 1115 | "write_ios": 66, 1116 | "write_merges": 3, 1117 | "write_sectors": 454, 1118 | "write_ticks": 2782, 1119 | "in_flight": 0, 1120 | "io_ticks": 2897, 1121 | "time_in_queue": 4109, 1122 | "discard_ios": 0, 1123 | "discard_merges": 0, 1124 | "discard_sectors": 0, 1125 | "discard_ticks": 0 1126 | } 1127 | }, 1128 | "holder_mds": null, 1129 | "holder_dms": null 1130 | }, 1131 | { 1132 | "info": { 1133 | "dev": "sda1", 1134 | "size": 3907027087, 1135 | "maj": 8, 1136 | "min": 1, 1137 | "block_size": 512, 1138 | "stat": { 1139 | "read_ios": 271, 1140 | "read_merges": 48, 1141 | "read_sectors": 7593, 1142 | "read_ticks": 3322, 1143 | "write_ios": 66, 1144 | "write_merges": 3, 1145 | "write_sectors": 454, 1146 | "write_ticks": 3696, 1147 | "in_flight": 0, 1148 | "io_ticks": 4520, 1149 | "time_in_queue": 7018, 1150 | "discard_ios": 0, 1151 | "discard_merges": 0, 1152 | "discard_sectors": 0, 1153 | "discard_ticks": 0 1154 | } 1155 | }, 1156 | "holder_mds": null, 1157 | "holder_dms": null 1158 | } 1159 | ], 1160 | "holder_devices": [ 1161 | { 1162 | "info": { 1163 | "dev": "dm-6", 1164 | "size": 209715200, 1165 | "maj": 254, 1166 | "min": 6, 1167 | "block_size": 4096, 1168 | "stat": { 1169 | "read_ios": 66, 1170 | "read_merges": 0, 1171 | "read_sectors": 2226, 1172 | "read_ticks": 1986, 1173 | "write_ios": 4, 1174 | "write_merges": 0, 1175 | "write_sectors": 8, 1176 | "write_ticks": 356, 1177 | "in_flight": 0, 1178 | "io_ticks": 1047, 1179 | "time_in_queue": 2343, 1180 | "discard_ios": 0, 1181 | "discard_merges": 0, 1182 | "discard_sectors": 0, 1183 | "discard_ticks": 0 1184 | } 1185 | }, 1186 | "name": "vgstor-rand", 1187 | "uuid": "LVM-3Wn54nieFFkISN2T3YodfGJV2jkG95EGYieQNcZKKxZHkPIoA25iUAGm0hfo0IW9", 1188 | "slave_parts": null, 1189 | "slave_mds": null 1190 | }, 1191 | { 1192 | "info": { 1193 | "dev": "dm-4", 1194 | "size": 629145600, 1195 | "maj": 254, 1196 | "min": 4, 1197 | "block_size": 4096, 1198 | "stat": { 1199 | "read_ios": 107, 1200 | "read_merges": 0, 1201 | "read_sectors": 2610, 1202 | "read_ticks": 3966, 1203 | "write_ios": 20, 1204 | "write_merges": 0, 1205 | "write_sectors": 136, 1206 | "write_ticks": 2433, 1207 | "in_flight": 0, 1208 | "io_ticks": 2297, 1209 | "time_in_queue": 6399, 1210 | "discard_ios": 0, 1211 | "discard_merges": 0, 1212 | "discard_sectors": 0, 1213 | "discard_ticks": 0 1214 | } 1215 | }, 1216 | "name": "vgstor-photos", 1217 | "uuid": "LVM-3Wn54nieFFkISN2T3YodfGJV2jkG95EGFS3UxLCTMNcHyjP3KaYPAmcByH9cdqxL", 1218 | "slave_parts": null, 1219 | "slave_mds": null 1220 | }, 1221 | { 1222 | "info": { 1223 | "dev": "dm-5", 1224 | "size": 209715200, 1225 | "maj": 254, 1226 | "min": 5, 1227 | "block_size": 4096, 1228 | "stat": { 1229 | "read_ios": 66, 1230 | "read_merges": 0, 1231 | "read_sectors": 2226, 1232 | "read_ticks": 749, 1233 | "write_ios": 4, 1234 | "write_merges": 0, 1235 | "write_sectors": 8, 1236 | "write_ticks": 629, 1237 | "in_flight": 0, 1238 | "io_ticks": 1327, 1239 | "time_in_queue": 1379, 1240 | "discard_ios": 0, 1241 | "discard_merges": 0, 1242 | "discard_sectors": 0, 1243 | "discard_ticks": 0 1244 | } 1245 | }, 1246 | "name": "vgstor-docs", 1247 | "uuid": "LVM-3Wn54nieFFkISN2T3YodfGJV2jkG95EGsh5G3o5enDMpks44ILBRayoGTjbiFzfp", 1248 | "slave_parts": null, 1249 | "slave_mds": null 1250 | }, 1251 | { 1252 | "info": { 1253 | "dev": "dm-3", 1254 | "size": 1677721600, 1255 | "maj": 254, 1256 | "min": 3, 1257 | "block_size": 4096, 1258 | "stat": { 1259 | "read_ios": 154, 1260 | "read_merges": 0, 1261 | "read_sectors": 2930, 1262 | "read_ticks": 1219, 1263 | "write_ios": 4, 1264 | "write_merges": 0, 1265 | "write_sectors": 8, 1266 | "write_ticks": 553, 1267 | "in_flight": 0, 1268 | "io_ticks": 1347, 1269 | "time_in_queue": 1773, 1270 | "discard_ios": 0, 1271 | "discard_merges": 0, 1272 | "discard_sectors": 0, 1273 | "discard_ticks": 0 1274 | } 1275 | }, 1276 | "name": "vgstor-media", 1277 | "uuid": "LVM-3Wn54nieFFkISN2T3YodfGJV2jkG95EGj23hIRRpNbd2YUuOLxrJpDEMldcjZhaR", 1278 | "slave_parts": null, 1279 | "slave_mds": null 1280 | } 1281 | ] 1282 | } 1283 | ] 1284 | }, 1285 | { 1286 | "info": { 1287 | "dev": "dm-4", 1288 | "size": 629145600, 1289 | "maj": 254, 1290 | "min": 4, 1291 | "block_size": 4096, 1292 | "stat": { 1293 | "read_ios": 107, 1294 | "read_merges": 0, 1295 | "read_sectors": 2610, 1296 | "read_ticks": 3966, 1297 | "write_ios": 20, 1298 | "write_merges": 0, 1299 | "write_sectors": 136, 1300 | "write_ticks": 2433, 1301 | "in_flight": 0, 1302 | "io_ticks": 2297, 1303 | "time_in_queue": 6399, 1304 | "discard_ios": 0, 1305 | "discard_merges": 0, 1306 | "discard_sectors": 0, 1307 | "discard_ticks": 0 1308 | } 1309 | }, 1310 | "name": "vgstor-photos", 1311 | "uuid": "LVM-3Wn54nieFFkISN2T3YodfGJV2jkG95EGFS3UxLCTMNcHyjP3KaYPAmcByH9cdqxL", 1312 | "slave_parts": null, 1313 | "slave_mds": [ 1314 | { 1315 | "info": { 1316 | "dev": "md0", 1317 | "size": 3906762880, 1318 | "maj": 9, 1319 | "min": 0, 1320 | "block_size": 4096, 1321 | "stat": { 1322 | "read_ios": 413, 1323 | "read_merges": 0, 1324 | "read_sectors": 10400, 1325 | "read_ticks": 0, 1326 | "write_ios": 32, 1327 | "write_merges": 0, 1328 | "write_sectors": 136, 1329 | "write_ticks": 0, 1330 | "in_flight": 0, 1331 | "io_ticks": 0, 1332 | "time_in_queue": 0, 1333 | "discard_ios": 0, 1334 | "discard_merges": 0, 1335 | "discard_sectors": 0, 1336 | "discard_ticks": 0 1337 | } 1338 | }, 1339 | "level": "raid1", 1340 | "slave_parts": [ 1341 | { 1342 | "info": { 1343 | "dev": "sdd1", 1344 | "size": 3907027087, 1345 | "maj": 8, 1346 | "min": 49, 1347 | "block_size": 512, 1348 | "stat": { 1349 | "read_ios": 189, 1350 | "read_merges": 69, 1351 | "read_sectors": 3888, 1352 | "read_ticks": 1327, 1353 | "write_ios": 66, 1354 | "write_merges": 3, 1355 | "write_sectors": 454, 1356 | "write_ticks": 2782, 1357 | "in_flight": 0, 1358 | "io_ticks": 2897, 1359 | "time_in_queue": 4109, 1360 | "discard_ios": 0, 1361 | "discard_merges": 0, 1362 | "discard_sectors": 0, 1363 | "discard_ticks": 0 1364 | } 1365 | }, 1366 | "holder_mds": null, 1367 | "holder_dms": null 1368 | }, 1369 | { 1370 | "info": { 1371 | "dev": "sda1", 1372 | "size": 3907027087, 1373 | "maj": 8, 1374 | "min": 1, 1375 | "block_size": 512, 1376 | "stat": { 1377 | "read_ios": 271, 1378 | "read_merges": 48, 1379 | "read_sectors": 7593, 1380 | "read_ticks": 3322, 1381 | "write_ios": 66, 1382 | "write_merges": 3, 1383 | "write_sectors": 454, 1384 | "write_ticks": 3696, 1385 | "in_flight": 0, 1386 | "io_ticks": 4520, 1387 | "time_in_queue": 7018, 1388 | "discard_ios": 0, 1389 | "discard_merges": 0, 1390 | "discard_sectors": 0, 1391 | "discard_ticks": 0 1392 | } 1393 | }, 1394 | "holder_mds": null, 1395 | "holder_dms": null 1396 | } 1397 | ], 1398 | "holder_devices": [ 1399 | { 1400 | "info": { 1401 | "dev": "dm-6", 1402 | "size": 209715200, 1403 | "maj": 254, 1404 | "min": 6, 1405 | "block_size": 4096, 1406 | "stat": { 1407 | "read_ios": 66, 1408 | "read_merges": 0, 1409 | "read_sectors": 2226, 1410 | "read_ticks": 1986, 1411 | "write_ios": 4, 1412 | "write_merges": 0, 1413 | "write_sectors": 8, 1414 | "write_ticks": 356, 1415 | "in_flight": 0, 1416 | "io_ticks": 1047, 1417 | "time_in_queue": 2343, 1418 | "discard_ios": 0, 1419 | "discard_merges": 0, 1420 | "discard_sectors": 0, 1421 | "discard_ticks": 0 1422 | } 1423 | }, 1424 | "name": "vgstor-rand", 1425 | "uuid": "LVM-3Wn54nieFFkISN2T3YodfGJV2jkG95EGYieQNcZKKxZHkPIoA25iUAGm0hfo0IW9", 1426 | "slave_parts": null, 1427 | "slave_mds": null 1428 | }, 1429 | { 1430 | "info": { 1431 | "dev": "dm-4", 1432 | "size": 629145600, 1433 | "maj": 254, 1434 | "min": 4, 1435 | "block_size": 4096, 1436 | "stat": { 1437 | "read_ios": 107, 1438 | "read_merges": 0, 1439 | "read_sectors": 2610, 1440 | "read_ticks": 3966, 1441 | "write_ios": 20, 1442 | "write_merges": 0, 1443 | "write_sectors": 136, 1444 | "write_ticks": 2433, 1445 | "in_flight": 0, 1446 | "io_ticks": 2297, 1447 | "time_in_queue": 6399, 1448 | "discard_ios": 0, 1449 | "discard_merges": 0, 1450 | "discard_sectors": 0, 1451 | "discard_ticks": 0 1452 | } 1453 | }, 1454 | "name": "vgstor-photos", 1455 | "uuid": "LVM-3Wn54nieFFkISN2T3YodfGJV2jkG95EGFS3UxLCTMNcHyjP3KaYPAmcByH9cdqxL", 1456 | "slave_parts": null, 1457 | "slave_mds": null 1458 | }, 1459 | { 1460 | "info": { 1461 | "dev": "dm-5", 1462 | "size": 209715200, 1463 | "maj": 254, 1464 | "min": 5, 1465 | "block_size": 4096, 1466 | "stat": { 1467 | "read_ios": 66, 1468 | "read_merges": 0, 1469 | "read_sectors": 2226, 1470 | "read_ticks": 749, 1471 | "write_ios": 4, 1472 | "write_merges": 0, 1473 | "write_sectors": 8, 1474 | "write_ticks": 629, 1475 | "in_flight": 0, 1476 | "io_ticks": 1327, 1477 | "time_in_queue": 1379, 1478 | "discard_ios": 0, 1479 | "discard_merges": 0, 1480 | "discard_sectors": 0, 1481 | "discard_ticks": 0 1482 | } 1483 | }, 1484 | "name": "vgstor-docs", 1485 | "uuid": "LVM-3Wn54nieFFkISN2T3YodfGJV2jkG95EGsh5G3o5enDMpks44ILBRayoGTjbiFzfp", 1486 | "slave_parts": null, 1487 | "slave_mds": null 1488 | }, 1489 | { 1490 | "info": { 1491 | "dev": "dm-3", 1492 | "size": 1677721600, 1493 | "maj": 254, 1494 | "min": 3, 1495 | "block_size": 4096, 1496 | "stat": { 1497 | "read_ios": 154, 1498 | "read_merges": 0, 1499 | "read_sectors": 2930, 1500 | "read_ticks": 1219, 1501 | "write_ios": 4, 1502 | "write_merges": 0, 1503 | "write_sectors": 8, 1504 | "write_ticks": 553, 1505 | "in_flight": 0, 1506 | "io_ticks": 1347, 1507 | "time_in_queue": 1773, 1508 | "discard_ios": 0, 1509 | "discard_merges": 0, 1510 | "discard_sectors": 0, 1511 | "discard_ticks": 0 1512 | } 1513 | }, 1514 | "name": "vgstor-media", 1515 | "uuid": "LVM-3Wn54nieFFkISN2T3YodfGJV2jkG95EGj23hIRRpNbd2YUuOLxrJpDEMldcjZhaR", 1516 | "slave_parts": null, 1517 | "slave_mds": null 1518 | } 1519 | ] 1520 | } 1521 | ] 1522 | }, 1523 | { 1524 | "info": { 1525 | "dev": "dm-2", 1526 | "size": 233398272, 1527 | "maj": 254, 1528 | "min": 2, 1529 | "block_size": 4096, 1530 | "stat": { 1531 | "read_ios": 71596, 1532 | "read_merges": 0, 1533 | "read_sectors": 4237490, 1534 | "read_ticks": 52724, 1535 | "write_ios": 1096894, 1536 | "write_merges": 0, 1537 | "write_sectors": 27309456, 1538 | "write_ticks": 1155000, 1539 | "in_flight": 0, 1540 | "io_ticks": 225740, 1541 | "time_in_queue": 1207725, 1542 | "discard_ios": 0, 1543 | "discard_merges": 0, 1544 | "discard_sectors": 0, 1545 | "discard_ticks": 0 1546 | } 1547 | }, 1548 | "name": "vgmain-root", 1549 | "uuid": "LVM-btxwpaK0pT59m3ftQrM0svBNT5524uoORWORdOWj3UnLudihVXhvTbZpfhFfRtek", 1550 | "slave_parts": [ 1551 | { 1552 | "info": { 1553 | "dev": "sde2", 1554 | "size": 233415567, 1555 | "maj": 8, 1556 | "min": 66, 1557 | "block_size": 512, 1558 | "stat": { 1559 | "read_ios": 46946, 1560 | "read_merges": 24700, 1561 | "read_sectors": 4238608, 1562 | "read_ticks": 25508, 1563 | "write_ios": 831951, 1564 | "write_merges": 252941, 1565 | "write_sectors": 27185832, 1566 | "write_ticks": 617000, 1567 | "in_flight": 0, 1568 | "io_ticks": 227080, 1569 | "time_in_queue": 642508, 1570 | "discard_ios": 0, 1571 | "discard_merges": 0, 1572 | "discard_sectors": 0, 1573 | "discard_ticks": 0 1574 | } 1575 | }, 1576 | "holder_mds": null, 1577 | "holder_dms": null 1578 | } 1579 | ], 1580 | "slave_mds": null 1581 | }, 1582 | { 1583 | "info": { 1584 | "dev": "dm-0", 1585 | "size": 1048576000, 1586 | "maj": 254, 1587 | "min": 0, 1588 | "block_size": 4096, 1589 | "stat": { 1590 | "read_ios": 114, 1591 | "read_merges": 0, 1592 | "read_sectors": 6320, 1593 | "read_ticks": 2033, 1594 | "write_ios": 2, 1595 | "write_merges": 0, 1596 | "write_sectors": 0, 1597 | "write_ticks": 0, 1598 | "in_flight": 0, 1599 | "io_ticks": 1377, 1600 | "time_in_queue": 2033, 1601 | "discard_ios": 0, 1602 | "discard_merges": 0, 1603 | "discard_sectors": 0, 1604 | "discard_ticks": 0 1605 | } 1606 | }, 1607 | "name": "vgvol-k8s", 1608 | "uuid": "LVM-D0J4mWtV7c3vTbjLQkTcCp3ltYxfuIXGfCivRZSyWEZyAvdlSAl4sJvnG8G2Gm5h", 1609 | "slave_parts": [ 1610 | { 1611 | "info": { 1612 | "dev": "sdc2", 1613 | "size": 2648735920, 1614 | "maj": 8, 1615 | "min": 34, 1616 | "block_size": 4096, 1617 | "stat": { 1618 | "read_ios": 291, 1619 | "read_merges": 0, 1620 | "read_sectors": 12130, 1621 | "read_ticks": 3428, 1622 | "write_ios": 5, 1623 | "write_merges": 1, 1624 | "write_sectors": 48, 1625 | "write_ticks": 29, 1626 | "in_flight": 0, 1627 | "io_ticks": 1644, 1628 | "time_in_queue": 3457, 1629 | "discard_ios": 0, 1630 | "discard_merges": 0, 1631 | "discard_sectors": 0, 1632 | "discard_ticks": 0 1633 | } 1634 | }, 1635 | "holder_mds": null, 1636 | "holder_dms": null 1637 | } 1638 | ], 1639 | "slave_mds": null 1640 | }, 1641 | { 1642 | "info": { 1643 | "dev": "dm-5", 1644 | "size": 209715200, 1645 | "maj": 254, 1646 | "min": 5, 1647 | "block_size": 4096, 1648 | "stat": { 1649 | "read_ios": 66, 1650 | "read_merges": 0, 1651 | "read_sectors": 2226, 1652 | "read_ticks": 749, 1653 | "write_ios": 4, 1654 | "write_merges": 0, 1655 | "write_sectors": 8, 1656 | "write_ticks": 629, 1657 | "in_flight": 0, 1658 | "io_ticks": 1327, 1659 | "time_in_queue": 1379, 1660 | "discard_ios": 0, 1661 | "discard_merges": 0, 1662 | "discard_sectors": 0, 1663 | "discard_ticks": 0 1664 | } 1665 | }, 1666 | "name": "vgstor-docs", 1667 | "uuid": "LVM-3Wn54nieFFkISN2T3YodfGJV2jkG95EGsh5G3o5enDMpks44ILBRayoGTjbiFzfp", 1668 | "slave_parts": null, 1669 | "slave_mds": [ 1670 | { 1671 | "info": { 1672 | "dev": "md0", 1673 | "size": 3906762880, 1674 | "maj": 9, 1675 | "min": 0, 1676 | "block_size": 4096, 1677 | "stat": { 1678 | "read_ios": 413, 1679 | "read_merges": 0, 1680 | "read_sectors": 10400, 1681 | "read_ticks": 0, 1682 | "write_ios": 32, 1683 | "write_merges": 0, 1684 | "write_sectors": 136, 1685 | "write_ticks": 0, 1686 | "in_flight": 0, 1687 | "io_ticks": 0, 1688 | "time_in_queue": 0, 1689 | "discard_ios": 0, 1690 | "discard_merges": 0, 1691 | "discard_sectors": 0, 1692 | "discard_ticks": 0 1693 | } 1694 | }, 1695 | "level": "raid1", 1696 | "slave_parts": [ 1697 | { 1698 | "info": { 1699 | "dev": "sdd1", 1700 | "size": 3907027087, 1701 | "maj": 8, 1702 | "min": 49, 1703 | "block_size": 512, 1704 | "stat": { 1705 | "read_ios": 189, 1706 | "read_merges": 69, 1707 | "read_sectors": 3888, 1708 | "read_ticks": 1327, 1709 | "write_ios": 66, 1710 | "write_merges": 3, 1711 | "write_sectors": 454, 1712 | "write_ticks": 2782, 1713 | "in_flight": 0, 1714 | "io_ticks": 2897, 1715 | "time_in_queue": 4109, 1716 | "discard_ios": 0, 1717 | "discard_merges": 0, 1718 | "discard_sectors": 0, 1719 | "discard_ticks": 0 1720 | } 1721 | }, 1722 | "holder_mds": null, 1723 | "holder_dms": null 1724 | }, 1725 | { 1726 | "info": { 1727 | "dev": "sda1", 1728 | "size": 3907027087, 1729 | "maj": 8, 1730 | "min": 1, 1731 | "block_size": 512, 1732 | "stat": { 1733 | "read_ios": 271, 1734 | "read_merges": 48, 1735 | "read_sectors": 7593, 1736 | "read_ticks": 3322, 1737 | "write_ios": 66, 1738 | "write_merges": 3, 1739 | "write_sectors": 454, 1740 | "write_ticks": 3696, 1741 | "in_flight": 0, 1742 | "io_ticks": 4520, 1743 | "time_in_queue": 7018, 1744 | "discard_ios": 0, 1745 | "discard_merges": 0, 1746 | "discard_sectors": 0, 1747 | "discard_ticks": 0 1748 | } 1749 | }, 1750 | "holder_mds": null, 1751 | "holder_dms": null 1752 | } 1753 | ], 1754 | "holder_devices": [ 1755 | { 1756 | "info": { 1757 | "dev": "dm-6", 1758 | "size": 209715200, 1759 | "maj": 254, 1760 | "min": 6, 1761 | "block_size": 4096, 1762 | "stat": { 1763 | "read_ios": 66, 1764 | "read_merges": 0, 1765 | "read_sectors": 2226, 1766 | "read_ticks": 1986, 1767 | "write_ios": 4, 1768 | "write_merges": 0, 1769 | "write_sectors": 8, 1770 | "write_ticks": 356, 1771 | "in_flight": 0, 1772 | "io_ticks": 1047, 1773 | "time_in_queue": 2343, 1774 | "discard_ios": 0, 1775 | "discard_merges": 0, 1776 | "discard_sectors": 0, 1777 | "discard_ticks": 0 1778 | } 1779 | }, 1780 | "name": "vgstor-rand", 1781 | "uuid": "LVM-3Wn54nieFFkISN2T3YodfGJV2jkG95EGYieQNcZKKxZHkPIoA25iUAGm0hfo0IW9", 1782 | "slave_parts": null, 1783 | "slave_mds": null 1784 | }, 1785 | { 1786 | "info": { 1787 | "dev": "dm-4", 1788 | "size": 629145600, 1789 | "maj": 254, 1790 | "min": 4, 1791 | "block_size": 4096, 1792 | "stat": { 1793 | "read_ios": 107, 1794 | "read_merges": 0, 1795 | "read_sectors": 2610, 1796 | "read_ticks": 3966, 1797 | "write_ios": 20, 1798 | "write_merges": 0, 1799 | "write_sectors": 136, 1800 | "write_ticks": 2433, 1801 | "in_flight": 0, 1802 | "io_ticks": 2297, 1803 | "time_in_queue": 6399, 1804 | "discard_ios": 0, 1805 | "discard_merges": 0, 1806 | "discard_sectors": 0, 1807 | "discard_ticks": 0 1808 | } 1809 | }, 1810 | "name": "vgstor-photos", 1811 | "uuid": "LVM-3Wn54nieFFkISN2T3YodfGJV2jkG95EGFS3UxLCTMNcHyjP3KaYPAmcByH9cdqxL", 1812 | "slave_parts": null, 1813 | "slave_mds": null 1814 | }, 1815 | { 1816 | "info": { 1817 | "dev": "dm-5", 1818 | "size": 209715200, 1819 | "maj": 254, 1820 | "min": 5, 1821 | "block_size": 4096, 1822 | "stat": { 1823 | "read_ios": 66, 1824 | "read_merges": 0, 1825 | "read_sectors": 2226, 1826 | "read_ticks": 749, 1827 | "write_ios": 4, 1828 | "write_merges": 0, 1829 | "write_sectors": 8, 1830 | "write_ticks": 629, 1831 | "in_flight": 0, 1832 | "io_ticks": 1327, 1833 | "time_in_queue": 1379, 1834 | "discard_ios": 0, 1835 | "discard_merges": 0, 1836 | "discard_sectors": 0, 1837 | "discard_ticks": 0 1838 | } 1839 | }, 1840 | "name": "vgstor-docs", 1841 | "uuid": "LVM-3Wn54nieFFkISN2T3YodfGJV2jkG95EGsh5G3o5enDMpks44ILBRayoGTjbiFzfp", 1842 | "slave_parts": null, 1843 | "slave_mds": null 1844 | }, 1845 | { 1846 | "info": { 1847 | "dev": "dm-3", 1848 | "size": 1677721600, 1849 | "maj": 254, 1850 | "min": 3, 1851 | "block_size": 4096, 1852 | "stat": { 1853 | "read_ios": 154, 1854 | "read_merges": 0, 1855 | "read_sectors": 2930, 1856 | "read_ticks": 1219, 1857 | "write_ios": 4, 1858 | "write_merges": 0, 1859 | "write_sectors": 8, 1860 | "write_ticks": 553, 1861 | "in_flight": 0, 1862 | "io_ticks": 1347, 1863 | "time_in_queue": 1773, 1864 | "discard_ios": 0, 1865 | "discard_merges": 0, 1866 | "discard_sectors": 0, 1867 | "discard_ticks": 0 1868 | } 1869 | }, 1870 | "name": "vgstor-media", 1871 | "uuid": "LVM-3Wn54nieFFkISN2T3YodfGJV2jkG95EGj23hIRRpNbd2YUuOLxrJpDEMldcjZhaR", 1872 | "slave_parts": null, 1873 | "slave_mds": null 1874 | } 1875 | ] 1876 | } 1877 | ] 1878 | }, 1879 | { 1880 | "info": { 1881 | "dev": "dm-3", 1882 | "size": 1677721600, 1883 | "maj": 254, 1884 | "min": 3, 1885 | "block_size": 4096, 1886 | "stat": { 1887 | "read_ios": 154, 1888 | "read_merges": 0, 1889 | "read_sectors": 2930, 1890 | "read_ticks": 1219, 1891 | "write_ios": 4, 1892 | "write_merges": 0, 1893 | "write_sectors": 8, 1894 | "write_ticks": 553, 1895 | "in_flight": 0, 1896 | "io_ticks": 1347, 1897 | "time_in_queue": 1773, 1898 | "discard_ios": 0, 1899 | "discard_merges": 0, 1900 | "discard_sectors": 0, 1901 | "discard_ticks": 0 1902 | } 1903 | }, 1904 | "name": "vgstor-media", 1905 | "uuid": "LVM-3Wn54nieFFkISN2T3YodfGJV2jkG95EGj23hIRRpNbd2YUuOLxrJpDEMldcjZhaR", 1906 | "slave_parts": null, 1907 | "slave_mds": [ 1908 | { 1909 | "info": { 1910 | "dev": "md0", 1911 | "size": 3906762880, 1912 | "maj": 9, 1913 | "min": 0, 1914 | "block_size": 4096, 1915 | "stat": { 1916 | "read_ios": 413, 1917 | "read_merges": 0, 1918 | "read_sectors": 10400, 1919 | "read_ticks": 0, 1920 | "write_ios": 32, 1921 | "write_merges": 0, 1922 | "write_sectors": 136, 1923 | "write_ticks": 0, 1924 | "in_flight": 0, 1925 | "io_ticks": 0, 1926 | "time_in_queue": 0, 1927 | "discard_ios": 0, 1928 | "discard_merges": 0, 1929 | "discard_sectors": 0, 1930 | "discard_ticks": 0 1931 | } 1932 | }, 1933 | "level": "raid1", 1934 | "slave_parts": [ 1935 | { 1936 | "info": { 1937 | "dev": "sdd1", 1938 | "size": 3907027087, 1939 | "maj": 8, 1940 | "min": 49, 1941 | "block_size": 512, 1942 | "stat": { 1943 | "read_ios": 189, 1944 | "read_merges": 69, 1945 | "read_sectors": 3888, 1946 | "read_ticks": 1327, 1947 | "write_ios": 66, 1948 | "write_merges": 3, 1949 | "write_sectors": 454, 1950 | "write_ticks": 2782, 1951 | "in_flight": 0, 1952 | "io_ticks": 2897, 1953 | "time_in_queue": 4109, 1954 | "discard_ios": 0, 1955 | "discard_merges": 0, 1956 | "discard_sectors": 0, 1957 | "discard_ticks": 0 1958 | } 1959 | }, 1960 | "holder_mds": null, 1961 | "holder_dms": null 1962 | }, 1963 | { 1964 | "info": { 1965 | "dev": "sda1", 1966 | "size": 3907027087, 1967 | "maj": 8, 1968 | "min": 1, 1969 | "block_size": 512, 1970 | "stat": { 1971 | "read_ios": 271, 1972 | "read_merges": 48, 1973 | "read_sectors": 7593, 1974 | "read_ticks": 3322, 1975 | "write_ios": 66, 1976 | "write_merges": 3, 1977 | "write_sectors": 454, 1978 | "write_ticks": 3696, 1979 | "in_flight": 0, 1980 | "io_ticks": 4520, 1981 | "time_in_queue": 7018, 1982 | "discard_ios": 0, 1983 | "discard_merges": 0, 1984 | "discard_sectors": 0, 1985 | "discard_ticks": 0 1986 | } 1987 | }, 1988 | "holder_mds": null, 1989 | "holder_dms": null 1990 | } 1991 | ], 1992 | "holder_devices": [ 1993 | { 1994 | "info": { 1995 | "dev": "dm-6", 1996 | "size": 209715200, 1997 | "maj": 254, 1998 | "min": 6, 1999 | "block_size": 4096, 2000 | "stat": { 2001 | "read_ios": 66, 2002 | "read_merges": 0, 2003 | "read_sectors": 2226, 2004 | "read_ticks": 1986, 2005 | "write_ios": 4, 2006 | "write_merges": 0, 2007 | "write_sectors": 8, 2008 | "write_ticks": 356, 2009 | "in_flight": 0, 2010 | "io_ticks": 1047, 2011 | "time_in_queue": 2343, 2012 | "discard_ios": 0, 2013 | "discard_merges": 0, 2014 | "discard_sectors": 0, 2015 | "discard_ticks": 0 2016 | } 2017 | }, 2018 | "name": "vgstor-rand", 2019 | "uuid": "LVM-3Wn54nieFFkISN2T3YodfGJV2jkG95EGYieQNcZKKxZHkPIoA25iUAGm0hfo0IW9", 2020 | "slave_parts": null, 2021 | "slave_mds": null 2022 | }, 2023 | { 2024 | "info": { 2025 | "dev": "dm-4", 2026 | "size": 629145600, 2027 | "maj": 254, 2028 | "min": 4, 2029 | "block_size": 4096, 2030 | "stat": { 2031 | "read_ios": 107, 2032 | "read_merges": 0, 2033 | "read_sectors": 2610, 2034 | "read_ticks": 3966, 2035 | "write_ios": 20, 2036 | "write_merges": 0, 2037 | "write_sectors": 136, 2038 | "write_ticks": 2433, 2039 | "in_flight": 0, 2040 | "io_ticks": 2297, 2041 | "time_in_queue": 6399, 2042 | "discard_ios": 0, 2043 | "discard_merges": 0, 2044 | "discard_sectors": 0, 2045 | "discard_ticks": 0 2046 | } 2047 | }, 2048 | "name": "vgstor-photos", 2049 | "uuid": "LVM-3Wn54nieFFkISN2T3YodfGJV2jkG95EGFS3UxLCTMNcHyjP3KaYPAmcByH9cdqxL", 2050 | "slave_parts": null, 2051 | "slave_mds": null 2052 | }, 2053 | { 2054 | "info": { 2055 | "dev": "dm-5", 2056 | "size": 209715200, 2057 | "maj": 254, 2058 | "min": 5, 2059 | "block_size": 4096, 2060 | "stat": { 2061 | "read_ios": 66, 2062 | "read_merges": 0, 2063 | "read_sectors": 2226, 2064 | "read_ticks": 749, 2065 | "write_ios": 4, 2066 | "write_merges": 0, 2067 | "write_sectors": 8, 2068 | "write_ticks": 629, 2069 | "in_flight": 0, 2070 | "io_ticks": 1327, 2071 | "time_in_queue": 1379, 2072 | "discard_ios": 0, 2073 | "discard_merges": 0, 2074 | "discard_sectors": 0, 2075 | "discard_ticks": 0 2076 | } 2077 | }, 2078 | "name": "vgstor-docs", 2079 | "uuid": "LVM-3Wn54nieFFkISN2T3YodfGJV2jkG95EGsh5G3o5enDMpks44ILBRayoGTjbiFzfp", 2080 | "slave_parts": null, 2081 | "slave_mds": null 2082 | }, 2083 | { 2084 | "info": { 2085 | "dev": "dm-3", 2086 | "size": 1677721600, 2087 | "maj": 254, 2088 | "min": 3, 2089 | "block_size": 4096, 2090 | "stat": { 2091 | "read_ios": 154, 2092 | "read_merges": 0, 2093 | "read_sectors": 2930, 2094 | "read_ticks": 1219, 2095 | "write_ios": 4, 2096 | "write_merges": 0, 2097 | "write_sectors": 8, 2098 | "write_ticks": 553, 2099 | "in_flight": 0, 2100 | "io_ticks": 1347, 2101 | "time_in_queue": 1773, 2102 | "discard_ios": 0, 2103 | "discard_merges": 0, 2104 | "discard_sectors": 0, 2105 | "discard_ticks": 0 2106 | } 2107 | }, 2108 | "name": "vgstor-media", 2109 | "uuid": "LVM-3Wn54nieFFkISN2T3YodfGJV2jkG95EGj23hIRRpNbd2YUuOLxrJpDEMldcjZhaR", 2110 | "slave_parts": null, 2111 | "slave_mds": null 2112 | } 2113 | ] 2114 | } 2115 | ] 2116 | } 2117 | ] 2118 | } 2119 | -------------------------------------------------------------------------------- /example_output/graph.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vv9k/rsys-cli/08bf0bc2fb24e53be0abfc54957e0c1fc7227a6e/example_output/graph.gif -------------------------------------------------------------------------------- /src/cli.rs: -------------------------------------------------------------------------------- 1 | use super::cmd::{RsysCmd, RsysOpt}; 2 | use rsys::{Result, Rsys}; 3 | use structopt::StructOpt; 4 | 5 | pub struct RsysCli { 6 | pub opts: RsysOpt, 7 | pub system: Rsys, 8 | } 9 | 10 | impl Default for RsysCli { 11 | fn default() -> Self { 12 | RsysCli { 13 | opts: RsysOpt::from_args(), 14 | system: Rsys::new(), 15 | } 16 | } 17 | } 18 | 19 | impl RsysCli { 20 | pub fn new() -> Self { 21 | Self::default() 22 | } 23 | 24 | pub fn main(&self) -> Result<()> { 25 | if let Some(cmd) = self.opts.cmd.clone() { 26 | match cmd { 27 | RsysCmd::Get(opts) => self.get(opts)?, 28 | RsysCmd::Dump(opts) => self.dump(opts)?, 29 | RsysCmd::Watch(opts) => self.watch(opts)?, 30 | RsysCmd::Show { cmd } => self.show(cmd), 31 | } 32 | } 33 | 34 | Ok(()) 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/cmd/common.rs: -------------------------------------------------------------------------------- 1 | use crate::util::{conv_b, conv_hz, handle_err}; 2 | use prettytable::{format, Table}; 3 | use rsys::{ 4 | linux::{ 5 | cpu::Processor, 6 | mem::Memory, 7 | misc::MountPoints, 8 | net::Interfaces, 9 | ps::Processes, 10 | storage::{ 11 | storage_devices, DeviceMapper, DeviceMappers, MultipleDeviceStorage, MultipleDeviceStorages, StorageDevice, 12 | StorageDevices, 13 | }, 14 | }, 15 | Result, Rsys, 16 | }; 17 | use serde::{Deserialize, Serialize}; 18 | use std::fmt::{self, Formatter}; 19 | 20 | const SECTOR_SIZE: u64 = 512; 21 | 22 | #[derive(Debug, Serialize, Deserialize)] 23 | pub struct SystemInfo { 24 | #[serde(skip_serializing_if = "Option::is_none")] 25 | arch: Option, 26 | #[serde(skip_serializing_if = "Option::is_none")] 27 | hostname: Option, 28 | #[serde(skip_serializing_if = "Option::is_none")] 29 | domain: Option, 30 | #[serde(skip_serializing_if = "Option::is_none")] 31 | uptime: Option, 32 | #[serde(skip_serializing_if = "Option::is_none")] 33 | os: Option, 34 | #[serde(skip_serializing_if = "Option::is_none")] 35 | kernel: Option, 36 | #[serde(skip_serializing_if = "Option::is_none")] 37 | cpu: Option, 38 | #[serde(skip_serializing_if = "Option::is_none")] 39 | memory: Option, 40 | #[serde(skip_serializing_if = "Option::is_none")] 41 | processes: Option, 42 | #[serde(skip_serializing_if = "Option::is_none")] 43 | mounts: Option, 44 | #[serde(skip_serializing_if = "Option::is_none")] 45 | interfaces: Option, 46 | #[serde(skip_serializing_if = "Option::is_none")] 47 | storage_devices: Option, 48 | #[serde(skip_serializing_if = "Option::is_none")] 49 | multiple_device_storages: Option, 50 | #[serde(skip_serializing_if = "Option::is_none")] 51 | device_mappers: Option, 52 | #[serde(skip_serializing)] 53 | display_stats: bool, 54 | #[serde(skip_serializing)] 55 | display_all: bool, 56 | } 57 | impl SystemInfo { 58 | #[allow(clippy::too_many_arguments)] 59 | pub fn new( 60 | r: &Rsys, 61 | arch: bool, 62 | hostname: bool, 63 | domain: bool, 64 | uptime: bool, 65 | os: bool, 66 | kernel: bool, 67 | cpu: bool, 68 | memory: bool, 69 | net: bool, 70 | storage: bool, 71 | mounts: bool, 72 | all: bool, 73 | stats: bool, 74 | processes: bool, 75 | ) -> Result { 76 | Ok(Self { 77 | arch: if arch || all { Some(handle_err(r.arch())) } else { None }, 78 | hostname: if hostname || all { 79 | Some(handle_err(r.hostname())) 80 | } else { 81 | None 82 | }, 83 | domain: if domain || all { 84 | Some(handle_err(r.domainname())) 85 | } else { 86 | None 87 | }, 88 | uptime: if uptime || all { 89 | Some(handle_err(r.uptime())) 90 | } else { 91 | None 92 | }, 93 | os: if os || all { Some(r.os()) } else { None }, 94 | kernel: if kernel || all { 95 | Some(handle_err(r.kernel_version())) 96 | } else { 97 | None 98 | }, 99 | cpu: if cpu || all { 100 | Some(handle_err(r.processor())) 101 | } else { 102 | None 103 | }, 104 | memory: if memory || all { 105 | Some(handle_err(r.memory())) 106 | } else { 107 | None 108 | }, 109 | processes: if processes || all { 110 | Some(handle_err(r.processes())) 111 | } else { 112 | None 113 | }, 114 | mounts: if mounts || all { 115 | Some(handle_err(r.mounts())) 116 | } else { 117 | None 118 | }, 119 | interfaces: if net || all { Some(handle_err(r.ifaces())) } else { None }, 120 | storage_devices: if storage || all { 121 | let show_stats = if all { true } else { stats }; 122 | Some(handle_err(storage_devices::(show_stats))) 123 | } else { 124 | None 125 | }, 126 | multiple_device_storages: if storage || all { 127 | let show_stats = if all { true } else { stats }; 128 | Some(handle_err(storage_devices::(show_stats))) 129 | } else { 130 | None 131 | }, 132 | device_mappers: if storage || all { 133 | let show_stats = if all { true } else { stats }; 134 | Some(handle_err(storage_devices::(show_stats))) 135 | } else { 136 | None 137 | }, 138 | display_stats: stats, 139 | display_all: all, 140 | }) 141 | } 142 | fn general_section_string(&self) -> String { 143 | let mut s = String::new(); 144 | let mut table = Table::new(); 145 | table.set_format(*format::consts::FORMAT_NO_LINESEP_WITH_TITLE); 146 | if let Some(hostname) = &self.hostname { 147 | table.add_row(row!["hostname:", l -> hostname]); 148 | } 149 | if let Some(arch) = &self.arch { 150 | table.add_row(row!["arch:", l -> arch]); 151 | } 152 | if let Some(domain) = &self.domain { 153 | if domain != "(none)" { 154 | table.add_row(row!["domain:", l -> domain]); 155 | } 156 | } 157 | if let Some(kernel) = &self.kernel { 158 | table.add_row(row!["kernel:", l -> kernel]); 159 | } 160 | if let Some(uptime) = &self.uptime { 161 | table.add_row(row!["uptime:", l -> format!("{} s", uptime)]); 162 | } 163 | if let Some(os) = &self.os { 164 | table.add_row(row!["os:", l -> os]); 165 | } 166 | s.push_str(" GENERAL:\n"); 167 | s.push_str(&table.to_string()); 168 | s 169 | } 170 | fn cpu_section_string(&self) -> String { 171 | let mut s = String::new(); 172 | if let Some(cpu) = &self.cpu { 173 | s.push_str(" CPU:\n"); 174 | let mut cpu_table = Table::new(); 175 | let mut cores_table = Table::new(); 176 | cpu_table.set_format(*format::consts::FORMAT_NO_LINESEP_WITH_TITLE); 177 | cores_table.set_format(*format::consts::FORMAT_NO_LINESEP_WITH_TITLE); 178 | cpu_table.add_row(row!["model:", cpu.model]); 179 | cpu_table.add_row(row!["cache size:", conv_b(cpu.cache_size)]); 180 | cpu_table.add_row(row!["bogomips:", cpu.bogomips]); 181 | cores_table.add_row(row![c => "core", "minimum", "current", "max"]); 182 | 183 | for core in &cpu.cores { 184 | cores_table.add_row(row![ 185 | &format!("cpu{}", core.id), 186 | conv_hz(core.min_freq), 187 | conv_hz(core.cur_freq), 188 | conv_hz(core.max_freq), 189 | ]); 190 | } 191 | s.push_str(&cpu_table.to_string()); 192 | s.push_str(&cores_table.to_string()); 193 | } 194 | s 195 | } 196 | fn memory_section_string(&self) -> String { 197 | let mut s = String::new(); 198 | if let Some(memory) = &self.memory { 199 | s.push_str(" MEMORY:\n"); 200 | let mut mem_table = Table::new(); 201 | mem_table.set_format(*format::consts::FORMAT_NO_LINESEP_WITH_TITLE); 202 | mem_table.add_row(row!["total:", r -> conv_b(memory.total)]); 203 | mem_table.add_row(row!["free:", r -> conv_b(memory.free)]); 204 | mem_table.add_row(row!["available:", r -> conv_b(memory.available)]); 205 | mem_table.add_row(row!["buffers:", r -> conv_b(memory.buffers)]); 206 | mem_table.add_row(row!["cached:", r -> conv_b(memory.cached)]); 207 | mem_table.add_row(row!["active:", r -> conv_b(memory.active)]); 208 | mem_table.add_row(row!["inactive:", r -> conv_b(memory.inactive)]); 209 | mem_table.add_row(row!["shared:", r -> conv_b(memory.shared)]); 210 | s.push_str(&mem_table.to_string()); 211 | } 212 | s 213 | } 214 | fn network_section_string(&self) -> String { 215 | let mut s = String::new(); 216 | if let Some(ifaces) = &self.interfaces { 217 | s.push_str(" NETWORK:\n"); 218 | let mut net_table = Table::new(); 219 | let mut stats_table = Table::new(); 220 | net_table.set_format(*format::consts::FORMAT_NO_LINESEP); 221 | stats_table.set_format(*format::consts::FORMAT_NO_LINESEP); 222 | 223 | net_table.add_row(row![ c => "name", "ipv4", "ipv6", "mac", "speed", "mtu",]); 224 | stats_table.add_row(row![ c => 225 | "name", 226 | "bytes", 227 | "packets", 228 | "errs", 229 | "drop", 230 | "fifo", 231 | "frame", 232 | "compressed", 233 | "multicast", 234 | ]); 235 | for iface in &ifaces.0 { 236 | net_table.add_row(row![ 237 | iface.name, 238 | iface.ipv4, 239 | iface.ipv6, 240 | iface.mac_address, 241 | format!("{} mb/s", iface.speed), 242 | iface.mtu, 243 | ]); 244 | stats_table.add_row(row![ 245 | iface.name, 246 | c -> format!("{} / {}", conv_b(iface.stat.rx_bytes), conv_b(iface.stat.tx_bytes)), 247 | c -> format!("{} / {}", iface.stat.rx_packets, iface.stat.tx_packets), 248 | c -> format!("{} / {}", iface.stat.rx_errs, iface.stat.tx_errs), 249 | c -> format!("{} / {}", iface.stat.rx_drop, iface.stat.tx_drop), 250 | c -> format!("{} / {}", iface.stat.rx_fifo, iface.stat.tx_fifo), 251 | c -> format!("{} / {}", iface.stat.rx_frame, iface.stat.tx_frame), 252 | c -> format!("{} / {}", iface.stat.rx_compressed, iface.stat.tx_compressed), 253 | c -> format!("{} / {}", iface.stat.rx_multicast, iface.stat.tx_multicast), 254 | ]); 255 | } 256 | s.push_str(&net_table.to_string()); 257 | if self.display_stats || self.display_all { 258 | s.push_str(" NETWORK STATS: ( rx / tx - received / transfered )\n"); 259 | s.push_str(&stats_table.to_string()); 260 | } 261 | } 262 | s 263 | } 264 | fn storage_section_string(&self) -> String { 265 | let mut s = String::new(); 266 | if let Some(storages) = &self.storage_devices { 267 | s.push_str(" STORAGE DEVICES:\n"); 268 | let mut storage_table = Table::new(); 269 | let mut stats_table = Table::new(); 270 | storage_table.set_format(*format::consts::FORMAT_NO_LINESEP); 271 | stats_table.set_format(*format::consts::FORMAT_NO_LINESEP); 272 | 273 | storage_table.add_row(row![ 274 | c => 275 | "name", 276 | "size", 277 | "major", 278 | "min", 279 | "block size", 280 | "model", 281 | "vendor", 282 | "state" 283 | ]); 284 | stats_table.add_row(row![ 285 | c => 286 | "device", 287 | "r I/O's", 288 | "r merges", 289 | "r sectors", 290 | "r ticks", 291 | "w I/O's", 292 | "w merges", 293 | "w sectors", 294 | "w ticks", 295 | "d I/O's", 296 | "d merges", 297 | "d sectors", 298 | "d ticks", 299 | "in flight", 300 | "I/O ticks", 301 | ]); 302 | for storage in storages { 303 | storage_table.add_row(row![ 304 | storage.info.dev, 305 | r -> conv_b(storage.info.size as u64 * SECTOR_SIZE), 306 | storage.info.maj, 307 | storage.info.min, 308 | storage.info.block_size, 309 | storage.model, 310 | storage.vendor, 311 | storage.state 312 | ]); 313 | 314 | if let Some(stat) = &storage.info.stat { 315 | stats_table.add_row(row![ 316 | storage.info.dev, 317 | stat.read_ios, 318 | stat.read_merges, 319 | stat.read_sectors, 320 | stat.read_ticks, 321 | stat.write_ios, 322 | stat.write_merges, 323 | stat.write_sectors, 324 | stat.write_ticks, 325 | stat.discard_ios, 326 | stat.discard_merges, 327 | stat.discard_sectors, 328 | stat.discard_ticks, 329 | stat.in_flight, 330 | stat.io_ticks 331 | ]); 332 | } 333 | } 334 | s.push_str(&storage_table.to_string()); 335 | if let Some(mds) = &self.multiple_device_storages { 336 | s.push_str(" MULTIPLE DEVICE ARRAYS:\n"); 337 | let mut mds_table = Table::new(); 338 | mds_table.set_format(*format::consts::FORMAT_NO_LINESEP); 339 | 340 | mds_table.add_row(row![ c => "name", "size", "major", "min", "block size", "level",]); 341 | for md in mds { 342 | mds_table.add_row(row![ 343 | md.info.dev, 344 | r -> conv_b(md.info.size as u64 * SECTOR_SIZE), 345 | md.info.maj, 346 | md.info.min, 347 | md.info.block_size, 348 | md.level, 349 | ]); 350 | if let Some(stat) = &md.info.stat { 351 | stats_table.add_row(row![ 352 | md.info.dev, 353 | stat.read_ios, 354 | stat.read_merges, 355 | stat.read_sectors, 356 | stat.read_ticks, 357 | stat.write_ios, 358 | stat.write_merges, 359 | stat.write_sectors, 360 | stat.write_ticks, 361 | stat.discard_ios, 362 | stat.discard_merges, 363 | stat.discard_sectors, 364 | stat.discard_ticks, 365 | stat.in_flight, 366 | stat.io_ticks 367 | ]); 368 | } 369 | } 370 | s.push_str(&mds_table.to_string()); 371 | } 372 | if let Some(dms) = &self.device_mappers { 373 | s.push_str(" DEVICE MAPPERS:\n"); 374 | let mut dms_table = Table::new(); 375 | dms_table.set_format(*format::consts::FORMAT_NO_LINESEP); 376 | 377 | dms_table.add_row(row![ c => "name", "size", "major", "min", "block size", "vname", "uuid",]); 378 | for dm in dms { 379 | dms_table.add_row(row![ 380 | dm.info.dev, 381 | r -> conv_b(dm.info.size as u64 * SECTOR_SIZE), 382 | dm.info.maj, 383 | dm.info.min, 384 | dm.info.block_size, 385 | dm.name, 386 | dm.uuid, 387 | ]); 388 | if let Some(stat) = &dm.info.stat { 389 | stats_table.add_row(row![ 390 | dm.info.dev, 391 | stat.read_ios, 392 | stat.read_merges, 393 | stat.read_sectors, 394 | stat.read_ticks, 395 | stat.write_ios, 396 | stat.write_merges, 397 | stat.write_sectors, 398 | stat.write_ticks, 399 | stat.discard_ios, 400 | stat.discard_merges, 401 | stat.discard_sectors, 402 | stat.discard_ticks, 403 | stat.in_flight, 404 | stat.io_ticks 405 | ]); 406 | } 407 | } 408 | s.push_str(&dms_table.to_string()); 409 | } 410 | if self.display_stats || self.display_all { 411 | s.push_str(" STORAGE STATS: (r - read, w - write, d - discard)\n"); 412 | s.push_str(&stats_table.to_string()); 413 | } 414 | } 415 | s 416 | } 417 | fn processes_section_string(&self) -> String { 418 | let mut s = String::new(); 419 | if let Some(processes) = &self.processes { 420 | s.push_str(" PROCESSES:\n"); 421 | let mut p_table = Table::new(); 422 | p_table.set_format(*format::consts::FORMAT_NO_LINESEP); 423 | p_table.add_row(row![ 424 | c => 425 | "pid", 426 | "cmdline", 427 | "name", 428 | "state", 429 | "ppid", 430 | "pgrp", 431 | "session", 432 | "tty_nr", 433 | "utime", 434 | "stime", 435 | "cutime", 436 | "cstime", 437 | "priority", 438 | "nice", 439 | "num_threads", 440 | "itrealvalue", 441 | "starttime", 442 | "vsize", 443 | "rss", 444 | "rsslim", 445 | "nswap", 446 | "cnswap", 447 | "guest_time", 448 | "cguest_time", 449 | "processor" 450 | ]); 451 | 452 | for p in processes { 453 | p_table.add_row(row![ 454 | p.stat.pid, 455 | p.cmdline, 456 | p.stat.name, 457 | p.stat.state, 458 | p.stat.ppid, 459 | p.stat.pgrp, 460 | p.stat.session, 461 | p.stat.tty_nr, 462 | p.stat.utime, 463 | p.stat.stime, 464 | p.stat.cutime, 465 | p.stat.cstime, 466 | p.stat.priority, 467 | p.stat.nice, 468 | p.stat.num_threads, 469 | p.stat.itrealvalue, 470 | p.stat.starttime, 471 | p.stat.vsize, 472 | p.stat.rss, 473 | p.stat.rsslim, 474 | p.stat.nswap, 475 | p.stat.cnswap, 476 | p.stat.guest_time, 477 | p.stat.cguest_time, 478 | p.stat.processor 479 | ]); 480 | } 481 | s.push_str(&p_table.to_string()); 482 | } 483 | 484 | s 485 | } 486 | } 487 | impl fmt::Display for SystemInfo { 488 | fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { 489 | let mut s = String::new(); 490 | s.push_str(&self.general_section_string()); 491 | s.push_str(&self.cpu_section_string()); 492 | s.push_str(&self.memory_section_string()); 493 | s.push_str(&self.network_section_string()); 494 | s.push_str(&self.storage_section_string()); 495 | s.push_str(&self.processes_section_string()); 496 | write!(f, "{}", s) 497 | } 498 | } 499 | -------------------------------------------------------------------------------- /src/cmd/dump.rs: -------------------------------------------------------------------------------- 1 | use super::DumpOpts; 2 | use crate::{ 3 | cmd::common::SystemInfo, 4 | util::{print, PrintFormat}, 5 | RsysCli, 6 | }; 7 | use rsys::Result; 8 | 9 | impl RsysCli { 10 | pub fn dump(&self, opts: DumpOpts) -> Result<()> { 11 | let format = if opts.json { 12 | PrintFormat::Json 13 | } else if opts.yaml { 14 | PrintFormat::Yaml 15 | } else { 16 | PrintFormat::Normal 17 | }; 18 | print( 19 | SystemInfo::new( 20 | &self.system, 21 | true, 22 | true, 23 | true, 24 | true, 25 | true, 26 | true, 27 | opts.cpu, 28 | opts.memory, 29 | opts.network, 30 | opts.storage, 31 | opts.mounts, 32 | opts.all, 33 | opts.stats, 34 | opts.processes, 35 | )?, 36 | format, 37 | opts.pretty, 38 | ) 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/cmd/get.rs: -------------------------------------------------------------------------------- 1 | use super::GetOpts; 2 | use crate::{ 3 | cli::RsysCli, 4 | util::{print, PrintFormat}, 5 | }; 6 | use rsys::linux::{ 7 | net::Interface, 8 | ps::{processes, Process}, 9 | storage::{BlockStorageDeviceName, DeviceMapper, MultipleDeviceStorage, ScsiCdrom, StorageDevice}, 10 | }; 11 | use rsys::Result; 12 | use structopt::StructOpt; 13 | 14 | #[allow(non_camel_case_types)] 15 | #[derive(StructOpt, Clone)] 16 | pub enum Property { 17 | /// Cpu architecture 18 | arch, 19 | /// All cpu stats and cores 20 | cpu, 21 | cpu_model, 22 | cpu_clock, 23 | cpu_cores, 24 | domain, 25 | hostname, 26 | /// Lookup statistics and information about network interface 27 | interface { 28 | /// Name of the interface to lookup. For example `eth0` or `enp8s0` 29 | name: String, 30 | }, 31 | interfaces, 32 | kernel, 33 | logical_cores, 34 | /// All memory statistics 35 | memory, 36 | memory_free, 37 | memory_total, 38 | /// Mountpoints from /etc/mounts 39 | mounts, 40 | os, 41 | pid { 42 | id: i32, 43 | }, 44 | /// Prints the first process that contains name in its cmdline 45 | ps { 46 | /// Process name 47 | name: String, 48 | }, 49 | /// Storage device info 50 | storage { 51 | /// Name of the storage device. For example `sda` or `md0` 52 | name: String, 53 | }, 54 | swap_free, 55 | swap_total, 56 | uptime, 57 | } 58 | 59 | impl RsysCli { 60 | pub fn get(&self, opts: GetOpts) -> Result<()> { 61 | use Property::*; 62 | let format = PrintFormat::from_bools(opts.json, opts.yaml); 63 | match opts.property { 64 | arch => print(self.system.arch()?, format, opts.pretty)?, 65 | cpu => print(self.system.processor()?, format, opts.pretty)?, 66 | cpu_model => print(self.system.cpu()?, format, opts.pretty)?, 67 | cpu_clock => print(self.system.cpu_clock()?, format, opts.pretty)?, 68 | cpu_cores => print(self.system.cpu_cores()?, format, opts.pretty)?, 69 | domain => print(self.system.domainname()?, format, opts.pretty)?, 70 | hostname => print(self.system.hostname()?, format, opts.pretty)?, 71 | interface { name } => { 72 | if let Some(iface) = self.get_interface(&name) { 73 | print(iface, format, opts.pretty)?; 74 | } else { 75 | println!("Interface `{}` not found", name); 76 | } 77 | } 78 | interfaces => print(self.system.ifaces()?, format, opts.pretty)?, 79 | kernel => print(self.system.kernel_version()?, format, opts.pretty)?, 80 | logical_cores => print(self.system.logical_cores()?, format, opts.pretty)?, 81 | os => print(self.system.os(), format, opts.pretty)?, 82 | memory => print(self.system.memory()?, format, opts.pretty)?, 83 | memory_free => print(self.system.memory_free()?, format, opts.pretty)?, 84 | memory_total => print(self.system.memory_total()?, format, opts.pretty)?, 85 | mounts => print(self.system.mounts()?, format, opts.pretty)?, 86 | pid { id } => print(Process::new(id)?, format, opts.pretty)?, 87 | ps { name } => { 88 | for process in processes()? { 89 | if process.cmdline.contains(&name) { 90 | print(process, format, opts.pretty)?; 91 | break; 92 | } 93 | } 94 | } 95 | storage { name } => self.print_storage(&name, format, opts.pretty)?, 96 | swap_total => print(self.system.swap_total()?, format, opts.pretty)?, 97 | swap_free => print(self.system.swap_free()?, format, opts.pretty)?, 98 | uptime => print(self.system.uptime()?, format, opts.pretty)?, 99 | } 100 | Ok(()) 101 | } 102 | 103 | fn print_storage(&self, name: &str, format: PrintFormat, pretty: bool) -> Result<()> { 104 | if name.starts_with(StorageDevice::prefix()) { 105 | print(self.system.stat_block_device(name)?, format, pretty)? 106 | } else if name.starts_with(DeviceMapper::prefix()) { 107 | print(self.system.stat_device_mapper(name)?, format, pretty)? 108 | } else if name.starts_with(MultipleDeviceStorage::prefix()) { 109 | print(self.system.stat_multiple_device_storage(name)?, format, pretty)? 110 | } else if name.starts_with(ScsiCdrom::prefix()) { 111 | print(self.system.stat_scsi_cdrom(name)?, format, pretty)? 112 | } 113 | 114 | Ok(()) 115 | } 116 | 117 | fn get_interface(&self, name: &str) -> Option { 118 | if let Some(interface) = self.system.ifaces().ok()?.0.iter().find(|i| i.name == name) { 119 | return Some(interface.clone()); 120 | } 121 | None 122 | } 123 | } 124 | -------------------------------------------------------------------------------- /src/cmd/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod common; 2 | pub mod dump; 3 | pub mod get; 4 | pub mod show; 5 | pub mod watch; 6 | use get::Property; 7 | pub use show::ShowCmd; 8 | use structopt::StructOpt; 9 | 10 | #[derive(StructOpt, Clone)] 11 | pub enum RsysCmd { 12 | /// Prints out a system proprty to stdout 13 | Get(GetOpts), 14 | /// Dumps all information 15 | Dump(DumpOpts), 16 | /// Monitor specified parameters. Default parameters are hostname and uptime. 17 | /// To monitor more parameters use flags like `cpu`, `memory` or `storage`. 18 | /// This command runs indefinitely unless a `duration` parameter is specified 19 | /// and by default prints JSON with parameters each second. To change how often 20 | /// there is a snapshot of data adjust `interval` parameter. 21 | Watch(WatchOpts), 22 | /// Dashboard mode with graphs and interactive lists 23 | Show { 24 | #[structopt(subcommand)] 25 | /// What dashboard to show 26 | cmd: ShowCmd, 27 | }, 28 | } 29 | 30 | #[derive(StructOpt, Clone)] 31 | #[structopt(name = "rsys", about = "Aquire all important information about your system")] 32 | pub struct RsysOpt { 33 | #[structopt(subcommand)] 34 | /// Command to run 35 | pub cmd: Option, 36 | } 37 | 38 | #[derive(StructOpt, Clone)] 39 | pub struct GetOpts { 40 | #[structopt(subcommand)] 41 | /// One of system properties 42 | pub property: Property, 43 | #[structopt(short, long)] 44 | /// Print output as JSON 45 | pub json: bool, 46 | #[structopt(short, long)] 47 | /// Print output as YAML 48 | pub yaml: bool, 49 | #[structopt(short, long)] 50 | /// Make the output pretty 51 | pub pretty: bool, 52 | } 53 | 54 | #[derive(StructOpt, Clone)] 55 | pub struct DumpOpts { 56 | #[structopt(short, long)] 57 | /// Print output as JSON 58 | pub json: bool, 59 | #[structopt(short, long)] 60 | /// Print output as YAML 61 | pub yaml: bool, 62 | #[structopt(short, long)] 63 | /// Make the output pretty 64 | pub pretty: bool, 65 | #[structopt(long)] 66 | /// Include CPU info with cores 67 | pub cpu: bool, 68 | #[structopt(long)] 69 | /// Include memory statistics 70 | pub memory: bool, 71 | #[structopt(long)] 72 | /// Adds network interfaces to the output 73 | pub network: bool, 74 | #[structopt(long)] 75 | /// Adds info about storage devices, device mappers, 76 | /// multiple device arrays 77 | pub storage: bool, 78 | #[structopt(long)] 79 | /// Adds all processes 80 | pub processes: bool, 81 | #[structopt(long)] 82 | /// Whether to parse stats for all storage devices or just the main ones. 83 | /// Only functional with `--storage` and `network` flag 84 | pub stats: bool, 85 | #[structopt(long)] 86 | /// Adds information about mountpoints on host os 87 | pub mounts: bool, 88 | #[structopt(short, long)] 89 | /// Shortcut for `--cpu --memory --storage --network --mounts --stats --processes` 90 | pub all: bool, 91 | } 92 | 93 | #[derive(StructOpt, Clone)] 94 | pub struct WatchOpts { 95 | #[structopt(short, long)] 96 | /// Make the output pretty 97 | pub pretty: bool, 98 | #[structopt(long)] 99 | /// Include CPU info with cores 100 | pub cpu: bool, 101 | #[structopt(long)] 102 | /// Include memory statistics 103 | pub memory: bool, 104 | #[structopt(long)] 105 | /// Adds network interfaces to the output 106 | pub network: bool, 107 | #[structopt(long)] 108 | /// Adds info about storage devices, device mappers, 109 | /// multiple device arrays 110 | pub storage: bool, 111 | #[structopt(long)] 112 | /// Whether to parse stats for all storage devices or just the main ones. 113 | /// Only functional with `--storage` flag 114 | pub stats: bool, 115 | #[structopt(short, long)] 116 | /// Shortcut for `--cpu --memory --storage --network --mounts` 117 | pub all: bool, 118 | #[structopt(short, long)] 119 | /// Duration in seconds for which to collect data. Default is 18_446_744_073_709_551_615 seconds 120 | pub duration: Option, 121 | #[structopt(short, long)] 122 | /// How long to wait between runs in milliseconds. Default is 1000 123 | pub interval: Option, 124 | } 125 | -------------------------------------------------------------------------------- /src/cmd/show/common/data.rs: -------------------------------------------------------------------------------- 1 | use super::screen::Screen; 2 | use anyhow::Result; 3 | use tui::style::Color; 4 | 5 | #[derive(Debug)] 6 | /// Wrapper stuct for graph datapoints used by Datasets. 7 | pub struct DataSeries { 8 | data: Vec<(f64, f64)>, 9 | pub color: Color, 10 | len: usize, 11 | } 12 | 13 | impl Default for DataSeries { 14 | fn default() -> Self { 15 | Self { 16 | data: Vec::new(), 17 | color: Color::White, 18 | len: 0, 19 | } 20 | } 21 | } 22 | 23 | impl DataSeries { 24 | pub fn new(color: Color) -> Self { 25 | Self { 26 | data: Vec::new(), 27 | color, 28 | len: 0, 29 | } 30 | } 31 | /// Return self data as slice readable by tui's Dataset 32 | pub fn dataset(&self) -> &[(f64, f64)] { 33 | &self.data 34 | } 35 | 36 | /// Add a data point 37 | pub fn add(&mut self, time: f64, value: f64) { 38 | self.data.push((time, value)); 39 | self.len += 1; 40 | } 41 | 42 | /// Pop first point returning it. If data vector is empty 43 | /// return (0., 0.) 44 | pub fn pop(&mut self) -> (f64, f64) { 45 | if self.len > 0 { 46 | self.len -= 1; 47 | return self.data.remove(0); 48 | } 49 | (0., 0.) 50 | } 51 | 52 | /// Return nth element of data set if such exists. 53 | pub fn nth(&self, n: usize) -> Option<(f64, f64)> { 54 | if n < self.len { 55 | return Some(self.data[n]); 56 | } 57 | None 58 | } 59 | 60 | /// Return first element of data set if such exists. 61 | pub fn first(&self) -> Option<(f64, f64)> { 62 | self.nth(0) 63 | } 64 | } 65 | 66 | pub trait Statistic { 67 | /// Updates the value of this stat 68 | fn update(&mut self, m: &mut Screen) -> Result<()>; 69 | /// Pops all datasets returning time delta between popped 70 | /// element and new first element of set 71 | fn pop(&mut self) -> f64; 72 | fn name(&self) -> &str; 73 | } 74 | -------------------------------------------------------------------------------- /src/cmd/show/common/display.rs: -------------------------------------------------------------------------------- 1 | use tui::{ 2 | backend::Backend, 3 | layout::{Alignment, Constraint, Direction, Layout, Rect}, 4 | style::{Color, Modifier, Style}, 5 | text::{Span, Spans}, 6 | widgets::{Block, Borders, Clear, Paragraph, Wrap}, 7 | Frame, 8 | }; 9 | 10 | type KvSpan<'a> = [Span<'a>; 2]; 11 | 12 | pub fn kv_span<'a, T: Into>(k: T, v: T, color: Color, bold: bool) -> KvSpan<'a> { 13 | let val = if bold { 14 | Span::styled(v.into(), Style::default().fg(color).add_modifier(Modifier::BOLD)) 15 | } else { 16 | Span::styled(v.into(), Style::default().fg(color)) 17 | }; 18 | [Span::raw(k.into()), val] 19 | } 20 | 21 | pub fn spans_from(kvspans: Vec>) -> Spans<'_> { 22 | Spans::from(kvspans.concat()) 23 | } 24 | 25 | pub fn popup(f: &mut Frame, message: Span<'_>, title: &str, border_style: Style, button: Span<'_>) { 26 | let area = centered_rect(60, 20, f.size()); 27 | let layout = Layout::default() 28 | .direction(Direction::Vertical) 29 | .constraints(vec![Constraint::Max(10)]) 30 | .split(area); 31 | 32 | let popup_block = Block::default() 33 | .title(title) 34 | .borders(Borders::ALL) 35 | .border_style(border_style); 36 | let text = Paragraph::new(vec![ 37 | Spans::from(message), 38 | Spans::from(Span::raw("")), 39 | Spans::from(button), 40 | ]) 41 | .block(popup_block) 42 | .alignment(Alignment::Center) 43 | .wrap(Wrap { trim: true }); 44 | f.render_widget(Clear, layout[0]); 45 | f.render_widget(text, layout[0]); 46 | } 47 | 48 | pub fn err_popup(f: &mut Frame, error: &str, button: &str) { 49 | popup( 50 | f, 51 | Span::styled(error, Style::default().add_modifier(Modifier::ITALIC)), 52 | "ERROR", 53 | Style::default().fg(Color::Red).add_modifier(Modifier::BOLD), 54 | Span::raw(button), 55 | ) 56 | } 57 | 58 | pub fn centered_rect(percent_x: u16, percent_y: u16, r: Rect) -> Rect { 59 | let popup_layout = Layout::default() 60 | .direction(Direction::Vertical) 61 | .constraints( 62 | [ 63 | Constraint::Percentage((100 - percent_y) / 2), 64 | Constraint::Percentage(percent_y), 65 | Constraint::Percentage((100 - percent_y) / 2), 66 | ] 67 | .as_ref(), 68 | ) 69 | .split(r); 70 | 71 | Layout::default() 72 | .direction(Direction::Horizontal) 73 | .constraints( 74 | [ 75 | Constraint::Percentage((100 - percent_x) / 2), 76 | Constraint::Percentage(percent_x), 77 | Constraint::Percentage((100 - percent_x) / 2), 78 | ] 79 | .as_ref(), 80 | ) 81 | .split(popup_layout[1])[1] 82 | } 83 | -------------------------------------------------------------------------------- /src/cmd/show/common/mod.rs: -------------------------------------------------------------------------------- 1 | //! Module containing common functionality used across all widgets. 2 | mod data; 3 | mod display; 4 | mod monitor; 5 | mod rxtx; 6 | mod screen; 7 | mod widget; 8 | 9 | pub use data::*; 10 | pub use display::*; 11 | pub use monitor::Monitor; 12 | pub use rxtx::RxTx; 13 | pub use screen::Screen; 14 | pub use widget::*; 15 | 16 | use super::{events, get_terminal}; 17 | -------------------------------------------------------------------------------- /src/cmd/show/common/monitor.rs: -------------------------------------------------------------------------------- 1 | use super::{InfoGraphWidget, Screen, StatefulWidget, Statistic, Updatable}; 2 | use anyhow::{anyhow, Result}; 3 | use tui::{ 4 | backend::Backend, 5 | layout::{Constraint, Direction, Layout, Rect}, 6 | Frame, 7 | }; 8 | 9 | pub struct Monitor { 10 | pub stats: Vec, 11 | pub m: Screen, 12 | } 13 | 14 | impl Updatable for Monitor { 15 | fn update(&mut self) -> Result<()> { 16 | for stat in &mut self.stats { 17 | stat.update(&mut self.m) 18 | .map_err(|e| anyhow!("Failed to update widget statistics - `{}`", e))?; 19 | } 20 | self.m.update_last_time(); 21 | 22 | // Move x axis if time reached end 23 | if self.m.elapsed_since_start() > self.m.max_x() { 24 | let delta = self.stats[0].pop(); 25 | self.m.inc_x_axis(delta); 26 | 27 | self.stats.iter_mut().skip(1).for_each(|s| { 28 | s.pop(); 29 | }); 30 | } 31 | 32 | Ok(()) 33 | } 34 | } 35 | 36 | impl StatefulWidget for W { 37 | fn update(&mut self) -> Result<()> { 38 | self.update() 39 | } 40 | // By default widget is rendered on full area. If a monitor of some 41 | // statistic wants to display more widgets it has to override this method 42 | fn render_widget(&self, f: &mut Frame, area: Rect) { 43 | let chunks = Layout::default() 44 | .direction(Direction::Horizontal) 45 | .constraints([Constraint::Percentage(100)].as_ref()) 46 | .split(area); 47 | 48 | self.render_widget(f, chunks[0]); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/cmd/show/common/rxtx.rs: -------------------------------------------------------------------------------- 1 | use crate::util::conv_fb; 2 | use std::{fmt::Debug, ops::AddAssign}; 3 | 4 | #[derive(Default, Debug)] 5 | // Struct for grouping read(rx) and transfered(tx) values together 6 | pub struct RxTx(pub (T, T)); 7 | impl RxTx { 8 | /// Returns a reference to rx value 9 | pub fn rx(&self) -> &T { 10 | &(self.0).0 11 | } 12 | /// Returns a reference to tx value 13 | pub fn tx(&self) -> &T { 14 | &(self.0).1 15 | } 16 | /// Returns a mutable reference to rx value 17 | pub fn rx_mut(&mut self) -> &mut T { 18 | &mut (self.0).0 19 | } 20 | /// Returns a mutable reference to tx value 21 | pub fn tx_mut(&mut self) -> &mut T { 22 | &mut (self.0).1 23 | } 24 | } 25 | impl RxTx { 26 | /// Increments both rx and transfered elements by coresponding values 27 | pub fn inc(&mut self, r: T, t: T) { 28 | self.rx_mut().add_assign(r); 29 | self.tx_mut().add_assign(t); 30 | } 31 | } 32 | impl RxTx { 33 | /// Returns rx value in scaled bytes/s as display string. 34 | pub fn rx_speed_str(&self) -> String { 35 | format!("{}/s", conv_fb(*self.rx())) 36 | } 37 | /// Returns tx value in scaled bytes/s as display string. 38 | pub fn tx_speed_str(&self) -> String { 39 | format!("{}/s", conv_fb(*self.tx())) 40 | } 41 | /// Returns scaled total rx bytes as display string. 42 | pub fn rx_bytes_str(&self) -> String { 43 | conv_fb(*self.rx()) 44 | } 45 | /// Returns scaled total tx bytes as display string 46 | pub fn tx_bytes_str(&self) -> String { 47 | conv_fb(*self.tx()) 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/cmd/show/common/screen.rs: -------------------------------------------------------------------------------- 1 | use std::time::Instant; 2 | use tui::{ 3 | style::{Modifier, Style}, 4 | text::Span, 5 | }; 6 | 7 | #[derive(Debug)] 8 | /// A helper struct for each monitor (cpu, storage, interface...) that 9 | /// gives a more convienient api to x axis, y axis and time of measurement. 10 | pub struct Screen { 11 | x_axis: [f64; 2], 12 | y_axis: [f64; 2], 13 | /// Monitor initialization time 14 | start_time: Instant, 15 | /// Last measurement time 16 | last_time: Instant, 17 | } 18 | impl Default for Screen { 19 | fn default() -> Self { 20 | Self::new((0., 0.), (0., 0.)) 21 | } 22 | } 23 | impl Screen { 24 | /// Returns a new instance of Monitor given x and y axis ranges. 25 | pub fn new(x: (f64, f64), y: (f64, f64)) -> Self { 26 | Self { 27 | x_axis: [x.0, x.1], 28 | y_axis: [y.0, y.1], 29 | start_time: Instant::now(), 30 | last_time: Instant::now(), 31 | } 32 | } 33 | 34 | /// Generic implementation of creating labels for axis bounds 35 | fn bounds_labels(&self, f: F, n: u32, min: f64, max: f64) -> Vec> 36 | where 37 | F: Fn(f64) -> String, 38 | { 39 | let mut spans = vec![Span::styled(f(min), Style::default().add_modifier(Modifier::BOLD))]; 40 | 41 | (1..n).into_iter().for_each(|i| { 42 | spans.push(Span::raw(f(min + (max - min) * (i as f64 / n as f64)))); 43 | }); 44 | 45 | spans.push(Span::styled(f(max), Style::default().add_modifier(Modifier::BOLD))); 46 | 47 | spans 48 | } 49 | 50 | /// Returns spans of y axis points divided into n parts and values of y axis 51 | /// converted with f 52 | pub fn y_bounds_labels(&self, f: F, n: u32) -> Vec> 53 | where 54 | F: Fn(f64) -> String, 55 | { 56 | self.bounds_labels(f, n, self.min_y(), self.max_y()) 57 | } 58 | 59 | /// Returns spans of x axis points divided into n parts and values of y axis 60 | /// converted with f 61 | pub fn x_bounds_labels(&self, f: F, n: u32) -> Vec> 62 | where 63 | F: Fn(f64) -> String, 64 | { 65 | self.bounds_labels(f, n, self.min_x(), self.max_x()) 66 | } 67 | 68 | /// Returns time elapsed since start in seconds 69 | pub fn elapsed_since_start(&self) -> f64 { 70 | self.start_time.elapsed().as_secs_f64() 71 | } 72 | 73 | /// Returns time since last measurement in seconds 74 | pub fn elapsed_since_last(&self) -> f64 { 75 | self.last_time.elapsed().as_secs_f64() 76 | } 77 | 78 | /// Updates last measurement time to current time 79 | pub fn update_last_time(&mut self) { 80 | self.last_time = Instant::now(); 81 | } 82 | 83 | /// Increment both ends of x axis by n 84 | pub fn inc_x_axis(&mut self, n: f64) { 85 | self.x_axis[0] += n; 86 | self.x_axis[1] += n; 87 | } 88 | 89 | /// Set second coordinate of y axis as y 90 | pub fn set_y_max(&mut self, y: f64) { 91 | self.y_axis[1] = y; 92 | } 93 | 94 | /// Set first coordinate of y axis as y 95 | pub fn set_y_min(&mut self, y: f64) { 96 | self.y_axis[0] = y; 97 | } 98 | 99 | /// Set second coordinate of y axis as y if y > current max 100 | pub fn set_if_y_max(&mut self, y: f64) { 101 | if y > self.max_y() { 102 | self.set_y_max(y) 103 | } 104 | } 105 | 106 | /// Set first coordinate of y axis as y if y < current min 107 | pub fn set_if_y_min(&mut self, y: f64) { 108 | if y < self.min_y() { 109 | self.set_y_min(y) 110 | } 111 | } 112 | 113 | /// Returns second coordinate of y 114 | pub fn max_y(&self) -> f64 { 115 | self.y_axis[1] 116 | } 117 | 118 | /// Returns first coordinate of y 119 | pub fn min_y(&self) -> f64 { 120 | self.y_axis[0] 121 | } 122 | 123 | /// Returns second coordinate of x 124 | pub fn max_x(&self) -> f64 { 125 | self.x_axis[1] 126 | } 127 | 128 | #[allow(dead_code)] 129 | /// Returns first coordinate of x 130 | pub fn min_x(&self) -> f64 { 131 | self.x_axis[0] 132 | } 133 | 134 | /// Returns y axis 135 | pub fn y(&self) -> [f64; 2] { 136 | self.y_axis 137 | } 138 | 139 | /// Returns x axis 140 | pub fn x(&self) -> [f64; 2] { 141 | self.x_axis 142 | } 143 | } 144 | -------------------------------------------------------------------------------- /src/cmd/show/common/widget.rs: -------------------------------------------------------------------------------- 1 | use super::{ 2 | err_popup, 3 | events::{Config, Event, Events}, 4 | get_terminal, Screen, 5 | }; 6 | use anyhow::Result; 7 | use std::borrow::Cow; 8 | use tui::{ 9 | backend::Backend, 10 | layout::{Constraint, Direction, Layout, Rect}, 11 | style::Style, 12 | text::Span, 13 | widgets::{Axis, Block, Borders, Chart, Dataset}, 14 | Frame, 15 | }; 16 | 17 | /// Trait grouping all widgets with state that needs updating 18 | /// together providing functionality like single_widget_loop. 19 | pub trait StatefulWidget { 20 | fn update(&mut self) -> Result<()>; 21 | fn render_widget(&self, f: &mut Frame, area: Rect); 22 | } 23 | 24 | /// Trait providing more readable way of creating graph widgets 25 | pub trait GraphWidget { 26 | fn datasets(&self) -> Vec; 27 | fn settings(&self) -> GraphSettings; 28 | fn monitor(&self) -> &Screen; 29 | 30 | fn chart(&self) -> Chart { 31 | Chart::new(self.datasets()) 32 | .block(Block::default().title(self.settings().title).borders(Borders::ALL)) 33 | .x_axis( 34 | Axis::default() 35 | .title(self.settings().x_title) 36 | .labels(self.settings().x_labels) 37 | .bounds(self.monitor().x()), 38 | ) 39 | .y_axis( 40 | Axis::default() 41 | .title(self.settings().y_title) 42 | .labels(self.settings().y_labels) 43 | .bounds(self.monitor().y()), 44 | ) 45 | } 46 | fn render_graph_widget(&self, f: &mut Frame, area: Rect) { 47 | let chart = self.chart(); 48 | f.render_widget(chart, area); 49 | } 50 | } 51 | 52 | pub trait InfoGraphWidget: GraphWidget { 53 | const DIRECTION: Direction; 54 | const CONSTRAINTS: [Constraint; 2]; 55 | fn render_extra_widget(&self, f: &mut Frame, area: Rect); 56 | 57 | fn render_widget(&self, f: &mut Frame, area: Rect) { 58 | let chunks = Layout::default() 59 | .direction(Self::DIRECTION) 60 | .constraints(Self::CONSTRAINTS) 61 | .split(area); 62 | 63 | self.render_extra_widget(f, chunks[0]); 64 | self.render_graph_widget(f, chunks[1]); 65 | } 66 | } 67 | 68 | pub trait Updatable { 69 | fn update(&mut self) -> Result<()>; 70 | } 71 | 72 | /// Loop a single widget on full screen endlessly 73 | pub fn single_widget_loop(widget: &mut W, config: Config) -> Result<()> { 74 | let mut terminal = get_terminal()?; 75 | let events = Events::with_config(config); 76 | let mut err_msg: Option = None; 77 | loop { 78 | terminal.draw(|f| { 79 | let size = f.size(); 80 | let layout = Layout::default().constraints([Constraint::Percentage(100)]).split(size); 81 | widget.render_widget(f, layout[0]); 82 | 83 | if let Some(err) = err_msg.clone() { 84 | err_popup(f, &err, "Press `q` to quit."); 85 | } 86 | })?; 87 | 88 | match events.next()? { 89 | Event::Input(input) => { 90 | if input == events.exit_key() { 91 | break; 92 | } 93 | } 94 | Event::Tick => { 95 | if let Err(e) = widget.update() { 96 | err_msg = Some(e.to_string()); 97 | } 98 | } 99 | } 100 | } 101 | Ok(()) 102 | } 103 | 104 | pub struct GraphSettings<'t, 'l> { 105 | pub title: Span<'t>, 106 | pub x_title: Span<'t>, 107 | pub y_title: Span<'t>, 108 | pub x_labels: Vec>, 109 | pub y_labels: Vec>, 110 | } 111 | impl<'t, 'l> Default for GraphSettings<'t, 'l> { 112 | fn default() -> Self { 113 | Self { 114 | title: Span::raw(""), 115 | x_title: Span::raw(""), 116 | y_title: Span::raw(""), 117 | x_labels: Vec::new(), 118 | y_labels: Vec::new(), 119 | } 120 | } 121 | } 122 | impl<'t, 'l> GraphSettings<'t, 'l> { 123 | pub fn new() -> Self { 124 | Self::default() 125 | } 126 | pub fn title>>(mut self, title: S, style: Style) -> Self { 127 | self.title = Span::styled(title.into(), style); 128 | self 129 | } 130 | pub fn x_title>>(mut self, x_axis: S, style: Style) -> Self { 131 | self.x_title = Span::styled(x_axis.into(), style); 132 | self 133 | } 134 | pub fn y_title>>(mut self, y_axis: S, style: Style) -> Self { 135 | self.y_title = Span::styled(y_axis.into(), style); 136 | self 137 | } 138 | pub fn x_labels(mut self, x_labels: Vec>) -> Self { 139 | self.x_labels = x_labels; 140 | self 141 | } 142 | pub fn y_labels(mut self, y_labels: Vec>) -> Self { 143 | self.y_labels = y_labels; 144 | self 145 | } 146 | } 147 | -------------------------------------------------------------------------------- /src/cmd/show/cpu/frequency.rs: -------------------------------------------------------------------------------- 1 | use super::{ 2 | common::{single_widget_loop, DataSeries, GraphSettings, GraphWidget, InfoGraphWidget, Monitor, Screen, Statistic}, 3 | events::Config, 4 | }; 5 | use crate::util::random_color; 6 | use crate::util::{conv_fhz, conv_hz, conv_t}; 7 | use anyhow::{anyhow, Result}; 8 | use rsys::linux::cpu::{processor, Core}; 9 | use tui::{ 10 | backend::Backend, 11 | layout::{Constraint, Direction, Layout, Rect}, 12 | style::{Color, Modifier, Style}, 13 | symbols, 14 | widgets::{Dataset, Row, Table}, 15 | Frame, 16 | }; 17 | 18 | const X_AXIS: (f64, f64) = (0., 30.0); 19 | const FREQUENCY_Y_AXIS: (f64, f64) = (f64::MAX, 0.); 20 | const TICK_RATE: u64 = 200; 21 | const CPU_INFO_HEADERS: &[&str] = &["core", "frequency"]; 22 | 23 | // Stats of a single core 24 | pub struct CoreFrequencyStat { 25 | name: String, 26 | frequency_data: DataSeries, 27 | core: Core, 28 | } 29 | impl From for CoreFrequencyStat { 30 | fn from(core: Core) -> Self { 31 | Self { 32 | name: format!("cpu{}", core.id), 33 | frequency_data: DataSeries::new(random_color(Some(20))), 34 | core, 35 | } 36 | } 37 | } 38 | impl Statistic for CoreFrequencyStat { 39 | // Updates core and returns its new frequency 40 | fn update(&mut self, m: &mut Screen) -> Result<()> { 41 | self.core 42 | .update() 43 | .map_err(|e| anyhow!("Failed to update core `{}` frequency - {}", self.name, e))?; 44 | let freq = self.core.cur_freq as f64; 45 | self.frequency_data.add(m.elapsed_since_start(), freq); 46 | 47 | m.set_if_y_max(freq + 100_000.); 48 | m.set_if_y_min(freq + 100_000.); 49 | 50 | Ok(()) 51 | } 52 | fn pop(&mut self) -> f64 { 53 | let removed = self.frequency_data.pop(); 54 | if let Some(point) = self.frequency_data.first() { 55 | return point.0 - removed.0; 56 | } 57 | 0. 58 | } 59 | fn name(&self) -> &str { 60 | &self.name 61 | } 62 | } 63 | 64 | impl Monitor { 65 | pub fn new() -> Result> { 66 | Ok(Monitor { 67 | stats: { 68 | let mut stats = processor()? 69 | .cores 70 | .into_iter() 71 | .map(CoreFrequencyStat::from) 72 | .collect::>(); 73 | stats.sort_by(|s1, s2| s1.core.id.cmp(&s2.core.id)); 74 | stats 75 | }, 76 | m: Screen::new(X_AXIS, FREQUENCY_Y_AXIS), 77 | }) 78 | } 79 | 80 | pub fn graph_loop() -> Result<()> { 81 | let mut monitor = Self::new()?; 82 | single_widget_loop(&mut monitor, Config::new(TICK_RATE)) 83 | } 84 | } 85 | 86 | impl GraphWidget for Monitor { 87 | fn datasets(&self) -> Vec { 88 | let mut data = Vec::new(); 89 | for core in &self.stats { 90 | data.push( 91 | Dataset::default() 92 | .name(core.name()) 93 | .marker(symbols::Marker::Braille) 94 | .style(Style::default().fg(core.frequency_data.color)) 95 | .data(&core.frequency_data.dataset()), 96 | ); 97 | } 98 | data 99 | } 100 | fn monitor(&self) -> &Screen { 101 | &self.m 102 | } 103 | fn settings(&self) -> GraphSettings { 104 | GraphSettings::new() 105 | .title( 106 | "Cpu Frequency", 107 | Style::default().add_modifier(Modifier::BOLD).fg(Color::Cyan), 108 | ) 109 | .x_title("Time", Style::default().fg(Color::White)) 110 | .y_title("Frequency", Style::default().fg(Color::White)) 111 | .x_labels(self.m.x_bounds_labels(conv_t, 4)) 112 | .y_labels(self.m.y_bounds_labels(conv_fhz, 4)) 113 | } 114 | } 115 | 116 | impl InfoGraphWidget for Monitor { 117 | const DIRECTION: Direction = Direction::Horizontal; 118 | const CONSTRAINTS: [Constraint; 2] = [Constraint::Percentage(20), Constraint::Min(80)]; 119 | 120 | fn render_extra_widget(&self, f: &mut Frame, area: Rect) { 121 | let chunks = Layout::default() 122 | .direction(Direction::Horizontal) 123 | .constraints([Constraint::Percentage(10), Constraint::Percentage(90)]) 124 | .split(area); 125 | 126 | let data = self.stats.iter().map(|s| { 127 | Row::StyledData( 128 | vec![s.name.clone(), conv_hz(s.core.cur_freq)].into_iter(), 129 | Style::default().fg(s.frequency_data.color), 130 | ) 131 | }); 132 | 133 | let table = 134 | Table::new(CPU_INFO_HEADERS.iter(), data).widths(&[Constraint::Percentage(25), Constraint::Percentage(60)]); 135 | 136 | f.render_widget(table, chunks[1]); 137 | } 138 | } 139 | -------------------------------------------------------------------------------- /src/cmd/show/cpu/mod.rs: -------------------------------------------------------------------------------- 1 | mod frequency; 2 | mod usage; 3 | 4 | use super::{common, events}; 5 | 6 | pub use frequency::CoreFrequencyStat; 7 | pub use usage::CoreUsageStat; 8 | -------------------------------------------------------------------------------- /src/cmd/show/cpu/usage.rs: -------------------------------------------------------------------------------- 1 | use super::{ 2 | common::{single_widget_loop, DataSeries, GraphSettings, GraphWidget, InfoGraphWidget, Monitor, Screen, Statistic}, 3 | events::Config, 4 | }; 5 | use crate::util::{conv_p, conv_t, random_color}; 6 | use anyhow::Result; 7 | use rsys::linux::cpu::{processor, Core}; 8 | use tui::{ 9 | backend::Backend, 10 | layout::{Constraint, Direction, Layout, Rect}, 11 | style::{Color, Modifier, Style}, 12 | symbols, 13 | widgets::{Block, Borders, Dataset, Gauge}, 14 | Frame, 15 | }; 16 | 17 | const X_AXIS: (f64, f64) = (0., 30.0); 18 | const USAGE_Y_AXIS: (f64, f64) = (0., 100.); 19 | const TICK_RATE: u64 = 250; 20 | 21 | #[derive(Debug)] 22 | pub struct CoreUsageStat { 23 | name: String, 24 | data: DataSeries, 25 | last_total_time: f64, 26 | last_idle_time: f64, 27 | last_usage: f64, 28 | core: Core, 29 | } 30 | impl From for CoreUsageStat { 31 | fn from(core: Core) -> Self { 32 | Self { 33 | name: format!("cpu{}", core.id), 34 | data: DataSeries::new(random_color(Some(20))), 35 | last_total_time: 0., 36 | last_idle_time: 0., 37 | last_usage: 0., 38 | core, 39 | } 40 | } 41 | } 42 | impl Statistic for CoreUsageStat { 43 | fn update(&mut self, m: &mut Screen) -> Result<()> { 44 | if let Some(times) = self.core.cpu_time()? { 45 | let total_time = times.total_time() as f64; 46 | let idle_time = times.idle_time() as f64; 47 | 48 | let idle_delta = idle_time - self.last_idle_time; 49 | let total_delta = total_time - self.last_total_time; 50 | 51 | self.last_usage = 100. * (1.0 - idle_delta / total_delta); 52 | self.data.add(m.elapsed_since_start(), self.last_usage); 53 | 54 | self.last_total_time = total_time; 55 | self.last_idle_time = idle_time; 56 | } 57 | 58 | Ok(()) 59 | } 60 | fn pop(&mut self) -> f64 { 61 | let removed = self.data.pop(); 62 | if let Some(point) = self.data.first() { 63 | return point.0 - removed.0; 64 | } 65 | 0. 66 | } 67 | fn name(&self) -> &str { 68 | &self.name 69 | } 70 | } 71 | 72 | impl Monitor { 73 | pub fn new() -> Result> { 74 | Ok(Monitor { 75 | stats: { 76 | let mut stats = processor()? 77 | .cores 78 | .into_iter() 79 | .map(CoreUsageStat::from) 80 | .collect::>(); 81 | stats.sort_by(|s1, s2| s1.core.id.cmp(&s2.core.id)); 82 | stats 83 | }, 84 | m: Screen::new(X_AXIS, USAGE_Y_AXIS), 85 | }) 86 | } 87 | pub fn graph_loop() -> Result<()> { 88 | let mut monitor = Monitor::::new()?; 89 | single_widget_loop(&mut monitor, Config::new(TICK_RATE)) 90 | } 91 | fn render_gauge_cores(&self, f: &mut Frame, area: Rect) { 92 | let mut constraints = Vec::new(); 93 | let count = self.stats.len(); 94 | let ratio = if count > 0 { (100 / count) as u16 } else { 100 }; 95 | self.stats 96 | .iter() 97 | .for_each(|_| constraints.push(Constraint::Percentage(ratio))); 98 | 99 | // Add an empty constraint so that last core is of equal size as the rest 100 | constraints.push(Constraint::Percentage(ratio)); 101 | 102 | let layout = Layout::default() 103 | .direction(Direction::Vertical) 104 | .constraints(constraints) 105 | .vertical_margin(0) 106 | .split(area); 107 | 108 | self.stats.iter().enumerate().for_each(|(i, s)| { 109 | let gauge = Gauge::default() 110 | .block(Block::default().title(s.name.as_str()).borders(Borders::ALL)) 111 | .percent(s.last_usage as u16) 112 | .gauge_style(Style::default().fg(s.data.color)); 113 | 114 | f.render_widget(gauge, layout[i]); 115 | }); 116 | } 117 | } 118 | 119 | impl GraphWidget for Monitor { 120 | fn datasets(&self) -> Vec { 121 | let mut data = Vec::new(); 122 | for core in &self.stats { 123 | data.push( 124 | Dataset::default() 125 | .name(core.name()) 126 | .marker(symbols::Marker::Braille) 127 | .style(Style::default().fg(core.data.color)) 128 | .data(&core.data.dataset()), 129 | ); 130 | } 131 | data 132 | } 133 | fn settings(&self) -> GraphSettings { 134 | GraphSettings::new() 135 | .title( 136 | "Cpu Usage", 137 | Style::default().add_modifier(Modifier::BOLD).fg(Color::Cyan), 138 | ) 139 | .x_title("Time", Style::default().fg(Color::White)) 140 | .y_title("Usage", Style::default().fg(Color::White)) 141 | .x_labels(self.m.x_bounds_labels(conv_t, 4)) 142 | .y_labels(self.m.y_bounds_labels(conv_p, 4)) 143 | } 144 | fn monitor(&self) -> &Screen { 145 | &self.m 146 | } 147 | } 148 | impl InfoGraphWidget for Monitor { 149 | const DIRECTION: Direction = Direction::Horizontal; 150 | const CONSTRAINTS: [Constraint; 2] = [Constraint::Percentage(20), Constraint::Min(80)]; 151 | 152 | fn render_extra_widget(&self, f: &mut Frame, area: Rect) { 153 | let chunks = Layout::default() 154 | .direction(Direction::Horizontal) 155 | .constraints([Constraint::Percentage(100)]) 156 | .split(area); 157 | 158 | self.render_gauge_cores(f, chunks[0]); 159 | } 160 | } 161 | -------------------------------------------------------------------------------- /src/cmd/show/events.rs: -------------------------------------------------------------------------------- 1 | use std::{io, sync::mpsc, thread, time::Duration}; 2 | use termion::{event::Key, input::TermRead}; 3 | 4 | pub const DEFAULT_TICK_RATE: u64 = 1000; 5 | 6 | #[derive(Debug)] 7 | pub enum Event { 8 | Input(I), 9 | Tick, 10 | } 11 | 12 | #[derive(Debug)] 13 | pub struct Events { 14 | rx: mpsc::Receiver>, 15 | config: Config, 16 | } 17 | 18 | #[derive(Debug, Clone, Copy)] 19 | pub struct Config { 20 | pub exit_key: Key, 21 | pub tick_rate: Duration, 22 | } 23 | impl Config { 24 | pub fn new(tick_rate: u64) -> Config { 25 | Config { 26 | exit_key: Key::Char('q'), 27 | tick_rate: Duration::from_millis(tick_rate), 28 | } 29 | } 30 | } 31 | 32 | impl Default for Config { 33 | fn default() -> Config { 34 | Config { 35 | exit_key: Key::Char('q'), 36 | tick_rate: Duration::from_millis(DEFAULT_TICK_RATE), 37 | } 38 | } 39 | } 40 | 41 | impl Events { 42 | pub fn with_config(config: Config) -> Events { 43 | let (tx, rx) = mpsc::channel(); 44 | let _ = { 45 | let tx = tx.clone(); 46 | thread::spawn(move || { 47 | let stdin = io::stdin(); 48 | for evt in stdin.keys() { 49 | if let Ok(key) = evt { 50 | if tx.send(Event::Input(key)).is_err() { 51 | return; 52 | } 53 | if key == config.exit_key { 54 | return; 55 | } 56 | } 57 | } 58 | }) 59 | }; 60 | let _ = { 61 | thread::spawn(move || loop { 62 | if tx.send(Event::Tick).is_err() { 63 | break; 64 | } 65 | thread::sleep(config.tick_rate); 66 | }) 67 | }; 68 | Events { rx, config } 69 | } 70 | 71 | pub fn next(&self) -> Result, mpsc::RecvError> { 72 | self.rx.recv() 73 | } 74 | 75 | pub fn exit_key(&self) -> Key { 76 | self.config.exit_key 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /src/cmd/show/mod.rs: -------------------------------------------------------------------------------- 1 | mod common; 2 | mod cpu; 3 | mod events; 4 | mod net; 5 | mod ps; 6 | mod storage; 7 | 8 | use crate::RsysCli; 9 | use common::{err_popup, Monitor, StatefulWidget}; 10 | use cpu::{CoreFrequencyStat, CoreUsageStat}; 11 | use events::{Config, Event, Events}; 12 | use net::IfaceSpeedStat; 13 | use ps::ProcessMonitor; 14 | use storage::StorageSpeedStat; 15 | 16 | use anyhow::Error; 17 | use std::io::{self, stdout}; 18 | use structopt::StructOpt; 19 | use termion::{ 20 | event::Key, 21 | input::MouseTerminal, 22 | raw::{IntoRawMode, RawTerminal}, 23 | screen::AlternateScreen, 24 | }; 25 | use tui::{ 26 | backend::TermionBackend, 27 | layout::{Constraint, Layout}, 28 | Terminal, 29 | }; 30 | 31 | type Term = Terminal>>>>; 32 | use anyhow::{anyhow, Result}; 33 | 34 | pub fn get_terminal() -> Result { 35 | let stdout = stdout().into_raw_mode()?; 36 | let stdout = MouseTerminal::from(stdout); 37 | let stdout = AlternateScreen::from(stdout); 38 | let backend = TermionBackend::new(stdout); 39 | Terminal::new(backend).map_err(|e| anyhow!("Failed to get terminal handle - {}", e)) 40 | } 41 | 42 | #[derive(StructOpt, Clone)] 43 | pub enum ShowCmd { 44 | /// Draw interface rx/tx speed 45 | Interface { name: String }, 46 | /// Draw cpu usage 47 | CpuUsage, 48 | /// Draw cpu core frequencies 49 | CpuFreq, 50 | /// Display I/O stats for storage devices 51 | Storage, 52 | /// Display network interfaces graphs 53 | Net, 54 | /// Display process list 55 | Ps, 56 | /// Display all graphs at once 57 | All, 58 | } 59 | 60 | impl RsysCli { 61 | pub fn show(&self, cmd: ShowCmd) { 62 | let result = match cmd { 63 | ShowCmd::Interface { name } => Monitor::::single_iface_loop(&name), 64 | ShowCmd::CpuFreq => Monitor::::graph_loop(), 65 | ShowCmd::CpuUsage => Monitor::::graph_loop(), 66 | ShowCmd::Storage => Monitor::::graph_loop(), 67 | ShowCmd::Net => Monitor::::graph_loop(None), 68 | ShowCmd::Ps => ProcessMonitor::display_loop(), 69 | ShowCmd::All => show_all_loop(), 70 | }; 71 | 72 | if let Err(e) = result { 73 | eprintln!("Error: {}", e); 74 | } 75 | } 76 | } 77 | 78 | /// A loop with all graph widgets groupped together 79 | pub fn show_all_loop() -> Result<()> { 80 | let mut terminal = get_terminal()?; 81 | let events = Events::with_config(Config::new(200)); 82 | let mut cpumon = Monitor::::new()?; 83 | let mut ifacemon = Monitor::::new(None)?; 84 | let mut stormon = Monitor::::new()?; 85 | let mut errors: Vec = Vec::new(); 86 | let mut show_errors = true; 87 | let mut was_error = false; 88 | loop { 89 | terminal.draw(|f| { 90 | let size = f.size(); 91 | let layout = Layout::default() 92 | .constraints([ 93 | Constraint::Percentage(33), 94 | Constraint::Percentage(33), 95 | Constraint::Percentage(33), 96 | ]) 97 | .split(size); 98 | 99 | if !errors.is_empty() && show_errors { 100 | let error = &errors[0]; 101 | was_error = true; 102 | err_popup(f, &error.to_string(), "`q` - quit, `i` - ignore errors, `c` - continue") 103 | } else { 104 | cpumon.render_widget(f, layout[0]); 105 | ifacemon.render_widget(f, layout[1]); 106 | stormon.render_widget(f, layout[2]); 107 | } 108 | })?; 109 | 110 | match events.next()? { 111 | Event::Input(input) => { 112 | if input == events.exit_key() { 113 | break; 114 | } 115 | 116 | match input { 117 | Key::Char('c') if was_error => { 118 | errors.pop(); 119 | was_error = false; 120 | } 121 | Key::Char('i') => show_errors = false, 122 | _ => {} 123 | } 124 | } 125 | Event::Tick => { 126 | if let Err(e) = cpumon.update() { 127 | errors.push(e); 128 | } 129 | if let Err(e) = ifacemon.update() { 130 | errors.push(e); 131 | } 132 | if let Err(e) = stormon.update() { 133 | errors.push(e); 134 | } 135 | } 136 | } 137 | } 138 | 139 | Ok(()) 140 | } 141 | -------------------------------------------------------------------------------- /src/cmd/show/net.rs: -------------------------------------------------------------------------------- 1 | use super::{ 2 | common::{ 3 | kv_span, single_widget_loop, spans_from, DataSeries, GraphSettings, GraphWidget, InfoGraphWidget, Monitor, 4 | RxTx, Screen, Statistic, 5 | }, 6 | events::Config, 7 | }; 8 | use crate::util::{conv_fbs, conv_t, random_color}; 9 | use anyhow::{anyhow, Result}; 10 | use rsys::linux::net::{ifaces, Interface}; 11 | use tui::{ 12 | backend::Backend, 13 | layout::{Constraint, Direction, Layout, Rect}, 14 | style::{Color, Modifier, Style}, 15 | symbols, 16 | text::{Span, Spans}, 17 | widgets::{Dataset, Paragraph}, 18 | Frame, 19 | }; 20 | 21 | const X_AXIS: (f64, f64) = (0., 30.0); 22 | const Y_AXIS: (f64, f64) = (0., 100.0); 23 | const TICK_RATE: u64 = 300; 24 | 25 | pub struct IfaceSpeedStat { 26 | iface: Interface, 27 | data: RxTx, 28 | prev_bytes: RxTx, 29 | curr_speed: RxTx, 30 | total: RxTx, 31 | } 32 | impl Statistic for IfaceSpeedStat { 33 | // Updates core and returns its new frequency 34 | fn update(&mut self, m: &mut Screen) -> Result<()> { 35 | self.iface 36 | .update() 37 | .map_err(|e| anyhow!("Failed to update interface `{}` - {}", self.iface.name, e.to_string()))?; 38 | 39 | let (delta_rx, delta_tx) = self.delta(); 40 | 41 | self.total.inc(delta_rx, delta_tx); 42 | 43 | self.curr_speed = RxTx((delta_rx / m.elapsed_since_last(), delta_tx / m.elapsed_since_last())); 44 | self.data.rx_mut().add(m.elapsed_since_start(), *self.curr_speed.rx()); 45 | self.data.tx_mut().add(m.elapsed_since_start(), *self.curr_speed.tx()); 46 | 47 | m.set_if_y_max(*self.curr_speed.rx() + 100.); 48 | m.set_if_y_max(*self.curr_speed.tx() + 100.); 49 | 50 | self.prev_bytes = RxTx((self.iface.stat.rx_bytes, self.iface.stat.tx_bytes)); 51 | 52 | Ok(()) 53 | } 54 | fn pop(&mut self) -> f64 { 55 | let removed = self.data.rx_mut().pop(); 56 | self.data.tx_mut().pop(); 57 | 58 | if let Some(point) = self.data.rx().first() { 59 | return point.0 - removed.0; 60 | } 61 | 0. 62 | } 63 | fn name(&self) -> &str { 64 | &self.iface.name 65 | } 66 | } 67 | impl IfaceSpeedStat { 68 | fn new(iface: Interface) -> Self { 69 | let rx = iface.stat.rx_bytes; 70 | let tx = iface.stat.tx_bytes; 71 | Self { 72 | iface, 73 | data: RxTx(( 74 | DataSeries::new(random_color(Some(20))), 75 | DataSeries::new(random_color(Some(20))), 76 | )), 77 | prev_bytes: RxTx((rx, tx)), 78 | curr_speed: RxTx::default(), 79 | total: RxTx::default(), 80 | } 81 | } 82 | fn delta(&mut self) -> (f64, f64) { 83 | ( 84 | (self.iface.stat.rx_bytes - self.prev_bytes.rx()) as f64, 85 | (self.iface.stat.tx_bytes - self.prev_bytes.tx()) as f64, 86 | ) 87 | } 88 | fn info(&self) -> Paragraph { 89 | Paragraph::new(vec![ 90 | Spans::from(Span::styled( 91 | &self.iface.name, 92 | Style::default().add_modifier(Modifier::BOLD).fg(Color::Green), 93 | )), 94 | spans_from(vec![kv_span( 95 | " Vrx : ", 96 | &self.curr_speed.rx_speed_str(), 97 | self.data.rx().color, 98 | true, 99 | )]), 100 | spans_from(vec![kv_span( 101 | " Σrx : ", 102 | &self.total.rx_bytes_str(), 103 | self.data.rx().color, 104 | true, 105 | )]), 106 | spans_from(vec![kv_span( 107 | " Vtx : ", 108 | &self.curr_speed.tx_speed_str(), 109 | self.data.tx().color, 110 | true, 111 | )]), 112 | spans_from(vec![kv_span( 113 | " Σtx : ", 114 | &self.total.tx_bytes_str(), 115 | self.data.tx().color, 116 | true, 117 | )]), 118 | spans_from(vec![kv_span(" ipv4: ", &self.iface.ipv4, Color::White, true)]), 119 | spans_from(vec![kv_span(" ipv6: ", &self.iface.ipv6, Color::White, true)]), 120 | spans_from(vec![kv_span( 121 | " mtu : ", 122 | &self.iface.mtu.to_string(), 123 | Color::White, 124 | true, 125 | )]), 126 | spans_from(vec![kv_span(" mac : ", &self.iface.mac_address, Color::White, true)]), 127 | ]) 128 | } 129 | } 130 | impl From for IfaceSpeedStat { 131 | fn from(iface: Interface) -> IfaceSpeedStat { 132 | IfaceSpeedStat::new(iface) 133 | } 134 | } 135 | 136 | impl GraphWidget for Monitor { 137 | fn datasets(&self) -> Vec { 138 | let mut data = Vec::new(); 139 | for iface in &self.stats { 140 | data.push( 141 | Dataset::default() 142 | .name(format!("{} rx", iface.iface.name)) 143 | .marker(symbols::Marker::Dot) 144 | .style(Style::default().fg(iface.data.rx().color)) 145 | .data(&iface.data.rx().dataset()), 146 | ); 147 | data.push( 148 | Dataset::default() 149 | .name(format!("{} tx", iface.iface.name)) 150 | .marker(symbols::Marker::Braille) 151 | .style(Style::default().fg(iface.data.tx().color)) 152 | .data(&iface.data.tx().dataset()), 153 | ); 154 | } 155 | data 156 | } 157 | fn settings(&self) -> GraphSettings { 158 | GraphSettings::new() 159 | .title( 160 | "Network Speed", 161 | Style::default().add_modifier(Modifier::BOLD).fg(Color::Cyan), 162 | ) 163 | .x_title("Time", Style::default().fg(Color::White)) 164 | .y_title("Speed", Style::default().fg(Color::White)) 165 | .x_labels(self.m.x_bounds_labels(conv_t, 4)) 166 | .y_labels(self.m.y_bounds_labels(conv_fbs, 5)) 167 | } 168 | fn monitor(&self) -> &Screen { 169 | &self.m 170 | } 171 | } 172 | 173 | impl Monitor { 174 | pub fn new(filter: Option<&[&str]>) -> Result> { 175 | let stats = ifaces()? 176 | .0 177 | .into_iter() 178 | .filter(|s| { 179 | if let Some(filters) = filter { 180 | for f in filters { 181 | if *f == s.name { 182 | return true; 183 | } else { 184 | continue; 185 | } 186 | } 187 | false 188 | } else { 189 | true 190 | } 191 | }) 192 | .map(IfaceSpeedStat::from) 193 | .collect::>(); 194 | 195 | if stats.is_empty() { 196 | return Err(anyhow!("No interface matched passed in filter `{:?}`", filter)); 197 | } 198 | 199 | Ok(Monitor { 200 | stats, 201 | m: Screen::new(X_AXIS, Y_AXIS), 202 | }) 203 | } 204 | 205 | pub fn graph_loop(filter: Option<&[&str]>) -> Result<()> { 206 | let mut monitor = Self::new(filter)?; 207 | single_widget_loop(&mut monitor, Config::new(TICK_RATE)) 208 | } 209 | 210 | pub fn single_iface_loop(name: &str) -> Result<()> { 211 | Self::graph_loop(Some(&[name])) 212 | } 213 | } 214 | impl InfoGraphWidget for Monitor { 215 | const DIRECTION: Direction = Direction::Horizontal; 216 | const CONSTRAINTS: [Constraint; 2] = [Constraint::Percentage(20), Constraint::Min(80)]; 217 | 218 | fn render_extra_widget(&self, f: &mut Frame, area: Rect) { 219 | let count = self.stats.len(); 220 | let percentage = if count == 0 { 1_u16 } else { (100 / count) as u16 }; 221 | let constraints = (0..count) 222 | .into_iter() 223 | .map(|_| Constraint::Percentage(percentage)) 224 | .collect::>(); 225 | let chunks = Layout::default() 226 | .direction(Direction::Vertical) 227 | .constraints(constraints) 228 | .split(area); 229 | self.stats 230 | .iter() 231 | .enumerate() 232 | .for_each(|(i, s)| f.render_widget(s.info(), chunks[i])); 233 | } 234 | } 235 | -------------------------------------------------------------------------------- /src/cmd/show/ps.rs: -------------------------------------------------------------------------------- 1 | use super::{ 2 | common::{single_widget_loop, StatefulWidget}, 3 | events::Config, 4 | }; 5 | use anyhow::Result; 6 | use rsys::linux::ps::{processes, Process}; 7 | use tui::{ 8 | backend::Backend, 9 | layout::{Constraint, Direction, Layout, Rect}, 10 | style::Style, 11 | widgets::{Row, Table}, 12 | Frame, 13 | }; 14 | 15 | const PS_HEADERS: &[&str] = &["pid", "name", "state", "vsize", "rss", "utime", "stime"]; 16 | 17 | pub struct ProcessMonitor { 18 | processes: Vec, 19 | } 20 | 21 | impl StatefulWidget for ProcessMonitor { 22 | fn update(&mut self) -> Result<()> { 23 | for process in &mut self.processes { 24 | process.stat.update()?; 25 | } 26 | Ok(()) 27 | } 28 | fn render_widget(&self, f: &mut Frame, area: Rect) { 29 | let chunks = Layout::default() 30 | .direction(Direction::Horizontal) 31 | .constraints([Constraint::Percentage(100)].as_ref()) 32 | .split(area); 33 | 34 | self.render_storage_info_widget(f, chunks[0]); 35 | } 36 | } 37 | 38 | impl ProcessMonitor { 39 | pub fn new() -> Result { 40 | Ok(ProcessMonitor { 41 | processes: processes()?, 42 | }) 43 | } 44 | 45 | fn render_storage_info_widget(&self, f: &mut Frame, area: Rect) { 46 | let data = self.processes.iter().map(|s| { 47 | Row::StyledData( 48 | vec![ 49 | s.stat.pid.to_string(), 50 | s.stat.name.to_string(), 51 | s.stat.state.to_string(), 52 | s.stat.vsize.to_string(), 53 | s.stat.rss.to_string(), 54 | s.stat.utime.to_string(), 55 | s.stat.stime.to_string(), 56 | ] 57 | .into_iter(), 58 | Style::default(), 59 | ) 60 | }); 61 | 62 | let table = Table::new(PS_HEADERS.iter(), data).widths(&[ 63 | Constraint::Percentage(14), 64 | Constraint::Percentage(14), 65 | Constraint::Percentage(14), 66 | Constraint::Percentage(14), 67 | Constraint::Percentage(14), 68 | Constraint::Percentage(14), 69 | Constraint::Percentage(14), 70 | ]); 71 | 72 | f.render_widget(table, area); 73 | } 74 | 75 | pub fn display_loop() -> Result<()> { 76 | let mut pmon = ProcessMonitor::new()?; 77 | single_widget_loop(&mut pmon, Config::default()) 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /src/cmd/show/storage.rs: -------------------------------------------------------------------------------- 1 | use super::{ 2 | common::{ 3 | single_widget_loop, DataSeries, GraphSettings, GraphWidget, InfoGraphWidget, Monitor, RxTx, Screen, Statistic, 4 | }, 5 | events::Config, 6 | }; 7 | use crate::util::{conv_fbs, conv_t, random_color}; 8 | use anyhow::{anyhow, Result}; 9 | use rsys::linux::storage::{storage_devices_info, BlockStorageInfo}; 10 | use tui::{ 11 | backend::Backend, 12 | layout::{Constraint, Direction, Rect}, 13 | style::{Color, Modifier, Style}, 14 | symbols, 15 | widgets::{Dataset, Row, Table}, 16 | Frame, 17 | }; 18 | 19 | const X_AXIS: (f64, f64) = (0., 30.0); 20 | const Y_AXIS: (f64, f64) = (0., 100.); 21 | const TICK_RATE: u64 = 200; 22 | const SECTOR_SIZE: f64 = 512.; 23 | const STORAGE_INFO_HEADERS: &[&str] = &["name", "rx/s", "wx/s", "Σrx", "Σwx"]; 24 | 25 | #[derive(Debug)] 26 | // Stats of a single block storage device 27 | pub struct StorageSpeedStat { 28 | name: String, 29 | color: Color, 30 | device: BlockStorageInfo, 31 | data: RxTx, 32 | speed: RxTx, 33 | total: RxTx, 34 | } 35 | impl From for StorageSpeedStat { 36 | fn from(info: BlockStorageInfo) -> Self { 37 | Self { 38 | name: info.dev.to_string(), 39 | color: random_color(Some(20)), 40 | device: info, 41 | data: RxTx(( 42 | DataSeries::new(random_color(Some(20))), 43 | DataSeries::new(random_color(Some(20))), 44 | )), 45 | speed: RxTx::default(), 46 | total: RxTx::default(), 47 | } 48 | } 49 | } 50 | impl Statistic for StorageSpeedStat { 51 | fn update(&mut self, m: &mut Screen) -> Result<()> { 52 | let (rx_before, wx_before) = self.sectors(); 53 | let time_delta = m.elapsed_since_last(); 54 | 55 | self.device 56 | .update_stats() 57 | .map_err(|e| anyhow!("Failed to update block device `{}` stats - {}", self.name, e))?; 58 | 59 | let (rx_after, wx_after) = self.sectors(); 60 | 61 | let rx_delta = rx_after - rx_before; 62 | let wx_delta = wx_after - wx_before; 63 | 64 | self.total.inc(rx_delta, wx_delta); 65 | self.speed = RxTx((rx_delta / time_delta, wx_delta / time_delta)); 66 | 67 | m.set_if_y_max(*self.speed.rx() + 100.); 68 | m.set_if_y_max(*self.speed.tx() + 100.); 69 | 70 | self.add_current(m.elapsed_since_start()); 71 | 72 | Ok(()) 73 | } 74 | fn pop(&mut self) -> f64 { 75 | let removed = self.data.rx_mut().pop(); 76 | self.data.tx_mut().pop(); 77 | 78 | if let Some(point) = self.data.rx().first() { 79 | return point.0 - removed.0; 80 | } 81 | 0. 82 | } 83 | fn name(&self) -> &str { 84 | &self.name 85 | } 86 | } 87 | impl StorageSpeedStat { 88 | fn sectors(&mut self) -> (f64, f64) { 89 | if let Some(stat) = &self.device.stat { 90 | ( 91 | stat.read_sectors as f64 * SECTOR_SIZE, 92 | stat.write_sectors as f64 * SECTOR_SIZE, 93 | ) 94 | } else { 95 | (0., 0.) 96 | } 97 | } 98 | 99 | fn add_current(&mut self, time: f64) { 100 | self.data.rx_mut().add(time, *self.speed.rx()); 101 | self.data.tx_mut().add(time, *self.speed.tx()); 102 | } 103 | } 104 | 105 | impl GraphWidget for Monitor { 106 | fn datasets(&self) -> Vec { 107 | let mut data = Vec::new(); 108 | for device in &self.stats { 109 | data.push( 110 | Dataset::default() 111 | .name(format!("rx {}", &device.name)) 112 | .marker(symbols::Marker::Dot) 113 | .style(Style::default().fg(device.color)) 114 | .data(&device.data.rx().dataset()), 115 | ); 116 | data.push( 117 | Dataset::default() 118 | .name(format!("wx {}", &device.name)) 119 | .marker(symbols::Marker::Braille) 120 | .style(Style::default().fg(device.color)) 121 | .data(&device.data.tx().dataset()), 122 | ); 123 | } 124 | data 125 | } 126 | fn settings(&self) -> GraphSettings { 127 | GraphSettings::new() 128 | .title( 129 | "Storage devices", 130 | Style::default().add_modifier(Modifier::BOLD).fg(Color::Cyan), 131 | ) 132 | .x_title("Time", Style::default().fg(Color::White)) 133 | .y_title("r/w speed", Style::default().fg(Color::White)) 134 | .x_labels(self.m.x_bounds_labels(conv_t, 4)) 135 | .y_labels(self.m.y_bounds_labels(conv_fbs, 5)) 136 | } 137 | fn monitor(&self) -> &Screen { 138 | &self.m 139 | } 140 | } 141 | 142 | impl InfoGraphWidget for Monitor { 143 | const DIRECTION: Direction = Direction::Horizontal; 144 | const CONSTRAINTS: [Constraint; 2] = [Constraint::Percentage(20), Constraint::Min(80)]; 145 | 146 | fn render_extra_widget(&self, f: &mut Frame, area: Rect) { 147 | let data = self.stats.iter().map(|s| { 148 | Row::StyledData( 149 | vec![ 150 | s.name.to_string(), 151 | s.speed.rx_speed_str(), 152 | s.speed.tx_speed_str(), 153 | s.total.rx_bytes_str(), 154 | s.total.tx_bytes_str(), 155 | ] 156 | .into_iter(), 157 | Style::default().fg(s.color), 158 | ) 159 | }); 160 | 161 | let table = Table::new(STORAGE_INFO_HEADERS.iter(), data) 162 | .widths(&[ 163 | Constraint::Percentage(10), 164 | Constraint::Percentage(20), 165 | Constraint::Percentage(20), 166 | Constraint::Percentage(16), 167 | Constraint::Percentage(16), 168 | ]) 169 | .header_gap(1) 170 | .column_spacing(1); 171 | 172 | f.render_widget(table, area); 173 | } 174 | } 175 | 176 | impl Monitor { 177 | pub fn new() -> Result> { 178 | Ok(Monitor { 179 | stats: { 180 | let mut stats = storage_devices_info() 181 | .map_err(|e| anyhow!("Failed to get storage devices info - {}", e))? 182 | .into_iter() 183 | .map(StorageSpeedStat::from) 184 | .collect::>(); 185 | stats.sort_by(|s1, s2| s1.name.cmp(&s2.name)); 186 | stats 187 | }, 188 | m: Screen::new(X_AXIS, Y_AXIS), 189 | }) 190 | } 191 | pub fn graph_loop() -> Result<()> { 192 | let mut monitor = Monitor::::new()?; 193 | single_widget_loop(&mut monitor, Config::new(TICK_RATE)) 194 | } 195 | } 196 | -------------------------------------------------------------------------------- /src/cmd/watch.rs: -------------------------------------------------------------------------------- 1 | use super::WatchOpts; 2 | use crate::{ 3 | cli::RsysCli, 4 | cmd::common::SystemInfo, 5 | util::{print, PrintFormat}, 6 | }; 7 | use rsys::Result; 8 | use std::{ 9 | thread, 10 | time::{Duration, Instant}, 11 | }; 12 | 13 | impl RsysCli { 14 | pub fn watch(&self, opts: WatchOpts) -> Result<()> { 15 | let duration = if let Some(d) = opts.duration { 16 | Duration::from_secs(d) 17 | } else { 18 | Duration::from_secs(u64::MAX) 19 | }; 20 | let interval: u128 = if let Some(i) = opts.interval { i as u128 } else { 1000 }; 21 | let loop_start = Instant::now(); 22 | loop { 23 | let print_start = Instant::now(); 24 | print( 25 | SystemInfo::new( 26 | &self.system, 27 | false, 28 | true, 29 | false, 30 | true, 31 | false, 32 | false, 33 | opts.cpu, 34 | opts.memory, 35 | opts.network, 36 | opts.storage, 37 | false, 38 | opts.all, 39 | opts.stats, 40 | false, 41 | )?, 42 | PrintFormat::Json, 43 | opts.pretty, 44 | )?; 45 | println!(); 46 | let print_duration = print_start.elapsed().as_millis(); 47 | if loop_start.elapsed() > duration { 48 | break; 49 | } 50 | if print_duration < interval { 51 | let sleep_duration = Duration::from_millis((interval - print_duration) as u64); 52 | thread::sleep(sleep_duration); 53 | } 54 | } 55 | Ok(()) 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/main.rs: -------------------------------------------------------------------------------- 1 | #[macro_use] 2 | extern crate prettytable; 3 | pub mod cli; 4 | pub mod cmd; 5 | pub mod util; 6 | use cli::RsysCli; 7 | 8 | fn main() { 9 | let rsys = RsysCli::new(); 10 | if let Err(e) = rsys.main() { 11 | eprintln!("Error: {}", e); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/util.rs: -------------------------------------------------------------------------------- 1 | use rand::seq::IteratorRandom; 2 | use rsys::{Error, Result}; 3 | use serde::Serialize; 4 | use serde_json as json; 5 | use serde_yaml as yaml; 6 | use std::any::type_name; 7 | use std::fmt::{Debug, Display}; 8 | use tui::style::Color; 9 | 10 | const KILO: f64 = 1000.; 11 | const MEGA: f64 = KILO * KILO; 12 | const GIGA: f64 = KILO * KILO * KILO; 13 | const TERA: f64 = KILO * KILO * KILO * KILO; 14 | 15 | pub enum PrintFormat { 16 | Normal, 17 | Json, 18 | Yaml, 19 | } 20 | impl PrintFormat { 21 | pub fn from_bools(json: bool, yaml: bool) -> Self { 22 | if json { 23 | PrintFormat::Json 24 | } else if yaml { 25 | PrintFormat::Yaml 26 | } else { 27 | PrintFormat::Normal 28 | } 29 | } 30 | } 31 | 32 | pub fn json_to_string(val: T, pretty: bool) -> Result { 33 | let f = if pretty { 34 | json::to_string_pretty 35 | } else { 36 | json::to_string 37 | }; 38 | 39 | f(&val).map_err(|e| Error::SerializeError(type_name::().to_string(), e.to_string())) 40 | } 41 | 42 | pub fn print(val: T, format: PrintFormat, pretty: bool) -> Result<()> { 43 | match format { 44 | PrintFormat::Normal => { 45 | if pretty { 46 | print!("{:#?}", val); 47 | } else { 48 | print!("{}", val); 49 | } 50 | } 51 | PrintFormat::Json => { 52 | print!("{}", json_to_string(val, pretty)?); 53 | } 54 | PrintFormat::Yaml => { 55 | print!( 56 | "{}", 57 | yaml::to_string(&val) 58 | .map_err(|e| Error::SerializeError(type_name::().to_string(), e.to_string()))? 59 | ); 60 | } 61 | } 62 | 63 | Ok(()) 64 | } 65 | 66 | pub fn handle_err(res: Result) -> T { 67 | match res { 68 | Ok(val) => val, 69 | Err(e) => { 70 | eprintln!("Error: {}", e); 71 | T::default() 72 | } 73 | } 74 | } 75 | 76 | fn conv_metric(value: f64, unit: &str) -> String { 77 | let (val, u) = if value < KILO { 78 | (value, "") 79 | } else if KILO <= value && value < MEGA { 80 | (value / KILO, "K") 81 | } else if MEGA <= value && value < GIGA { 82 | (value / MEGA, "M") 83 | } else if GIGA <= value && value < TERA { 84 | (value / GIGA, "G") 85 | } else { 86 | (value / TERA, "T") 87 | }; 88 | 89 | format!("{:.2}{}{}", val, u, unit) 90 | } 91 | 92 | pub fn conv_fbs(bytes: f64) -> String { 93 | conv_metric(bytes, "B/s") 94 | } 95 | 96 | pub fn conv_fb(bytes: f64) -> String { 97 | conv_metric(bytes, "B") 98 | } 99 | 100 | pub fn conv_b(bytes: u64) -> String { 101 | conv_fb(bytes as f64) 102 | } 103 | 104 | pub fn conv_hz(hz: u64) -> String { 105 | conv_fhz(hz as f64) 106 | } 107 | 108 | pub fn conv_fhz(hz: f64) -> String { 109 | conv_metric(hz, "Hz") 110 | } 111 | 112 | pub fn conv_t(time: f64) -> String { 113 | format!("{:.1}s", time) 114 | } 115 | 116 | pub fn conv_p(val: f64) -> String { 117 | format!("{:.1}%", val) 118 | } 119 | 120 | pub fn random_color(min: Option) -> Color { 121 | let mut rng = rand::thread_rng(); 122 | let mut color: [u8; 3] = [0, 0, 0]; 123 | 124 | let low = if let Some(min) = min { min } else { 0 }; 125 | 126 | (low..255).choose_multiple_fill(&mut rng, &mut color); 127 | Color::Rgb(color[0], color[1], color[2]) 128 | } 129 | --------------------------------------------------------------------------------