├── .dockerignore ├── .gitignore ├── .travis.yml ├── Cargo.lock ├── Cargo.toml ├── Dockerfile ├── LICENSE ├── README.md ├── resources └── favicon.ico └── src ├── index.html ├── lib.rs ├── main.rs ├── sysinfo_ext.rs ├── sysinfo_serde.rs └── web.rs /.dockerignore: -------------------------------------------------------------------------------- 1 | *.md 2 | *.yml 3 | .gitignore 4 | .git 5 | 6 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | target 2 | Cargo.lock 3 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: rust 2 | matrix: 3 | include: 4 | - os: linux 5 | rust: nightly 6 | dist: trusty 7 | - os: linux 8 | rust: stable 9 | dist: trusty 10 | - os: osx 11 | rust: nightly 12 | - os: osx 13 | rust: stable 14 | sudo: true 15 | env: 16 | global: 17 | - LD_LIBRARY_PATH=/usr/local/lib 18 | script: 19 | - rustc --version 20 | - RUST_BACKTRACE=1 cargo build 21 | - RUST_BACKTRACE=1 cargo test 22 | -------------------------------------------------------------------------------- /Cargo.lock: -------------------------------------------------------------------------------- 1 | [[package]] 2 | name = "arrayvec" 3 | version = "0.4.7" 4 | source = "registry+https://github.com/rust-lang/crates.io-index" 5 | dependencies = [ 6 | "nodrop 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", 7 | ] 8 | 9 | [[package]] 10 | name = "base64" 11 | version = "0.6.0" 12 | source = "registry+https://github.com/rust-lang/crates.io-index" 13 | dependencies = [ 14 | "byteorder 1.2.3 (registry+https://github.com/rust-lang/crates.io-index)", 15 | "safemem 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", 16 | ] 17 | 18 | [[package]] 19 | name = "bitflags" 20 | version = "1.0.3" 21 | source = "registry+https://github.com/rust-lang/crates.io-index" 22 | 23 | [[package]] 24 | name = "byteorder" 25 | version = "1.2.3" 26 | source = "registry+https://github.com/rust-lang/crates.io-index" 27 | 28 | [[package]] 29 | name = "cc" 30 | version = "1.0.15" 31 | source = "registry+https://github.com/rust-lang/crates.io-index" 32 | 33 | [[package]] 34 | name = "cfg-if" 35 | version = "0.1.3" 36 | source = "registry+https://github.com/rust-lang/crates.io-index" 37 | 38 | [[package]] 39 | name = "crossbeam-deque" 40 | version = "0.2.0" 41 | source = "registry+https://github.com/rust-lang/crates.io-index" 42 | dependencies = [ 43 | "crossbeam-epoch 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", 44 | "crossbeam-utils 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", 45 | ] 46 | 47 | [[package]] 48 | name = "crossbeam-epoch" 49 | version = "0.3.1" 50 | source = "registry+https://github.com/rust-lang/crates.io-index" 51 | dependencies = [ 52 | "arrayvec 0.4.7 (registry+https://github.com/rust-lang/crates.io-index)", 53 | "cfg-if 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", 54 | "crossbeam-utils 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", 55 | "lazy_static 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", 56 | "memoffset 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", 57 | "nodrop 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", 58 | "scopeguard 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", 59 | ] 60 | 61 | [[package]] 62 | name = "crossbeam-utils" 63 | version = "0.2.2" 64 | source = "registry+https://github.com/rust-lang/crates.io-index" 65 | dependencies = [ 66 | "cfg-if 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", 67 | ] 68 | 69 | [[package]] 70 | name = "dtoa" 71 | version = "0.4.2" 72 | source = "registry+https://github.com/rust-lang/crates.io-index" 73 | 74 | [[package]] 75 | name = "either" 76 | version = "1.5.0" 77 | source = "registry+https://github.com/rust-lang/crates.io-index" 78 | 79 | [[package]] 80 | name = "flate2" 81 | version = "1.0.1" 82 | source = "registry+https://github.com/rust-lang/crates.io-index" 83 | dependencies = [ 84 | "libc 0.2.41 (registry+https://github.com/rust-lang/crates.io-index)", 85 | "miniz-sys 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", 86 | ] 87 | 88 | [[package]] 89 | name = "fuchsia-zircon" 90 | version = "0.3.3" 91 | source = "registry+https://github.com/rust-lang/crates.io-index" 92 | dependencies = [ 93 | "bitflags 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", 94 | "fuchsia-zircon-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", 95 | ] 96 | 97 | [[package]] 98 | name = "fuchsia-zircon-sys" 99 | version = "0.3.3" 100 | source = "registry+https://github.com/rust-lang/crates.io-index" 101 | 102 | [[package]] 103 | name = "hostname" 104 | version = "0.1.4" 105 | source = "registry+https://github.com/rust-lang/crates.io-index" 106 | dependencies = [ 107 | "libc 0.2.41 (registry+https://github.com/rust-lang/crates.io-index)", 108 | "winutil 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", 109 | ] 110 | 111 | [[package]] 112 | name = "httparse" 113 | version = "1.2.4" 114 | source = "registry+https://github.com/rust-lang/crates.io-index" 115 | 116 | [[package]] 117 | name = "hyper" 118 | version = "0.10.13" 119 | source = "registry+https://github.com/rust-lang/crates.io-index" 120 | dependencies = [ 121 | "base64 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", 122 | "httparse 1.2.4 (registry+https://github.com/rust-lang/crates.io-index)", 123 | "language-tags 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", 124 | "log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", 125 | "mime 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", 126 | "num_cpus 1.8.0 (registry+https://github.com/rust-lang/crates.io-index)", 127 | "time 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)", 128 | "traitobject 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", 129 | "typeable 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", 130 | "unicase 1.4.2 (registry+https://github.com/rust-lang/crates.io-index)", 131 | "url 1.7.0 (registry+https://github.com/rust-lang/crates.io-index)", 132 | ] 133 | 134 | [[package]] 135 | name = "idna" 136 | version = "0.1.4" 137 | source = "registry+https://github.com/rust-lang/crates.io-index" 138 | dependencies = [ 139 | "matches 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", 140 | "unicode-bidi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", 141 | "unicode-normalization 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", 142 | ] 143 | 144 | [[package]] 145 | name = "iron" 146 | version = "0.6.0" 147 | source = "registry+https://github.com/rust-lang/crates.io-index" 148 | dependencies = [ 149 | "hyper 0.10.13 (registry+https://github.com/rust-lang/crates.io-index)", 150 | "log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", 151 | "mime_guess 1.8.4 (registry+https://github.com/rust-lang/crates.io-index)", 152 | "modifier 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", 153 | "num_cpus 1.8.0 (registry+https://github.com/rust-lang/crates.io-index)", 154 | "plugin 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", 155 | "typemap 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", 156 | "url 1.7.0 (registry+https://github.com/rust-lang/crates.io-index)", 157 | ] 158 | 159 | [[package]] 160 | name = "itoa" 161 | version = "0.4.1" 162 | source = "registry+https://github.com/rust-lang/crates.io-index" 163 | 164 | [[package]] 165 | name = "language-tags" 166 | version = "0.2.2" 167 | source = "registry+https://github.com/rust-lang/crates.io-index" 168 | 169 | [[package]] 170 | name = "lazy_static" 171 | version = "1.0.0" 172 | source = "registry+https://github.com/rust-lang/crates.io-index" 173 | 174 | [[package]] 175 | name = "libc" 176 | version = "0.2.41" 177 | source = "registry+https://github.com/rust-lang/crates.io-index" 178 | 179 | [[package]] 180 | name = "log" 181 | version = "0.3.9" 182 | source = "registry+https://github.com/rust-lang/crates.io-index" 183 | dependencies = [ 184 | "log 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", 185 | ] 186 | 187 | [[package]] 188 | name = "log" 189 | version = "0.4.1" 190 | source = "registry+https://github.com/rust-lang/crates.io-index" 191 | dependencies = [ 192 | "cfg-if 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", 193 | ] 194 | 195 | [[package]] 196 | name = "matches" 197 | version = "0.1.6" 198 | source = "registry+https://github.com/rust-lang/crates.io-index" 199 | 200 | [[package]] 201 | name = "memoffset" 202 | version = "0.2.1" 203 | source = "registry+https://github.com/rust-lang/crates.io-index" 204 | 205 | [[package]] 206 | name = "mime" 207 | version = "0.2.6" 208 | source = "registry+https://github.com/rust-lang/crates.io-index" 209 | dependencies = [ 210 | "log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", 211 | ] 212 | 213 | [[package]] 214 | name = "mime_guess" 215 | version = "1.8.4" 216 | source = "registry+https://github.com/rust-lang/crates.io-index" 217 | dependencies = [ 218 | "mime 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", 219 | "phf 0.7.22 (registry+https://github.com/rust-lang/crates.io-index)", 220 | "phf_codegen 0.7.22 (registry+https://github.com/rust-lang/crates.io-index)", 221 | "unicase 1.4.2 (registry+https://github.com/rust-lang/crates.io-index)", 222 | ] 223 | 224 | [[package]] 225 | name = "miniz-sys" 226 | version = "0.1.10" 227 | source = "registry+https://github.com/rust-lang/crates.io-index" 228 | dependencies = [ 229 | "cc 1.0.15 (registry+https://github.com/rust-lang/crates.io-index)", 230 | "libc 0.2.41 (registry+https://github.com/rust-lang/crates.io-index)", 231 | ] 232 | 233 | [[package]] 234 | name = "modifier" 235 | version = "0.1.0" 236 | source = "registry+https://github.com/rust-lang/crates.io-index" 237 | 238 | [[package]] 239 | name = "nodrop" 240 | version = "0.1.12" 241 | source = "registry+https://github.com/rust-lang/crates.io-index" 242 | 243 | [[package]] 244 | name = "num_cpus" 245 | version = "1.8.0" 246 | source = "registry+https://github.com/rust-lang/crates.io-index" 247 | dependencies = [ 248 | "libc 0.2.41 (registry+https://github.com/rust-lang/crates.io-index)", 249 | ] 250 | 251 | [[package]] 252 | name = "percent-encoding" 253 | version = "1.0.1" 254 | source = "registry+https://github.com/rust-lang/crates.io-index" 255 | 256 | [[package]] 257 | name = "phf" 258 | version = "0.7.22" 259 | source = "registry+https://github.com/rust-lang/crates.io-index" 260 | dependencies = [ 261 | "phf_shared 0.7.22 (registry+https://github.com/rust-lang/crates.io-index)", 262 | ] 263 | 264 | [[package]] 265 | name = "phf_codegen" 266 | version = "0.7.22" 267 | source = "registry+https://github.com/rust-lang/crates.io-index" 268 | dependencies = [ 269 | "phf_generator 0.7.22 (registry+https://github.com/rust-lang/crates.io-index)", 270 | "phf_shared 0.7.22 (registry+https://github.com/rust-lang/crates.io-index)", 271 | ] 272 | 273 | [[package]] 274 | name = "phf_generator" 275 | version = "0.7.22" 276 | source = "registry+https://github.com/rust-lang/crates.io-index" 277 | dependencies = [ 278 | "phf_shared 0.7.22 (registry+https://github.com/rust-lang/crates.io-index)", 279 | "rand 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", 280 | ] 281 | 282 | [[package]] 283 | name = "phf_shared" 284 | version = "0.7.22" 285 | source = "registry+https://github.com/rust-lang/crates.io-index" 286 | dependencies = [ 287 | "siphasher 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", 288 | "unicase 1.4.2 (registry+https://github.com/rust-lang/crates.io-index)", 289 | ] 290 | 291 | [[package]] 292 | name = "plugin" 293 | version = "0.2.6" 294 | source = "registry+https://github.com/rust-lang/crates.io-index" 295 | dependencies = [ 296 | "typemap 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", 297 | ] 298 | 299 | [[package]] 300 | name = "proc-macro2" 301 | version = "0.4.3" 302 | source = "registry+https://github.com/rust-lang/crates.io-index" 303 | dependencies = [ 304 | "unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", 305 | ] 306 | 307 | [[package]] 308 | name = "quote" 309 | version = "0.6.2" 310 | source = "registry+https://github.com/rust-lang/crates.io-index" 311 | dependencies = [ 312 | "proc-macro2 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", 313 | ] 314 | 315 | [[package]] 316 | name = "rand" 317 | version = "0.4.2" 318 | source = "registry+https://github.com/rust-lang/crates.io-index" 319 | dependencies = [ 320 | "fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", 321 | "libc 0.2.41 (registry+https://github.com/rust-lang/crates.io-index)", 322 | "winapi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", 323 | ] 324 | 325 | [[package]] 326 | name = "rayon" 327 | version = "1.0.1" 328 | source = "registry+https://github.com/rust-lang/crates.io-index" 329 | dependencies = [ 330 | "either 1.5.0 (registry+https://github.com/rust-lang/crates.io-index)", 331 | "rayon-core 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", 332 | ] 333 | 334 | [[package]] 335 | name = "rayon-core" 336 | version = "1.4.0" 337 | source = "registry+https://github.com/rust-lang/crates.io-index" 338 | dependencies = [ 339 | "crossbeam-deque 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", 340 | "lazy_static 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", 341 | "libc 0.2.41 (registry+https://github.com/rust-lang/crates.io-index)", 342 | "num_cpus 1.8.0 (registry+https://github.com/rust-lang/crates.io-index)", 343 | "rand 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", 344 | ] 345 | 346 | [[package]] 347 | name = "redox_syscall" 348 | version = "0.1.38" 349 | source = "registry+https://github.com/rust-lang/crates.io-index" 350 | 351 | [[package]] 352 | name = "safemem" 353 | version = "0.2.0" 354 | source = "registry+https://github.com/rust-lang/crates.io-index" 355 | 356 | [[package]] 357 | name = "scopeguard" 358 | version = "0.3.3" 359 | source = "registry+https://github.com/rust-lang/crates.io-index" 360 | 361 | [[package]] 362 | name = "serde" 363 | version = "1.0.59" 364 | source = "registry+https://github.com/rust-lang/crates.io-index" 365 | 366 | [[package]] 367 | name = "serde_derive" 368 | version = "1.0.59" 369 | source = "registry+https://github.com/rust-lang/crates.io-index" 370 | dependencies = [ 371 | "proc-macro2 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", 372 | "quote 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", 373 | "syn 0.14.0 (registry+https://github.com/rust-lang/crates.io-index)", 374 | ] 375 | 376 | [[package]] 377 | name = "serde_json" 378 | version = "1.0.17" 379 | source = "registry+https://github.com/rust-lang/crates.io-index" 380 | dependencies = [ 381 | "dtoa 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", 382 | "itoa 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", 383 | "serde 1.0.59 (registry+https://github.com/rust-lang/crates.io-index)", 384 | ] 385 | 386 | [[package]] 387 | name = "siphasher" 388 | version = "0.2.2" 389 | source = "registry+https://github.com/rust-lang/crates.io-index" 390 | 391 | [[package]] 392 | name = "syn" 393 | version = "0.14.0" 394 | source = "registry+https://github.com/rust-lang/crates.io-index" 395 | dependencies = [ 396 | "proc-macro2 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", 397 | "quote 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", 398 | "unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", 399 | ] 400 | 401 | [[package]] 402 | name = "sysinfo" 403 | version = "0.5.6" 404 | source = "registry+https://github.com/rust-lang/crates.io-index" 405 | dependencies = [ 406 | "cfg-if 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", 407 | "libc 0.2.41 (registry+https://github.com/rust-lang/crates.io-index)", 408 | "rayon 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", 409 | "winapi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", 410 | ] 411 | 412 | [[package]] 413 | name = "sysinfo-web" 414 | version = "0.1.2" 415 | dependencies = [ 416 | "flate2 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", 417 | "hostname 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", 418 | "iron 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", 419 | "serde 1.0.59 (registry+https://github.com/rust-lang/crates.io-index)", 420 | "serde_derive 1.0.59 (registry+https://github.com/rust-lang/crates.io-index)", 421 | "serde_json 1.0.17 (registry+https://github.com/rust-lang/crates.io-index)", 422 | "sysinfo 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)", 423 | ] 424 | 425 | [[package]] 426 | name = "time" 427 | version = "0.1.40" 428 | source = "registry+https://github.com/rust-lang/crates.io-index" 429 | dependencies = [ 430 | "libc 0.2.41 (registry+https://github.com/rust-lang/crates.io-index)", 431 | "redox_syscall 0.1.38 (registry+https://github.com/rust-lang/crates.io-index)", 432 | "winapi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", 433 | ] 434 | 435 | [[package]] 436 | name = "traitobject" 437 | version = "0.1.0" 438 | source = "registry+https://github.com/rust-lang/crates.io-index" 439 | 440 | [[package]] 441 | name = "typeable" 442 | version = "0.1.2" 443 | source = "registry+https://github.com/rust-lang/crates.io-index" 444 | 445 | [[package]] 446 | name = "typemap" 447 | version = "0.3.3" 448 | source = "registry+https://github.com/rust-lang/crates.io-index" 449 | dependencies = [ 450 | "unsafe-any 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", 451 | ] 452 | 453 | [[package]] 454 | name = "unicase" 455 | version = "1.4.2" 456 | source = "registry+https://github.com/rust-lang/crates.io-index" 457 | dependencies = [ 458 | "version_check 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", 459 | ] 460 | 461 | [[package]] 462 | name = "unicode-bidi" 463 | version = "0.3.4" 464 | source = "registry+https://github.com/rust-lang/crates.io-index" 465 | dependencies = [ 466 | "matches 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", 467 | ] 468 | 469 | [[package]] 470 | name = "unicode-normalization" 471 | version = "0.1.7" 472 | source = "registry+https://github.com/rust-lang/crates.io-index" 473 | 474 | [[package]] 475 | name = "unicode-xid" 476 | version = "0.1.0" 477 | source = "registry+https://github.com/rust-lang/crates.io-index" 478 | 479 | [[package]] 480 | name = "unsafe-any" 481 | version = "0.4.2" 482 | source = "registry+https://github.com/rust-lang/crates.io-index" 483 | dependencies = [ 484 | "traitobject 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", 485 | ] 486 | 487 | [[package]] 488 | name = "url" 489 | version = "1.7.0" 490 | source = "registry+https://github.com/rust-lang/crates.io-index" 491 | dependencies = [ 492 | "idna 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", 493 | "matches 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", 494 | "percent-encoding 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", 495 | ] 496 | 497 | [[package]] 498 | name = "version_check" 499 | version = "0.1.3" 500 | source = "registry+https://github.com/rust-lang/crates.io-index" 501 | 502 | [[package]] 503 | name = "winapi" 504 | version = "0.3.4" 505 | source = "registry+https://github.com/rust-lang/crates.io-index" 506 | dependencies = [ 507 | "winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", 508 | "winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", 509 | ] 510 | 511 | [[package]] 512 | name = "winapi-i686-pc-windows-gnu" 513 | version = "0.4.0" 514 | source = "registry+https://github.com/rust-lang/crates.io-index" 515 | 516 | [[package]] 517 | name = "winapi-x86_64-pc-windows-gnu" 518 | version = "0.4.0" 519 | source = "registry+https://github.com/rust-lang/crates.io-index" 520 | 521 | [[package]] 522 | name = "winutil" 523 | version = "0.1.1" 524 | source = "registry+https://github.com/rust-lang/crates.io-index" 525 | dependencies = [ 526 | "winapi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", 527 | ] 528 | 529 | [metadata] 530 | "checksum arrayvec 0.4.7 (registry+https://github.com/rust-lang/crates.io-index)" = "a1e964f9e24d588183fcb43503abda40d288c8657dfc27311516ce2f05675aef" 531 | "checksum base64 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "96434f987501f0ed4eb336a411e0631ecd1afa11574fe148587adc4ff96143c9" 532 | "checksum bitflags 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "d0c54bb8f454c567f21197eefcdbf5679d0bd99f2ddbe52e84c77061952e6789" 533 | "checksum byteorder 1.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "74c0b906e9446b0a2e4f760cdb3fa4b2c48cdc6db8766a845c54b6ff063fd2e9" 534 | "checksum cc 1.0.15 (registry+https://github.com/rust-lang/crates.io-index)" = "0ebb87d1116151416c0cf66a0e3fb6430cccd120fd6300794b4dfaa050ac40ba" 535 | "checksum cfg-if 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "405216fd8fe65f718daa7102ea808a946b6ce40c742998fbfd3463645552de18" 536 | "checksum crossbeam-deque 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f739f8c5363aca78cfb059edf753d8f0d36908c348f3d8d1503f03d8b75d9cf3" 537 | "checksum crossbeam-epoch 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "927121f5407de9956180ff5e936fe3cf4324279280001cd56b669d28ee7e9150" 538 | "checksum crossbeam-utils 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "2760899e32a1d58d5abb31129f8fae5de75220bc2176e77ff7c627ae45c918d9" 539 | "checksum dtoa 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "09c3753c3db574d215cba4ea76018483895d7bff25a31b49ba45db21c48e50ab" 540 | "checksum either 1.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3be565ca5c557d7f59e7cfcf1844f9e3033650c929c6566f511e8005f205c1d0" 541 | "checksum flate2 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "9fac2277e84e5e858483756647a9d0aa8d9a2b7cba517fd84325a0aaa69a0909" 542 | "checksum fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2e9763c69ebaae630ba35f74888db465e49e259ba1bc0eda7d06f4a067615d82" 543 | "checksum fuchsia-zircon-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7" 544 | "checksum hostname 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "58fab6e177434b0bb4cd344a4dabaa5bd6d7a8d792b1885aebcae7af1091d1cb" 545 | "checksum httparse 1.2.4 (registry+https://github.com/rust-lang/crates.io-index)" = "c2f407128745b78abc95c0ffbe4e5d37427fdc0d45470710cfef8c44522a2e37" 546 | "checksum hyper 0.10.13 (registry+https://github.com/rust-lang/crates.io-index)" = "368cb56b2740ebf4230520e2b90ebb0461e69034d85d1945febd9b3971426db2" 547 | "checksum idna 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "014b298351066f1512874135335d62a789ffe78a9974f94b43ed5621951eaf7d" 548 | "checksum iron 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1d8e17268922834707e1c29e8badbf9c712c9c43378e1b6a3388946baff10be2" 549 | "checksum itoa 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "c069bbec61e1ca5a596166e55dfe4773ff745c3d16b700013bcaff9a6df2c682" 550 | "checksum language-tags 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "a91d884b6667cd606bb5a69aa0c99ba811a115fc68915e7056ec08a46e93199a" 551 | "checksum lazy_static 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c8f31047daa365f19be14b47c29df4f7c3b581832407daabe6ae77397619237d" 552 | "checksum libc 0.2.41 (registry+https://github.com/rust-lang/crates.io-index)" = "ac8ebf8343a981e2fa97042b14768f02ed3e1d602eac06cae6166df3c8ced206" 553 | "checksum log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)" = "e19e8d5c34a3e0e2223db8e060f9e8264aeeb5c5fc64a4ee9965c062211c024b" 554 | "checksum log 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "89f010e843f2b1a31dbd316b3b8d443758bc634bed37aabade59c686d644e0a2" 555 | "checksum matches 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "100aabe6b8ff4e4a7e32c1c13523379802df0772b82466207ac25b013f193376" 556 | "checksum memoffset 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0f9dc261e2b62d7a622bf416ea3c5245cdd5d9a7fcc428c0d06804dfce1775b3" 557 | "checksum mime 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "ba626b8a6de5da682e1caa06bdb42a335aee5a84db8e5046a3e8ab17ba0a3ae0" 558 | "checksum mime_guess 1.8.4 (registry+https://github.com/rust-lang/crates.io-index)" = "b7e2b09d08313f84e0fb82d13a4d859109a17543fe9af3b6d941dc1431f7de79" 559 | "checksum miniz-sys 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)" = "609ce024854aeb19a0ef7567d348aaa5a746b32fb72e336df7fcc16869d7e2b4" 560 | "checksum modifier 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "41f5c9112cb662acd3b204077e0de5bc66305fa8df65c8019d5adb10e9ab6e58" 561 | "checksum nodrop 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)" = "9a2228dca57108069a5262f2ed8bd2e82496d2e074a06d1ccc7ce1687b6ae0a2" 562 | "checksum num_cpus 1.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c51a3322e4bca9d212ad9a158a02abc6934d005490c054a2778df73a70aa0a30" 563 | "checksum percent-encoding 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "31010dd2e1ac33d5b46a5b413495239882813e0369f8ed8a5e266f173602f831" 564 | "checksum phf 0.7.22 (registry+https://github.com/rust-lang/crates.io-index)" = "7d37a244c75a9748e049225155f56dbcb98fe71b192fd25fd23cb914b5ad62f2" 565 | "checksum phf_codegen 0.7.22 (registry+https://github.com/rust-lang/crates.io-index)" = "4e4048fe7dd7a06b8127ecd6d3803149126e9b33c7558879846da3a63f734f2b" 566 | "checksum phf_generator 0.7.22 (registry+https://github.com/rust-lang/crates.io-index)" = "05a079dd052e7b674d21cb31cbb6c05efd56a2cd2827db7692e2f1a507ebd998" 567 | "checksum phf_shared 0.7.22 (registry+https://github.com/rust-lang/crates.io-index)" = "c2261d544c2bb6aa3b10022b0be371b9c7c64f762ef28c6f5d4f1ef6d97b5930" 568 | "checksum plugin 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "1a6a0dc3910bc8db877ffed8e457763b317cf880df4ae19109b9f77d277cf6e0" 569 | "checksum proc-macro2 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "a45f2f0ae0b5757f6fe9e68745ba25f5246aea3598984ed81d013865873c1f84" 570 | "checksum quote 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "9e53eeda07ddbd8b057dde66d9beded11d0dfda13f0db0769e6b71d6bcf2074e" 571 | "checksum rand 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "eba5f8cb59cc50ed56be8880a5c7b496bfd9bd26394e176bc67884094145c2c5" 572 | "checksum rayon 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "80e811e76f1dbf68abf87a759083d34600017fc4e10b6bd5ad84a700f9dba4b1" 573 | "checksum rayon-core 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "9d24ad214285a7729b174ed6d3bcfcb80177807f959d95fafd5bfc5c4f201ac8" 574 | "checksum redox_syscall 0.1.38 (registry+https://github.com/rust-lang/crates.io-index)" = "0a12d51a5b5fd700e6c757f15877685bfa04fd7eb60c108f01d045cafa0073c2" 575 | "checksum safemem 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e27a8b19b835f7aea908818e871f5cc3a5a186550c30773be987e155e8163d8f" 576 | "checksum scopeguard 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "94258f53601af11e6a49f722422f6e3425c52b06245a5cf9bc09908b174f5e27" 577 | "checksum serde 1.0.59 (registry+https://github.com/rust-lang/crates.io-index)" = "2a4d976362a13caad61c38cf841401d2d4d480496a9391c3842c288b01f9de95" 578 | "checksum serde_derive 1.0.59 (registry+https://github.com/rust-lang/crates.io-index)" = "94bb618afe46430c6b089e9b111dc5b2fcd3e26a268da0993f6d16bea51c6021" 579 | "checksum serde_json 1.0.17 (registry+https://github.com/rust-lang/crates.io-index)" = "f3ad6d546e765177cf3dded3c2e424a8040f870083a0e64064746b958ece9cb1" 580 | "checksum siphasher 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "0df90a788073e8d0235a67e50441d47db7c8ad9debd91cbf43736a2a92d36537" 581 | "checksum syn 0.14.0 (registry+https://github.com/rust-lang/crates.io-index)" = "99d991a9e7c33123925e511baab68f7ec25c3795962fe326a2395e5a42a614f0" 582 | "checksum sysinfo 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)" = "c65f4e5794c2dacca1b1f6462c7774017e1ba8564ee268df2c89e2f23a70c5ea" 583 | "checksum time 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)" = "d825be0eb33fda1a7e68012d51e9c7f451dc1a69391e7fdc197060bb8c56667b" 584 | "checksum traitobject 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "efd1f82c56340fdf16f2a953d7bda4f8fdffba13d93b00844c25572110b26079" 585 | "checksum typeable 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "1410f6f91f21d1612654e7cc69193b0334f909dcf2c790c4826254fbb86f8887" 586 | "checksum typemap 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "653be63c80a3296da5551e1bfd2cca35227e13cdd08c6668903ae2f4f77aa1f6" 587 | "checksum unicase 1.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7f4765f83163b74f957c797ad9253caf97f103fb064d3999aea9568d09fc8a33" 588 | "checksum unicode-bidi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "49f2bd0c6468a8230e1db229cff8029217cf623c767ea5d60bfbd42729ea54d5" 589 | "checksum unicode-normalization 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "6a0180bc61fc5a987082bfa111f4cc95c4caff7f9799f3e46df09163a937aa25" 590 | "checksum unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc" 591 | "checksum unsafe-any 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f30360d7979f5e9c6e6cea48af192ea8fab4afb3cf72597154b8f08935bc9c7f" 592 | "checksum url 1.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f808aadd8cfec6ef90e4a14eb46f24511824d1ac596b9682703c87056c8678b7" 593 | "checksum version_check 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "6b772017e347561807c1aa192438c5fd74242a670a6cffacc40f2defd1dc069d" 594 | "checksum winapi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "04e3bd221fcbe8a271359c04f21a76db7d0c6028862d1bb5512d85e1e2eb5bb3" 595 | "checksum winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" 596 | "checksum winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" 597 | "checksum winutil 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7daf138b6b14196e3830a588acf1e86966c694d3e8fb026fb105b8b5dca07e6e" 598 | -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "sysinfo-web" 3 | description = "Lightweight web based process viewer built on top of sysinfo" 4 | version = "0.1.2" 5 | authors = ["Onur Aslan ", "Guillaume Gomez "] 6 | license = "MIT" 7 | readme = "README.md" 8 | repository = "https://github.com/onur/sysinfo-web" 9 | documentation = "https://docs.rs/sysinfo-web" 10 | 11 | [dependencies] 12 | serde = "1" 13 | serde_json = "1" 14 | iron = "0.6" 15 | hostname = "0.1" 16 | sysinfo = "0.5.6" 17 | flate2 = { version = "1.0.1", optional = true } 18 | 19 | [dev-dependencies] 20 | serde_derive = "1" 21 | 22 | [features] 23 | gzip = ["flate2"] 24 | default = ["gzip"] 25 | 26 | [[bin]] 27 | name = "sysinfo-web" 28 | test = false 29 | doc = false 30 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM rust:1.35.0-stretch 2 | 3 | WORKDIR /etc/sysinfo-web 4 | 5 | ADD . . 6 | 7 | RUN cargo build --release 8 | 9 | EXPOSE 3000 10 | 11 | CMD ./target/release/sysinfo-web 12 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2017 Onur Aslan 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 all 13 | 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 THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # sysinfo-web 2 | 3 | [![Build Status](https://secure.travis-ci.org/onur/sysinfo-web.svg?branch=master)](https://travis-ci.org/onur/sysinfo-web) 4 | [![License](https://img.shields.io/badge/license-MIT-blue.svg)](https://raw.githubusercontent.com/onur/sysinfo-web/master/LICENSE) 5 | [![Crates.io](https://img.shields.io/crates/v/sysinfo-web.svg)](https://crates.io/crates/sysinfo-web) 6 | 7 | Lightweight web based process viewer built on top of 8 | [sysinfo](https://github.com/GuillaumeGomez/sysinfo). 9 | 10 | [See a demo of sysinfo-web](https://docs.rs/@sysinfo/). 11 | 12 | ## Installation and usage 13 | 14 | You can grab a precompiled binary from 15 | [releases](https://github.com/onur/sysinfo-web/releases) page or you can install 16 | sysinfo-web with cargo: 17 | 18 | ```sh 19 | cargo install --git https://github.com/onur/sysinfo-web 20 | ``` 21 | 22 | Make sure `sysinfo-web` is in your `PATH` and you can run it with: 23 | 24 | ``` 25 | sysinfo-web 26 | ``` 27 | 28 | Socket address is optional, by default it will listen: . 29 | 30 | 31 | ## Screenshot 32 | 33 | [![sysinfo-web](https://i.imgur.com/qQPe9yN.png)](https://i.imgur.com/RH8l8Sz.png) 34 | -------------------------------------------------------------------------------- /resources/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onur/sysinfo-web/526e14737d20e44fc0d53b96a4538f1e18430638/resources/favicon.ico -------------------------------------------------------------------------------- /src/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | sysinfo-web 8 | 9 | 10 | 11 | 12 | 13 | 14 | 54 | 55 | 56 |
57 |

{{ sysinfo.hostname }} — {{ sysinfo.uptime }}

58 |
59 |
60 |
61 | 65 |
66 |
67 |
68 |
69 |
70 |
Global
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
{{ processor.name }}
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 | 89 |
90 |
91 |
92 |
93 | 97 |
98 |
99 |
100 |
101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 |
LabelTemperatureMaxCritical
{{ component.label }}{{ component.temperature }} °C{{ component.max }} °C{{ component.critical }} °C
120 |
121 |
122 | 123 |
124 |
125 |
126 |
127 |
128 |
129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 |
NameMPFSSizeUsedAvail
{{ disk.name }}{{ disk.mount_point }}{{ disk.file_system }}{{ disk.total_space | readableBytes }}{{ disk.total_space - disk.available_space | readableBytes }}{{ disk.available_space | readableBytes }}
151 |
152 |
153 |
154 |
155 | 159 |
160 |
161 |
162 |
163 |
164 |
165 | 166 |
167 |
168 | 169 |
170 |
171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 |
TotalUsedFree
Memory{{ sysinfo.memory[0] | readableKbytes }}{{ sysinfo.memory[1] | readableKbytes }}{{ sysinfo.memory[2] | readableKbytes }}
Swap{{ sysinfo.memory[3] | readableKbytes }}{{ sysinfo.memory[4] | readableKbytes }}{{ sysinfo.memory[5] | readableKbytes }}
195 |
196 |
197 | 198 |
199 |
200 |
201 |
202 |
203 |
204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 |
Incoming{{ sysinfo.bandwith[0] | readableBits }}/sec
Outgoing{{ sysinfo.bandwith[1] | readableBits }}/sec
217 |
218 |
219 |
220 |
221 |
222 |
223 |
224 |
225 | 226 | 227 | 228 | 229 | 235 | 236 | 237 | 238 | 239 | 240 | 241 | 242 | 243 | 244 | 245 | 246 | 247 |
230 |
{{ column }}
234 |
{{ process.pid }}{{ process.name | truncate }}{{ process.uid }}{{ process.gid }}{{ process.cpu_usage | round }}%{{ process.memory | readableKbytes }}
248 |
249 |
250 |
251 |
252 |
253 | 590 | 591 | 592 | -------------------------------------------------------------------------------- /src/lib.rs: -------------------------------------------------------------------------------- 1 | //! Lightweight web based process viewer built on top of 2 | //! [sysinfo](https://github.com/GuillaumeGomez/sysinfo). 3 | //! [See more info in GitHub repository](https://github.com/onur/sysinfo-web). 4 | 5 | pub extern crate sysinfo; 6 | extern crate serde_json; 7 | extern crate serde; 8 | extern crate iron; 9 | extern crate hostname; 10 | #[cfg(feature = "gzip")] 11 | extern crate flate2; 12 | 13 | pub mod sysinfo_serde; 14 | mod sysinfo_ext; 15 | mod web; 16 | 17 | pub use sysinfo_ext::SysinfoExt; 18 | pub use web::start_web_server; 19 | -------------------------------------------------------------------------------- /src/main.rs: -------------------------------------------------------------------------------- 1 | extern crate sysinfo_web; 2 | 3 | fn main() { 4 | sysinfo_web::start_web_server(::std::env::args().nth(1)).unwrap(); 5 | } 6 | -------------------------------------------------------------------------------- /src/sysinfo_ext.rs: -------------------------------------------------------------------------------- 1 | 2 | use std::collections::HashMap; 3 | use std::io::Error; 4 | use serde::{Serialize, Serializer}; 5 | use sysinfo::{NetworkExt, System, SystemExt, Disk, Process, ProcessExt, Component, Processor}; 6 | use hostname::get_hostname; 7 | 8 | 9 | /// `sysinfo` with extended features 10 | pub struct SysinfoExt<'a> { 11 | process_list: HashMap, 12 | processor_list: &'a [Processor], 13 | components_list: &'a [Component], 14 | disks: &'a [Disk], 15 | memory: [u64; 6], 16 | hostname: String, 17 | uptime: String, 18 | pub bandwith: (u64, u64), 19 | } 20 | 21 | 22 | impl<'a> SysinfoExt<'a> { 23 | pub fn new(system: &'a System) -> Self { 24 | let network = system.get_network(); 25 | SysinfoExt { 26 | process_list: system.get_process_list() 27 | // filter unnamed kernel threads 28 | .iter().filter(|p| !p.1.name().is_empty()) 29 | .map(|p| (*p.0, p.1.clone())) 30 | .collect(), 31 | processor_list: system.get_processor_list(), 32 | components_list: system.get_components_list(), 33 | disks: system.get_disks(), 34 | memory: [system.get_total_memory(), 35 | system.get_used_memory(), 36 | system.get_free_memory(), 37 | system.get_total_swap(), 38 | system.get_used_swap(), 39 | system.get_free_swap()], 40 | hostname: get_hostname().unwrap_or("Unknown".to_owned()), 41 | uptime: get_uptime().unwrap_or("Unknown".to_owned()), 42 | bandwith: (network.get_income(), network.get_outcome()), 43 | } 44 | } 45 | } 46 | 47 | 48 | 49 | impl<'a> Serialize for SysinfoExt<'a> { 50 | fn serialize(&self, serializer: S) -> Result 51 | where S: Serializer 52 | { 53 | use serde::ser::SerializeMap; 54 | use sysinfo_serde::Ser; 55 | let mut map = serializer.serialize_map(None)?; 56 | map.serialize_entry("processor_list", 57 | &self.processor_list 58 | .iter() 59 | .map(|p| Ser::new(p)) 60 | .collect::>>())?; 61 | map.serialize_entry("process_list", &Ser::new(&self.process_list))?; 62 | map.serialize_entry("components_list", 63 | &self.components_list 64 | .iter() 65 | .map(|c| Ser::new(c)) 66 | .collect::>>())?; 67 | map.serialize_entry("disks", 68 | &self.disks 69 | .iter() 70 | .map(|d| Ser::new(d)) 71 | .collect::>>())?; 72 | map.serialize_entry("memory", &self.memory)?; 73 | map.serialize_entry("hostname", &self.hostname)?; 74 | map.serialize_entry("uptime", &self.uptime)?; 75 | map.serialize_entry("bandwith", &self.bandwith)?; 76 | map.end() 77 | } 78 | } 79 | 80 | 81 | /// Gets uptime from /proc/uptime and converts it to human readable String 82 | fn get_uptime() -> Result { 83 | use std::process::Command; 84 | let output = Command::new("uptime").output()?; 85 | Ok(String::from_utf8(output.stdout).unwrap_or("Unknown".to_owned())) 86 | } 87 | -------------------------------------------------------------------------------- /src/sysinfo_serde.rs: -------------------------------------------------------------------------------- 1 | //! Serde serialization support for sysinfo 2 | //! 3 | //! Usage example with `serde_derive`: 4 | //! 5 | //! ```rust 6 | //! # #[macro_use] 7 | //! # extern crate serde_derive; 8 | //! # extern crate serde_json; 9 | //! # extern crate sysinfo; 10 | //! # extern crate sysinfo_web; 11 | //! # use sysinfo_web::sysinfo_serde; 12 | //! # use sysinfo::SystemExt; 13 | //! # fn main() { 14 | //! #[derive(Serialize)] 15 | //! struct Info ( 16 | //! #[serde(serialize_with = "sysinfo_serde::serialize")] 17 | //! sysinfo::System 18 | //! ); 19 | //! 20 | //! let mut system = sysinfo::System::new(); 21 | //! system.refresh_all(); 22 | //! 23 | //! let info = Info(system); 24 | //! let serialized = serde_json::to_string(&info).unwrap(); 25 | //! # } 26 | //! 27 | //! ``` 28 | 29 | 30 | use std::collections::HashMap; 31 | use serde::{Serialize, Serializer}; 32 | use serde::ser::SerializeMap; 33 | use sysinfo::{System, SystemExt, Processor, ProcessorExt, Process, ProcessExt, 34 | Component, ComponentExt, Disk, DiskExt, DiskType}; 35 | 36 | 37 | pub fn serialize(value: &T, serializer: S) -> Result 38 | where S: Serializer, 39 | for<'a> Ser<'a, T>: Serialize 40 | { 41 | Ser::new(value).serialize(serializer) 42 | } 43 | 44 | 45 | /// A wrapper to serialize `sysinfo` types. 46 | pub struct Ser<'a, T: 'a>(&'a T); 47 | 48 | 49 | impl<'a, T> Ser<'a, T> 50 | where Ser<'a, T>: Serialize 51 | { 52 | #[inline(always)] 53 | pub fn new(value: &'a T) -> Self { 54 | Ser(value) 55 | } 56 | } 57 | 58 | 59 | impl<'a> Serialize for Ser<'a, Processor> { 60 | fn serialize(&self, serializer: S) -> Result 61 | where S: Serializer 62 | { 63 | let mut map = serializer.serialize_map(None)?; 64 | map.serialize_entry("name", self.0.get_name())?; 65 | map.serialize_entry("cpu_usage", &self.0.get_cpu_usage())?; 66 | map.end() 67 | } 68 | } 69 | 70 | 71 | impl<'a> Serialize for Ser<'a, Process> { 72 | fn serialize(&self, serializer: S) -> Result 73 | where S: Serializer 74 | { 75 | // Do not serialize command line arguments and environment variables 76 | // for extra security and save up some bandwith on each request. 77 | // 78 | // This is actually breaking whole idea behind this serde serializer, 79 | // but since only sysinfo-web is using this serializer it should be fine. 80 | let mut map = serializer.serialize_map(None)?; 81 | map.serialize_entry("name", &self.0.name())?; 82 | //map.serialize_entry("cmd", &self.0.cmd())?; 83 | map.serialize_entry("exe", &self.0.exe())?; 84 | map.serialize_entry("pid", &self.0.pid())?; 85 | map.serialize_entry("parent", &self.0.parent())?; 86 | //map.serialize_entry("environ", &self.0.environ())?; 87 | map.serialize_entry("cwd", &self.0.cwd())?; 88 | map.serialize_entry("root", &self.0.root())?; 89 | map.serialize_entry("memory", &self.0.memory())?; 90 | map.serialize_entry("start_time", &self.0.start_time())?; 91 | map.serialize_entry("cpu_usage", &self.0.cpu_usage())?; 92 | map.serialize_entry("uid", &self.0.uid)?; 93 | map.serialize_entry("gid", &self.0.gid)?; 94 | #[cfg(target_os = "linux")] 95 | map.serialize_entry("tasks", &Ser::new(&self.0.tasks))?; 96 | map.end() 97 | } 98 | } 99 | 100 | 101 | impl<'a> Serialize for Ser<'a, HashMap> { 102 | fn serialize(&self, serializer: S) -> Result 103 | where S: Serializer 104 | { 105 | let mut map = serializer.serialize_map(None)?; 106 | for (pid, process) in self.0.iter() { 107 | map.serialize_key(pid)?; 108 | map.serialize_value(&Ser::new(process))?; 109 | } 110 | map.end() 111 | } 112 | } 113 | 114 | 115 | impl<'a> Serialize for Ser<'a, Component> { 116 | fn serialize(&self, serializer: S) -> Result 117 | where S: Serializer 118 | { 119 | let mut map = serializer.serialize_map(None)?; 120 | map.serialize_entry("temperature", &self.0.get_temperature())?; 121 | map.serialize_entry("max", &self.0.get_max())?; 122 | map.serialize_entry("critical", &self.0.get_critical())?; 123 | map.serialize_entry("label", &self.0.get_label())?; 124 | map.end() 125 | } 126 | } 127 | 128 | 129 | impl<'a> Serialize for Ser<'a, Disk> { 130 | fn serialize(&self, serializer: S) -> Result 131 | where S: Serializer 132 | { 133 | let mut map = serializer.serialize_map(None)?; 134 | map.serialize_entry("type", 135 | &match self.0.get_type() { 136 | DiskType::HDD => "HDD".to_owned(), 137 | DiskType::SSD => "SSD".to_owned(), 138 | DiskType::Unknown(size) => format!("Unknown({})", size), 139 | })?; 140 | map.serialize_entry("name", self.0.get_name().to_str().unwrap())?; 141 | map.serialize_entry("file_system", ::std::str::from_utf8(self.0.get_file_system()).unwrap())?; 142 | map.serialize_entry("mount_point", self.0.get_mount_point())?; 143 | map.serialize_entry("total_space", &self.0.get_total_space())?; 144 | map.serialize_entry("available_space", &self.0.get_available_space())?; 145 | map.end() 146 | } 147 | } 148 | 149 | 150 | impl<'a> Serialize for Ser<'a, System> { 151 | fn serialize(&self, serializer: S) -> Result 152 | where S: Serializer 153 | { 154 | let mut map = serializer.serialize_map(None)?; 155 | map.serialize_entry("process_list", &Ser::new(self.0.get_process_list()))?; 156 | map.serialize_entry("processor_list", 157 | &self.0 158 | .get_processor_list() 159 | .iter() 160 | .map(|p| Ser::new(p)) 161 | .collect::>>())?; 162 | map.serialize_entry("total_memory", &self.0.get_total_memory())?; 163 | map.serialize_entry("free_memory", &self.0.get_free_memory())?; 164 | map.serialize_entry("used_memory", &self.0.get_used_memory())?; 165 | map.serialize_entry("total_swap", &self.0.get_total_swap())?; 166 | map.serialize_entry("free_swap", &self.0.get_free_swap())?; 167 | map.serialize_entry("used_swap", &self.0.get_used_swap())?; 168 | map.serialize_entry("components_list", 169 | &self.0 170 | .get_components_list() 171 | .iter() 172 | .map(|c| Ser::new(c)) 173 | .collect::>>())?; 174 | map.serialize_entry("disks", 175 | &self.0 176 | .get_disks() 177 | .iter() 178 | .map(|c| Ser::new(c)) 179 | .collect::>>())?; 180 | 181 | map.end() 182 | } 183 | } 184 | -------------------------------------------------------------------------------- /src/web.rs: -------------------------------------------------------------------------------- 1 | 2 | use iron::{Iron, IronResult, Listening, status}; 3 | use iron::error::HttpResult; 4 | use iron::response::Response; 5 | #[cfg(feature = "gzip")] 6 | use iron::response::WriteBody; 7 | use iron::request::Request; 8 | use iron::middleware::Handler; 9 | use iron::mime::Mime; 10 | 11 | use sysinfo::{System, SystemExt}; 12 | 13 | #[cfg(feature = "gzip")] 14 | use flate2::Compression; 15 | #[cfg(feature = "gzip")] 16 | use flate2::write::GzEncoder; 17 | 18 | use std::sync::{Arc, Mutex, RwLock}; 19 | use std::thread; 20 | use std::time::{Duration, SystemTime}; 21 | #[cfg(feature = "gzip")] 22 | use std::io::{self, Write}; 23 | 24 | use SysinfoExt; 25 | use serde_json; 26 | 27 | 28 | const INDEX_HTML: &'static [u8] = include_bytes!("index.html"); 29 | const FAVICON: &'static [u8] = include_bytes!("../resources/favicon.ico"); 30 | const REFRESH_DELAY: u64 = 60 * 10; // 10 minutes 31 | 32 | /// Simple wrapper to get gzip compressed output on string types. 33 | #[cfg(feature = "gzip")] 34 | struct GzipContent(Box); 35 | 36 | #[cfg(feature = "gzip")] 37 | impl WriteBody for GzipContent { 38 | fn write_body(&mut self, w: &mut Write) -> io::Result<()> { 39 | let mut w = GzEncoder::new(w, Compression::default()); 40 | self.0.write_body(&mut w)?; 41 | w.finish().map(|_| ()) 42 | } 43 | } 44 | 45 | struct SysinfoIronHandler(Arc); 46 | 47 | struct DataHandler { 48 | system: RwLock, 49 | last_connection: Mutex, 50 | json_output: RwLock, 51 | } 52 | 53 | impl DataHandler { 54 | fn can_update_system_info(&self) -> bool { 55 | SystemTime::now().duration_since(*self.last_connection.lock().unwrap()) 56 | .unwrap() 57 | .as_secs() < REFRESH_DELAY 58 | } 59 | 60 | fn update_last_connection(&self) { 61 | *self.last_connection.lock().unwrap() = SystemTime::now(); 62 | } 63 | } 64 | 65 | #[cfg(feature = "gzip")] 66 | macro_rules! return_gzip_or_not { 67 | ($req:expr, $content:expr, $typ:expr) => {{ 68 | let mut use_gzip = false; 69 | 70 | if let Some(raw_accept_encoding) = $req.headers.get_raw("accept-encoding") { 71 | for accept_encoding in raw_accept_encoding { 72 | match ::std::str::from_utf8(accept_encoding).map(|s| s.to_lowercase()) { 73 | Ok(ref s) if s.contains("gzip") => { 74 | use_gzip = true; 75 | break; 76 | } 77 | _ => continue, 78 | } 79 | } 80 | } 81 | if !use_gzip { 82 | Ok(Response::with((status::Ok, $typ.parse::().unwrap(), $content))) 83 | } else { 84 | use iron::headers::{ContentType, ContentEncoding, Encoding}; 85 | let mut res = Response::new(); 86 | res.status = Some(status::Ok); 87 | res.body = Some(Box::new(GzipContent(Box::new($content)))); 88 | res.headers.set(ContentType($typ.parse::().unwrap())); 89 | res.headers.set(ContentEncoding(vec![Encoding::Gzip])); 90 | Ok(res) 91 | } 92 | }} 93 | } 94 | 95 | #[cfg(not(feature = "gzip"))] 96 | macro_rules! return_gzip_or_not { 97 | ($req:expr, $content:expr, $typ:expr) => {{ 98 | Ok(Response::with((status::Ok, $typ.parse::().unwrap(), $content))) 99 | }} 100 | } 101 | 102 | impl Handler for SysinfoIronHandler { 103 | fn handle(&self, req: &mut Request) -> IronResult { 104 | match match req.url.path().last() { 105 | Some(path) => { 106 | if *path == "" { 107 | 1 108 | } else if *path == "favicon.ico" { 109 | 2 110 | } else { 111 | 3 112 | } 113 | } 114 | None => 0, 115 | } { 116 | 1 => return_gzip_or_not!(req, INDEX_HTML, "text/html"), 117 | 2 => return_gzip_or_not!(req, FAVICON, "image/x-icon"), 118 | 3 => { 119 | self.0.update_last_connection(); 120 | return_gzip_or_not!(req, 121 | self.0.json_output.read().unwrap().clone(), 122 | "application/json") 123 | } 124 | _ => Ok(Response::with((status::NotFound, "Not found"))), 125 | } 126 | } 127 | } 128 | 129 | pub fn start_web_server(sock_addr: Option) -> HttpResult { 130 | let data_handler = Arc::new(DataHandler { 131 | system: RwLock::new(System::new()), 132 | last_connection: Mutex::new(SystemTime::now()), 133 | json_output: RwLock::new(String::from("[]")), 134 | }); 135 | let data_handler_clone = data_handler.clone(); 136 | thread::spawn(move || { 137 | let mut sleeping = false; 138 | loop { 139 | if data_handler_clone.can_update_system_info() { 140 | { 141 | let mut system = data_handler_clone.system.write().unwrap(); 142 | system.refresh_all(); 143 | // refresh it twice to provide accurate information after wake up 144 | if sleeping { 145 | system.refresh_all(); 146 | sleeping = false; 147 | } 148 | let sysinfo = SysinfoExt::new(&system); 149 | let mut json_output = data_handler_clone.json_output.write().unwrap(); 150 | json_output.clear(); 151 | use std::fmt::Write; 152 | json_output.write_str(&serde_json::to_string(&sysinfo) 153 | .unwrap_or(String::from("[]"))).unwrap(); 154 | } 155 | thread::sleep(Duration::new(5, 0)); 156 | } else { 157 | // If we don't need to refresh the system information, we can sleep a lot less. 158 | thread::sleep(Duration::from_millis(500)); 159 | sleeping = true; 160 | } 161 | } 162 | }); 163 | let mut iron = Iron::new(SysinfoIronHandler(data_handler)); 164 | iron.threads = 4; 165 | let ret = iron.http(sock_addr.unwrap_or("localhost:3000".to_owned())); 166 | if ret.is_ok() { 167 | println!("Started server on port 3000"); 168 | } 169 | ret 170 | } 171 | --------------------------------------------------------------------------------