1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 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 151 152 153 154 155 156 157 158 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 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717
// Take a look at the license at the top of the repository in the LICENSE file.
use crate::{
common::{Gid, MacAddr, Uid},
sys::{Component, Cpu, Disk, Networks, Process},
};
use crate::{
CpuRefreshKind, DiskType, DiskUsage, LoadAvg, NetworksIter, Pid, ProcessRefreshKind,
ProcessStatus, RefreshKind, Signal, User,
};
use std::collections::HashMap;
use std::ffi::OsStr;
use std::fmt::Debug;
use std::path::Path;
/// Contains all the methods of the [`Disk`][crate::Disk] struct.
///
/// ```no_run
/// use sysinfo::{DiskExt, System, SystemExt};
///
/// let s = System::new();
/// for disk in s.disks() {
/// println!("{:?}: {:?}", disk.name(), disk.type_());
/// }
/// ```
pub trait DiskExt: Debug {
/// Returns the disk type.
///
/// ```no_run
/// use sysinfo::{DiskExt, System, SystemExt};
///
/// let s = System::new();
/// for disk in s.disks() {
/// println!("{:?}", disk.type_());
/// }
/// ```
fn type_(&self) -> DiskType;
/// Returns the disk name.
///
/// ```no_run
/// use sysinfo::{DiskExt, System, SystemExt};
///
/// let s = System::new();
/// for disk in s.disks() {
/// println!("{:?}", disk.name());
/// }
/// ```
fn name(&self) -> &OsStr;
/// Returns the file system used on this disk (so for example: `EXT4`, `NTFS`, etc...).
///
/// ```no_run
/// use sysinfo::{DiskExt, System, SystemExt};
///
/// let s = System::new();
/// for disk in s.disks() {
/// println!("{:?}", disk.file_system());
/// }
/// ```
fn file_system(&self) -> &[u8];
/// Returns the mount point of the disk (`/` for example).
///
/// ```no_run
/// use sysinfo::{DiskExt, System, SystemExt};
///
/// let s = System::new();
/// for disk in s.disks() {
/// println!("{:?}", disk.mount_point());
/// }
/// ```
fn mount_point(&self) -> &Path;
/// Returns the total disk size, in bytes.
///
/// ```no_run
/// use sysinfo::{DiskExt, System, SystemExt};
///
/// let s = System::new();
/// for disk in s.disks() {
/// println!("{}", disk.total_space());
/// }
/// ```
fn total_space(&self) -> u64;
/// Returns the available disk size, in bytes.
///
/// ```no_run
/// use sysinfo::{DiskExt, System, SystemExt};
///
/// let s = System::new();
/// for disk in s.disks() {
/// println!("{}", disk.available_space());
/// }
/// ```
fn available_space(&self) -> u64;
/// Returns `true` if the disk is removable.
///
/// ```no_run
/// use sysinfo::{DiskExt, System, SystemExt};
///
/// let s = System::new();
/// for disk in s.disks() {
/// println!("{}", disk.is_removable());
/// }
/// ```
fn is_removable(&self) -> bool;
/// Updates the disk' information.
///
/// ```no_run
/// use sysinfo::{DiskExt, System, SystemExt};
///
/// let mut s = System::new_all();
/// for disk in s.disks_mut() {
/// disk.refresh();
/// }
/// ```
fn refresh(&mut self) -> bool;
}
/// Contains all the methods of the [`Process`][crate::Process] struct.
pub trait ProcessExt: Debug {
/// Sends [`Signal::Kill`] to the process (which is the only signal supported on all supported
/// platforms by this crate).
///
/// If you want to send another signal, take a look at [`ProcessExt::kill_with`].
///
/// To get the list of the supported signals on this system, use
/// [`SystemExt::SUPPORTED_SIGNALS`].
///
/// ```no_run
/// use sysinfo::{Pid, ProcessExt, System, SystemExt};
///
/// let s = System::new();
/// if let Some(process) = s.process(Pid::from(1337)) {
/// process.kill();
/// }
/// ```
fn kill(&self) -> bool {
self.kill_with(Signal::Kill).unwrap_or(false)
}
/// Sends the given `signal` to the process. If the signal doesn't exist on this platform,
/// it'll do nothing and will return `None`. Otherwise it'll return if the signal was sent
/// successfully.
///
/// If you just want to kill the process, use [`ProcessExt::kill`] directly.
///
/// To get the list of the supported signals on this system, use
/// [`SystemExt::SUPPORTED_SIGNALS`].
///
/// ```no_run
/// use sysinfo::{Pid, ProcessExt, Signal, System, SystemExt};
///
/// let s = System::new();
/// if let Some(process) = s.process(Pid::from(1337)) {
/// if process.kill_with(Signal::Kill).is_none() {
/// eprintln!("This signal isn't supported on this platform");
/// }
/// }
/// ```
fn kill_with(&self, signal: Signal) -> Option<bool>;
/// Returns the name of the process.
///
/// **⚠️ Important ⚠️**
///
/// On **linux**, there are two things to know about processes' name:
/// 1. It is limited to 15 characters.
/// 2. It is not always the exe name.
///
/// If you are looking for a specific process, unless you know what you are doing, in most
/// cases it's better to use [`ProcessExt::exe`] instead (which can be empty sometimes!).
///
/// ```no_run
/// use sysinfo::{Pid, ProcessExt, System, SystemExt};
///
/// let s = System::new();
/// if let Some(process) = s.process(Pid::from(1337)) {
/// println!("{}", process.name());
/// }
/// ```
fn name(&self) -> &str;
/// Returns the command line.
///
/// ```no_run
/// use sysinfo::{Pid, ProcessExt, System, SystemExt};
///
/// let s = System::new();
/// if let Some(process) = s.process(Pid::from(1337)) {
/// println!("{:?}", process.cmd());
/// }
/// ```
fn cmd(&self) -> &[String];
/// Returns the path to the process.
///
/// ```no_run
/// use sysinfo::{Pid, ProcessExt, System, SystemExt};
///
/// let s = System::new();
/// if let Some(process) = s.process(Pid::from(1337)) {
/// println!("{}", process.exe().display());
/// }
/// ```
///
/// ### Implementation notes
///
/// On Linux, this method will return an empty path if there
/// was an error trying to read `/proc/<pid>/exe`. This can
/// happen, for example, if the permission levels or UID namespaces
/// between the caller and target processes are different.
///
/// It is also the case that `cmd[0]` is _not_ usually a correct
/// replacement for this.
/// A process [may change its `cmd[0]` value](https://man7.org/linux/man-pages/man5/proc.5.html)
/// freely, making this an untrustworthy source of information.
fn exe(&self) -> &Path;
/// Returns the pid of the process.
///
/// ```no_run
/// use sysinfo::{Pid, ProcessExt, System, SystemExt};
///
/// let s = System::new();
/// if let Some(process) = s.process(Pid::from(1337)) {
/// println!("{}", process.pid());
/// }
/// ```
fn pid(&self) -> Pid;
/// Returns the environment variables of the process.
///
/// ```no_run
/// use sysinfo::{Pid, ProcessExt, System, SystemExt};
///
/// let s = System::new();
/// if let Some(process) = s.process(Pid::from(1337)) {
/// println!("{:?}", process.environ());
/// }
/// ```
fn environ(&self) -> &[String];
/// Returns the current working directory.
///
/// ```no_run
/// use sysinfo::{Pid, ProcessExt, System, SystemExt};
///
/// let s = System::new();
/// if let Some(process) = s.process(Pid::from(1337)) {
/// println!("{}", process.cwd().display());
/// }
/// ```
fn cwd(&self) -> &Path;
/// Returns the path of the root directory.
///
/// ```no_run
/// use sysinfo::{Pid, ProcessExt, System, SystemExt};
///
/// let s = System::new();
/// if let Some(process) = s.process(Pid::from(1337)) {
/// println!("{}", process.root().display());
/// }
/// ```
fn root(&self) -> &Path;
/// Returns the memory usage (in bytes).
///
/// ```no_run
/// use sysinfo::{Pid, ProcessExt, System, SystemExt};
///
/// let s = System::new();
/// if let Some(process) = s.process(Pid::from(1337)) {
/// println!("{} bytes", process.memory());
/// }
/// ```
fn memory(&self) -> u64;
/// Returns the virtual memory usage (in bytes).
///
/// ```no_run
/// use sysinfo::{Pid, ProcessExt, System, SystemExt};
///
/// let s = System::new();
/// if let Some(process) = s.process(Pid::from(1337)) {
/// println!("{} bytes", process.virtual_memory());
/// }
/// ```
fn virtual_memory(&self) -> u64;
/// Returns the parent pid.
///
/// ```no_run
/// use sysinfo::{Pid, ProcessExt, System, SystemExt};
///
/// let s = System::new();
/// if let Some(process) = s.process(Pid::from(1337)) {
/// println!("{:?}", process.parent());
/// }
/// ```
fn parent(&self) -> Option<Pid>;
/// Returns the status of the processus.
///
/// ```no_run
/// use sysinfo::{Pid, ProcessExt, System, SystemExt};
///
/// let s = System::new();
/// if let Some(process) = s.process(Pid::from(1337)) {
/// println!("{:?}", process.status());
/// }
/// ```
fn status(&self) -> ProcessStatus;
/// Returns the time where the process was started (in seconds) from epoch.
///
/// ```no_run
/// use sysinfo::{Pid, ProcessExt, System, SystemExt};
///
/// let s = System::new();
/// if let Some(process) = s.process(Pid::from(1337)) {
/// println!("Started at {} seconds", process.start_time());
/// }
/// ```
fn start_time(&self) -> u64;
/// Returns for how much time the process has been running (in seconds).
///
/// ```no_run
/// use sysinfo::{Pid, ProcessExt, System, SystemExt};
///
/// let s = System::new();
/// if let Some(process) = s.process(Pid::from(1337)) {
/// println!("Running since {} seconds", process.run_time());
/// }
/// ```
fn run_time(&self) -> u64;
/// Returns the total CPU usage (in %). Notice that it might be bigger than 100 if run on a
/// multicore machine.
///
/// If you want a value between 0% and 100%, divide the returned value by the number of CPU
/// CPUs.
///
/// **Warning**: If you want accurate CPU usage number, better leave a bit of time
/// between two calls of this method (200 ms for example).
///
/// ```no_run
/// use sysinfo::{Pid, ProcessExt, System, SystemExt};
///
/// let s = System::new();
/// if let Some(process) = s.process(Pid::from(1337)) {
/// println!("{}%", process.cpu_usage());
/// }
/// ```
fn cpu_usage(&self) -> f32;
/// Returns number of bytes read and written to disk.
///
/// ⚠️ On Windows and FreeBSD, this method actually returns **ALL** I/O read and written bytes.
///
/// ```no_run
/// use sysinfo::{Pid, ProcessExt, System, SystemExt};
///
/// let s = System::new();
/// if let Some(process) = s.process(Pid::from(1337)) {
/// let disk_usage = process.disk_usage();
/// println!("read bytes : new/total => {}/{}",
/// disk_usage.read_bytes,
/// disk_usage.total_read_bytes,
/// );
/// println!("written bytes: new/total => {}/{}",
/// disk_usage.written_bytes,
/// disk_usage.total_written_bytes,
/// );
/// }
/// ```
fn disk_usage(&self) -> DiskUsage;
/// Returns the ID of the owner user of this process or `None` if this information couldn't
/// be retrieved. If you want to get the [`User`] from it, take a look at
/// [`SystemExt::get_user_by_id`].
///
/// ```no_run
/// use sysinfo::{Pid, ProcessExt, System, SystemExt};
///
/// let mut s = System::new_all();
///
/// if let Some(process) = s.process(Pid::from(1337)) {
/// eprintln!("User id for process 1337: {:?}", process.user_id());
/// }
/// ```
fn user_id(&self) -> Option<&Uid>;
/// Returns the process group ID of the process.
///
/// ⚠️ It always returns `None` on Windows.
///
/// ```no_run
/// use sysinfo::{Pid, ProcessExt, System, SystemExt};
///
/// let mut s = System::new_all();
///
/// if let Some(process) = s.process(Pid::from(1337)) {
/// eprintln!("Group ID for process 1337: {:?}", process.group_id());
/// }
/// ```
fn group_id(&self) -> Option<Gid>;
/// Wait for process termination.
///
/// ```no_run
/// use sysinfo::{Pid, ProcessExt, System, SystemExt};
///
/// let mut s = System::new_all();
///
/// if let Some(process) = s.process(Pid::from(1337)) {
/// eprintln!("Waiting for pid 1337");
/// process.wait();
/// eprintln!("Pid 1337 exited");
/// }
/// ```
fn wait(&self);
/// Returns the session ID for the current process or `None` if it couldn't be retrieved.
///
/// ⚠️ This information is computed every time this method is called.
///
/// ```no_run
/// use sysinfo::{Pid, ProcessExt, System, SystemExt};
///
/// let mut s = System::new_all();
///
/// if let Some(process) = s.process(Pid::from(1337)) {
/// eprintln!("Session ID for process 1337: {:?}", process.session_id());
/// }
/// ```
fn session_id(&self) -> Option<Pid>;
}
/// Contains all the methods of the [`Cpu`][crate::Cpu] struct.
pub trait CpuExt: Debug {
/// Returns this CPU's usage.
///
/// Note: You'll need to refresh it at least twice (diff between the first and the second is
/// how CPU usage is computed) at first if you want to have a non-zero value.
///
/// ```no_run
/// use sysinfo::{CpuExt, System, SystemExt};
///
/// let s = System::new();
/// for cpu in s.cpus() {
/// println!("{}%", cpu.cpu_usage());
/// }
/// ```
fn cpu_usage(&self) -> f32;
/// Returns this CPU's name.
///
/// ```no_run
/// use sysinfo::{CpuExt, System, SystemExt};
///
/// let s = System::new();
/// for cpu in s.cpus() {
/// println!("{}", cpu.name());
/// }
/// ```
fn name(&self) -> &str;
/// Returns the CPU's vendor id.
///
/// ```no_run
/// use sysinfo::{CpuExt, System, SystemExt};
///
/// let s = System::new();
/// for cpu in s.cpus() {
/// println!("{}", cpu.vendor_id());
/// }
/// ```
fn vendor_id(&self) -> &str;
/// Returns the CPU's brand.
///
/// ```no_run
/// use sysinfo::{CpuExt, System, SystemExt};
///
/// let s = System::new();
/// for cpu in s.cpus() {
/// println!("{}", cpu.brand());
/// }
/// ```
fn brand(&self) -> &str;
/// Returns the CPU's frequency.
///
/// ```no_run
/// use sysinfo::{CpuExt, System, SystemExt};
///
/// let s = System::new();
/// for cpu in s.cpus() {
/// println!("{}", cpu.frequency());
/// }
/// ```
fn frequency(&self) -> u64;
}
/// Contains all the methods of the [`System`][crate::System] type.
pub trait SystemExt: Sized + Debug + Default + Send + Sync {
/// Returns `true` if this OS is supported. Please refer to the
/// [crate-level documentation](index.html) to get the list of supported OSes.
///
/// ```
/// use sysinfo::{System, SystemExt};
///
/// if System::IS_SUPPORTED {
/// println!("This OS is supported!");
/// } else {
/// println!("This OS isn't supported (yet?).");
/// }
/// ```
const IS_SUPPORTED: bool;
/// Returns the list of the supported signals on this system (used by
/// [`ProcessExt::kill_with`]).
///
/// ```
/// use sysinfo::{System, SystemExt};
///
/// println!("supported signals: {:?}", System::SUPPORTED_SIGNALS);
/// ```
const SUPPORTED_SIGNALS: &'static [Signal];
/// Creates a new [`System`] instance with nothing loaded. If you want to
/// load components, network interfaces or the disks, you'll have to use the
/// `refresh_*_list` methods. [`SystemExt::refresh_networks_list`] for
/// example.
///
/// Use the [`refresh_all`] method to update its internal information (or any of the `refresh_`
/// method).
///
/// [`System`]: crate::System
/// [`refresh_all`]: #method.refresh_all
///
/// ```no_run
/// use sysinfo::{System, SystemExt};
///
/// let s = System::new();
/// ```
fn new() -> Self {
Self::new_with_specifics(RefreshKind::new())
}
/// Creates a new [`System`] instance with everything loaded.
///
/// It is an equivalent of [`SystemExt::new_with_specifics`]`(`[`RefreshKind::everything`]`())`.
///
/// [`System`]: crate::System
///
/// ```no_run
/// use sysinfo::{System, SystemExt};
///
/// let s = System::new_all();
/// ```
fn new_all() -> Self {
Self::new_with_specifics(RefreshKind::everything())
}
/// Creates a new [`System`] instance and refresh the data corresponding to the
/// given [`RefreshKind`].
///
/// [`System`]: crate::System
///
/// ```
/// use sysinfo::{RefreshKind, System, SystemExt};
///
/// // We want everything except disks.
/// let mut system = System::new_with_specifics(RefreshKind::everything().without_disks_list());
///
/// assert_eq!(system.disks().len(), 0);
/// # if System::IS_SUPPORTED && !cfg!(feature = "apple-sandbox") {
/// assert!(system.processes().len() > 0);
/// # }
///
/// // If you want the disks list afterwards, just call the corresponding
/// // "refresh_disks_list":
/// system.refresh_disks_list();
/// let disks = system.disks();
/// ```
fn new_with_specifics(refreshes: RefreshKind) -> Self;
/// Refreshes according to the given [`RefreshKind`]. It calls the corresponding
/// "refresh_" methods.
///
/// ```
/// use sysinfo::{ProcessRefreshKind, RefreshKind, System, SystemExt};
///
/// let mut s = System::new_all();
///
/// // Let's just update networks and processes:
/// s.refresh_specifics(
/// RefreshKind::new().with_networks().with_processes(ProcessRefreshKind::everything()),
/// );
/// ```
fn refresh_specifics(&mut self, refreshes: RefreshKind) {
if refreshes.memory() {
self.refresh_memory();
}
if let Some(kind) = refreshes.cpu() {
self.refresh_cpu_specifics(kind);
}
if refreshes.components_list() {
self.refresh_components_list();
} else if refreshes.components() {
self.refresh_components();
}
if refreshes.networks_list() {
self.refresh_networks_list();
} else if refreshes.networks() {
self.refresh_networks();
}
if let Some(kind) = refreshes.processes() {
self.refresh_processes_specifics(kind);
}
if refreshes.disks_list() {
self.refresh_disks_list();
} else if refreshes.disks() {
self.refresh_disks();
}
if refreshes.users_list() {
self.refresh_users_list();
}
}
/// Refreshes all system, processes, disks and network interfaces information.
///
/// Please note that it doesn't recompute disks list, components list, network interfaces
/// list nor users list.
///
/// ```no_run
/// use sysinfo::{System, SystemExt};
///
/// let mut s = System::new_all();
/// s.refresh_all();
/// ```
fn refresh_all(&mut self) {
self.refresh_system();
self.refresh_processes();
self.refresh_disks();
self.refresh_networks();
}
/// Refreshes system information (RAM, swap, CPU usage and components' temperature).
///
/// If you want some more specific refreshes, you might be interested into looking at
/// [`refresh_memory`], [`refresh_cpu`] and [`refresh_components`].
///
/// [`refresh_memory`]: SystemExt::refresh_memory
/// [`refresh_cpu`]: SystemExt::refresh_memory
/// [`refresh_components`]: SystemExt::refresh_components
///
/// ```no_run
/// use sysinfo::{System, SystemExt};
///
/// let mut s = System::new_all();
/// s.refresh_system();
/// ```
fn refresh_system(&mut self) {
self.refresh_memory();
self.refresh_cpu();
self.refresh_components();
}
/// Refreshes RAM and SWAP usage.
///
/// ```no_run
/// use sysinfo::{System, SystemExt};
///
/// let mut s = System::new_all();
/// s.refresh_memory();
/// ```
fn refresh_memory(&mut self);
/// Refreshes CPUs information.
///
/// ⚠️ Please note that the result will very likely be inaccurate at the first call.
/// You need to call this method at least twice (with a bit of time between each call, like
/// 200ms) to get accurate values as it uses previous results to compute the next value.
///
/// Calling this method is the same as calling
/// `refresh_cpu_specifics(CpuRefreshKind::new().with_cpu_usage())`.
///
/// ```no_run
/// use sysinfo::{System, SystemExt};
///
/// let mut s = System::new_all();
/// s.refresh_cpu();
/// ```
fn refresh_cpu(&mut self) {
self.refresh_cpu_specifics(CpuRefreshKind::new().with_cpu_usage())
}
/// Refreshes CPUs specific information.
///
/// Please note that it doesn't recompute disks list, components list, network interfaces
/// list nor users list.
///
/// ```no_run
/// use sysinfo::{System, SystemExt, CpuRefreshKind};
///
/// let mut s = System::new_all();
/// s.refresh_cpu_specifics(CpuRefreshKind::everything());
/// ```
fn refresh_cpu_specifics(&mut self, refresh_kind: CpuRefreshKind);
/// Refreshes components' temperature.
///
/// ```no_run
/// use sysinfo::{System, SystemExt};
///
/// let mut s = System::new_all();
/// s.refresh_components();
/// ```
fn refresh_components(&mut self) {
for component in self.components_mut() {
component.refresh();
}
}
/// Refreshes components list.
///
/// ```no_run
/// use sysinfo::{System, SystemExt};
///
/// let mut s = System::new();
/// s.refresh_components_list();
/// ```
fn refresh_components_list(&mut self);
/// Gets all processes and updates their information.
///
/// It does the same as `system.refresh_processes_specifics(ProcessRefreshKind::everything())`.
///
/// ⚠️ On Linux, `sysinfo` keeps the `stat` files open by default. You can change this behaviour
/// by using [`set_open_files_limit`][crate::set_open_files_limit].
///
/// ```no_run
/// use sysinfo::{System, SystemExt};
///
/// let mut s = System::new_all();
/// s.refresh_processes();
/// ```
fn refresh_processes(&mut self) {
self.refresh_processes_specifics(ProcessRefreshKind::everything());
}
/// Gets all processes and updates the specified information.
///
/// ⚠️ On Linux, `sysinfo` keeps the `stat` files open by default. You can change this behaviour
/// by using [`set_open_files_limit`][crate::set_open_files_limit].
///
/// ```no_run
/// use sysinfo::{ProcessRefreshKind, System, SystemExt};
///
/// let mut s = System::new_all();
/// s.refresh_processes_specifics(ProcessRefreshKind::new());
/// ```
fn refresh_processes_specifics(&mut self, refresh_kind: ProcessRefreshKind);
/// Refreshes *only* the process corresponding to `pid`. Returns `false` if the process doesn't
/// exist (it will **NOT** be removed from the processes if it doesn't exist anymore). If it
/// isn't listed yet, it'll be added.
///
/// It is the same as calling
/// `sys.refresh_process_specifics(pid, ProcessRefreshKind::everything())`.
///
/// ```no_run
/// use sysinfo::{Pid, System, SystemExt};
///
/// let mut s = System::new_all();
/// s.refresh_process(Pid::from(1337));
/// ```
fn refresh_process(&mut self, pid: Pid) -> bool {
self.refresh_process_specifics(pid, ProcessRefreshKind::everything())
}
/// Refreshes *only* the process corresponding to `pid`. Returns `false` if the process doesn't
/// exist (it will **NOT** be removed from the processes if it doesn't exist anymore). If it
/// isn't listed yet, it'll be added.
///
/// ```no_run
/// use sysinfo::{Pid, ProcessRefreshKind, System, SystemExt};
///
/// let mut s = System::new_all();
/// s.refresh_process_specifics(Pid::from(1337), ProcessRefreshKind::new());
/// ```
fn refresh_process_specifics(&mut self, pid: Pid, refresh_kind: ProcessRefreshKind) -> bool;
/// Refreshes the listed disks' information.
///
/// ```no_run
/// use sysinfo::{System, SystemExt};
///
/// let mut s = System::new_all();
/// s.refresh_disks();
/// ```
fn refresh_disks(&mut self) {
for disk in self.disks_mut() {
disk.refresh();
}
}
/// The disk list will be emptied then completely recomputed.
///
/// ## Linux
///
/// ⚠️ On linux, the [NFS](https://en.wikipedia.org/wiki/Network_File_System) file
/// systems are ignored and the information of a mounted NFS **cannot** be obtained
/// via [`SystemExt::refresh_disks_list`]. This is due to the fact that I/O function
/// `statvfs` used by [`SystemExt::refresh_disks_list`] is blocking and
/// [may hang](https://github.com/GuillaumeGomez/sysinfo/pull/876) in some cases,
/// requiring to call `systemctl stop` to terminate the NFS service from the remote
/// server in some cases.
///
/// ```no_run
/// use sysinfo::{System, SystemExt};
///
/// let mut s = System::new_all();
/// s.refresh_disks_list();
/// ```
fn refresh_disks_list(&mut self);
/// Refreshes users list.
///
/// ```no_run
/// use sysinfo::{System, SystemExt};
///
/// let mut s = System::new_all();
/// s.refresh_users_list();
/// ```
fn refresh_users_list(&mut self);
/// Refreshes networks data.
///
/// ```no_run
/// use sysinfo::{System, SystemExt};
///
/// let mut s = System::new_all();
/// s.refresh_networks();
/// ```
///
/// It is a shortcut for:
///
/// ```no_run
/// use sysinfo::{NetworksExt, System, SystemExt};
///
/// let mut s = System::new_all();
/// let networks = s.networks_mut();
/// networks.refresh();
/// ```
fn refresh_networks(&mut self) {
self.networks_mut().refresh();
}
/// The network list will be updated: removing not existing anymore interfaces and adding new
/// ones.
///
/// ```no_run
/// use sysinfo::{System, SystemExt};
///
/// let mut s = System::new_all();
/// s.refresh_networks_list();
/// ```
///
/// This is a shortcut for:
///
/// ```no_run
/// use sysinfo::{NetworksExt, System, SystemExt};
///
/// let mut s = System::new_all();
/// let networks = s.networks_mut();
/// networks.refresh_networks_list();
/// ```
fn refresh_networks_list(&mut self) {
self.networks_mut().refresh_networks_list();
}
/// Returns the process list.
///
/// ```no_run
/// use sysinfo::{ProcessExt, System, SystemExt};
///
/// let s = System::new_all();
/// for (pid, process) in s.processes() {
/// println!("{} {}", pid, process.name());
/// }
/// ```
fn processes(&self) -> &HashMap<Pid, Process>;
/// Returns the process corresponding to the given pid or `None` if no such process exists.
///
/// ```no_run
/// use sysinfo::{Pid, ProcessExt, System, SystemExt};
///
/// let s = System::new_all();
/// if let Some(process) = s.process(Pid::from(1337)) {
/// println!("{}", process.name());
/// }
/// ```
fn process(&self, pid: Pid) -> Option<&Process>;
/// Returns an iterator of process containing the given `name`.
///
/// If you want only the processes with exactly the given `name`, take a look at
/// [`SystemExt::processes_by_exact_name`].
///
/// **⚠️ Important ⚠️**
///
/// On **linux**, there are two things to know about processes' name:
/// 1. It is limited to 15 characters.
/// 2. It is not always the exe name.
///
/// ```no_run
/// use sysinfo::{ProcessExt, System, SystemExt};
///
/// let s = System::new_all();
/// for process in s.processes_by_name("htop") {
/// println!("{} {}", process.pid(), process.name());
/// }
/// ```
// FIXME: replace the returned type with `impl Iterator<Item = &Process>` when it's supported!
fn processes_by_name<'a>(
&'a self,
name: &'a str,
) -> Box<dyn Iterator<Item = &'a Process> + 'a> {
Box::new(
self.processes()
.values()
.filter(move |val: &&Process| val.name().contains(name)),
)
}
/// Returns an iterator of processes with exactly the given `name`.
///
/// If you instead want the processes containing `name`, take a look at
/// [`SystemExt::processes_by_name`].
///
/// **⚠️ Important ⚠️**
///
/// On **linux**, there are two things to know about processes' name:
/// 1. It is limited to 15 characters.
/// 2. It is not always the exe name.
///
/// ```no_run
/// use sysinfo::{ProcessExt, System, SystemExt};
///
/// let s = System::new_all();
/// for process in s.processes_by_exact_name("htop") {
/// println!("{} {}", process.pid(), process.name());
/// }
/// ```
// FIXME: replace the returned type with `impl Iterator<Item = &Process>` when it's supported!
fn processes_by_exact_name<'a>(
&'a self,
name: &'a str,
) -> Box<dyn Iterator<Item = &'a Process> + 'a> {
Box::new(
self.processes()
.values()
.filter(move |val: &&Process| val.name() == name),
)
}
/// Returns "global" cpus information (aka the addition of all the CPUs).
///
/// To have up-to-date information, you need to call [`SystemExt::refresh_cpu`] or
/// [`SystemExt::refresh_specifics`] with `cpu` enabled.
///
/// ```no_run
/// use sysinfo::{CpuRefreshKind, CpuExt, RefreshKind, System, SystemExt};
///
/// let s = System::new_with_specifics(
/// RefreshKind::new().with_cpu(CpuRefreshKind::everything()),
/// );
/// println!("{}%", s.global_cpu_info().cpu_usage());
/// ```
fn global_cpu_info(&self) -> &Cpu;
/// Returns the list of the CPUs.
///
/// By default, the list of cpus is empty until you call [`SystemExt::refresh_cpu`] or
/// [`SystemExt::refresh_specifics`] with `cpu` enabled.
///
/// ```no_run
/// use sysinfo::{CpuRefreshKind, CpuExt, RefreshKind, System, SystemExt};
///
/// let s = System::new_with_specifics(
/// RefreshKind::new().with_cpu(CpuRefreshKind::everything()),
/// );
/// for cpu in s.cpus() {
/// println!("{}%", cpu.cpu_usage());
/// }
/// ```
fn cpus(&self) -> &[Cpu];
/// Returns the number of physical cores on the CPU or `None` if it couldn't get it.
///
/// In case there are multiple CPUs, it will combine the physical core count of all the CPUs.
///
/// **Important**: this information is computed every time this function is called.
///
/// ```no_run
/// use sysinfo::{CpuExt, System, SystemExt};
///
/// let s = System::new();
/// println!("{:?}", s.physical_core_count());
/// ```
fn physical_core_count(&self) -> Option<usize>;
/// Returns the RAM size in bytes.
///
/// ```no_run
/// use sysinfo::{System, SystemExt};
///
/// let s = System::new_all();
/// println!("{} bytes", s.total_memory());
/// ```
fn total_memory(&self) -> u64;
/// Returns the amount of free RAM in bytes.
///
/// Generally, "free" memory refers to unallocated memory whereas "available" memory refers to
/// memory that is available for (re)use.
///
/// Side note: Windows doesn't report "free" memory so this method returns the same value
/// as [`get_available_memory`](#tymethod.available_memory).
///
/// ```no_run
/// use sysinfo::{System, SystemExt};
///
/// let s = System::new_all();
/// println!("{} bytes", s.free_memory());
/// ```
fn free_memory(&self) -> u64;
/// Returns the amount of available RAM in bytes.
///
/// Generally, "free" memory refers to unallocated memory whereas "available" memory refers to
/// memory that is available for (re)use.
///
/// ⚠️ Windows and FreeBSD don't report "available" memory so [`SystemExt::free_memory`]
/// returns the same value as this method.
///
/// ```no_run
/// use sysinfo::{System, SystemExt};
///
/// let s = System::new_all();
/// println!("{} bytes", s.available_memory());
/// ```
fn available_memory(&self) -> u64;
/// Returns the amount of used RAM in bytes.
///
/// ```no_run
/// use sysinfo::{System, SystemExt};
///
/// let s = System::new_all();
/// println!("{} bytes", s.used_memory());
/// ```
fn used_memory(&self) -> u64;
/// Returns the SWAP size in bytes.
///
/// ```no_run
/// use sysinfo::{System, SystemExt};
///
/// let s = System::new_all();
/// println!("{} bytes", s.total_swap());
/// ```
fn total_swap(&self) -> u64;
/// Returns the amount of free SWAP in bytes.
///
/// ```no_run
/// use sysinfo::{System, SystemExt};
///
/// let s = System::new_all();
/// println!("{} bytes", s.free_swap());
/// ```
fn free_swap(&self) -> u64;
/// Returns the amount of used SWAP in bytes.
///
/// ```no_run
/// use sysinfo::{System, SystemExt};
///
/// let s = System::new_all();
/// println!("{} bytes", s.used_swap());
/// ```
fn used_swap(&self) -> u64;
/// Returns the components list.
///
/// ```no_run
/// use sysinfo::{ComponentExt, System, SystemExt};
///
/// let s = System::new_all();
/// for component in s.components() {
/// println!("{}: {}°C", component.label(), component.temperature());
/// }
/// ```
fn components(&self) -> &[Component];
/// Returns a mutable components list.
///
/// ```no_run
/// use sysinfo::{ComponentExt, System, SystemExt};
///
/// let mut s = System::new_all();
/// for component in s.components_mut() {
/// component.refresh();
/// }
/// ```
fn components_mut(&mut self) -> &mut [Component];
/// Returns the users list.
///
/// ```no_run
/// use sysinfo::{System, SystemExt, UserExt};
///
/// let mut s = System::new_all();
/// for user in s.users() {
/// println!("{} is in {} groups", user.name(), user.groups().len());
/// }
/// ```
fn users(&self) -> &[User];
/// Returns the disks list.
///
/// ```no_run
/// use sysinfo::{DiskExt, System, SystemExt};
///
/// let s = System::new_all();
/// for disk in s.disks() {
/// println!("{:?}", disk.name());
/// }
/// ```
fn disks(&self) -> &[Disk];
/// Returns the disks list.
///
/// ```no_run
/// use sysinfo::{DiskExt, System, SystemExt};
///
/// let mut s = System::new_all();
/// for disk in s.disks_mut() {
/// disk.refresh();
/// }
/// ```
fn disks_mut(&mut self) -> &mut [Disk];
/// Sort the disk list with the provided callback.
///
/// Internally, it is using the [`slice::sort_unstable_by`] function, so please refer to it
/// for implementation details.
///
/// ⚠️ If you use [`SystemExt::refresh_disks_list`], you need to use this method before using
/// [`SystemExt::disks`] or [`SystemExt::disks_mut`] if you want them to be sorted.
fn sort_disks_by<F>(&mut self, compare: F)
where
F: FnMut(&Disk, &Disk) -> std::cmp::Ordering;
/// Returns the network interfaces object.
///
/// ```no_run
/// use sysinfo::{NetworkExt, NetworksExt, System, SystemExt};
///
/// let s = System::new_all();
/// let networks = s.networks();
/// for (interface_name, data) in networks {
/// println!(
/// "[{}] in: {}, out: {}",
/// interface_name,
/// data.received(),
/// data.transmitted(),
/// );
/// }
/// ```
fn networks(&self) -> &Networks;
/// Returns a mutable access to network interfaces.
///
/// ```no_run
/// use sysinfo::{NetworkExt, NetworksExt, System, SystemExt};
///
/// let mut s = System::new_all();
/// let networks = s.networks_mut();
/// networks.refresh_networks_list();
/// ```
fn networks_mut(&mut self) -> &mut Networks;
/// Returns system uptime (in seconds).
///
/// ```no_run
/// use sysinfo::{System, SystemExt};
///
/// let s = System::new_all();
/// println!("System running since {} seconds", s.uptime());
/// ```
fn uptime(&self) -> u64;
/// Returns the time (in seconds) when the system booted since UNIX epoch.
///
/// ```no_run
/// use sysinfo::{System, SystemExt};
///
/// let s = System::new();
/// println!("System booted at {} seconds", s.boot_time());
/// ```
fn boot_time(&self) -> u64;
/// Returns the system load average value.
///
/// ```no_run
/// use sysinfo::{System, SystemExt};
///
/// let s = System::new_all();
/// let load_avg = s.load_average();
/// println!(
/// "one minute: {}%, five minutes: {}%, fifteen minutes: {}%",
/// load_avg.one,
/// load_avg.five,
/// load_avg.fifteen,
/// );
/// ```
fn load_average(&self) -> LoadAvg;
/// Returns the system name.
///
/// **Important**: this information is computed every time this function is called.
///
/// ```no_run
/// use sysinfo::{System, SystemExt};
///
/// let s = System::new();
/// println!("OS: {:?}", s.name());
/// ```
fn name(&self) -> Option<String>;
/// Returns the system's kernel version.
///
/// **Important**: this information is computed every time this function is called.
///
/// ```no_run
/// use sysinfo::{System, SystemExt};
///
/// let s = System::new();
/// println!("kernel version: {:?}", s.kernel_version());
/// ```
fn kernel_version(&self) -> Option<String>;
/// Returns the system version (e.g. for MacOS this will return 11.1 rather than the kernel version).
///
/// **Important**: this information is computed every time this function is called.
///
/// ```no_run
/// use sysinfo::{System, SystemExt};
///
/// let s = System::new();
/// println!("OS version: {:?}", s.os_version());
/// ```
fn os_version(&self) -> Option<String>;
/// Returns the system long os version (e.g "MacOS 11.2 BigSur").
///
/// **Important**: this information is computed every time this function is called.
///
/// ```no_run
/// use sysinfo::{System, SystemExt};
///
/// let s = System::new();
/// println!("Long OS Version: {:?}", s.long_os_version());
/// ```
fn long_os_version(&self) -> Option<String>;
/// Returns the distribution id as defined by os-release,
/// or [`std::env::consts::OS`].
///
/// See also
/// - <https://www.freedesktop.org/software/systemd/man/os-release.html#ID=>
/// - <https://doc.rust-lang.org/std/env/consts/constant.OS.html>
///
/// **Important**: this information is computed every time this function is called.
///
/// ```no_run
/// use sysinfo::{System, SystemExt};
///
/// let s = System::new();
/// println!("Distribution ID: {:?}", s.distribution_id());
/// ```
fn distribution_id(&self) -> String;
/// Returns the system hostname based off DNS
///
/// **Important**: this information is computed every time this function is called.
///
/// ```no_run
/// use sysinfo::{System, SystemExt};
///
/// let s = System::new();
/// println!("Hostname: {:?}", s.host_name());
/// ```
fn host_name(&self) -> Option<String>;
/// Returns the [`User`] matching the given `user_id`.
///
/// **Important**: The user list must be filled before using this method, otherwise it will
/// always return `None` (through the `refresh_*` methods).
///
/// It is a shorthand for:
///
/// ```ignore
/// let s = System::new_all();
/// s.users().find(|user| user.id() == user_id);
/// ```
///
/// Full example:
///
/// ```no_run
/// use sysinfo::{Pid, ProcessExt, System, SystemExt};
///
/// let mut s = System::new_all();
///
/// if let Some(process) = s.process(Pid::from(1337)) {
/// if let Some(user_id) = process.user_id() {
/// eprintln!("User for process 1337: {:?}", s.get_user_by_id(user_id));
/// }
/// }
/// ```
fn get_user_by_id(&self, user_id: &Uid) -> Option<&User> {
self.users().iter().find(|user| user.id() == user_id)
}
}
/// Getting volume of received and transmitted data.
pub trait NetworkExt: Debug {
/// Returns the number of received bytes since the last refresh.
///
/// ```no_run
/// use sysinfo::{NetworkExt, NetworksExt, System, SystemExt};
///
/// let s = System::new_all();
/// let networks = s.networks();
/// for (interface_name, network) in networks {
/// println!("in: {} B", network.received());
/// }
/// ```
fn received(&self) -> u64;
/// Returns the total number of received bytes.
///
/// ```no_run
/// use sysinfo::{NetworkExt, NetworksExt, System, SystemExt};
///
/// let s = System::new_all();
/// let networks = s.networks();
/// for (interface_name, network) in networks {
/// println!("in: {} B", network.total_received());
/// }
/// ```
fn total_received(&self) -> u64;
/// Returns the number of transmitted bytes since the last refresh.
///
/// ```no_run
/// use sysinfo::{NetworkExt, NetworksExt, System, SystemExt};
///
/// let s = System::new_all();
/// let networks = s.networks();
/// for (interface_name, network) in networks {
/// println!("out: {} B", network.transmitted());
/// }
/// ```
fn transmitted(&self) -> u64;
/// Returns the total number of transmitted bytes.
///
/// ```no_run
/// use sysinfo::{NetworkExt, NetworksExt, System, SystemExt};
///
/// let s = System::new_all();
/// let networks = s.networks();
/// for (interface_name, network) in networks {
/// println!("out: {} B", network.total_transmitted());
/// }
/// ```
fn total_transmitted(&self) -> u64;
/// Returns the number of incoming packets since the last refresh.
///
/// ```no_run
/// use sysinfo::{NetworkExt, NetworksExt, System, SystemExt};
///
/// let s = System::new_all();
/// let networks = s.networks();
/// for (interface_name, network) in networks {
/// println!("in: {}", network.packets_received());
/// }
/// ```
fn packets_received(&self) -> u64;
/// Returns the total number of incoming packets.
///
/// ```no_run
/// use sysinfo::{NetworkExt, NetworksExt, System, SystemExt};
///
/// let s = System::new_all();
/// let networks = s.networks();
/// for (interface_name, network) in networks {
/// println!("in: {}", network.total_packets_received());
/// }
/// ```
fn total_packets_received(&self) -> u64;
/// Returns the number of outcoming packets since the last refresh.
///
/// ```no_run
/// use sysinfo::{NetworkExt, NetworksExt, System, SystemExt};
///
/// let s = System::new_all();
/// let networks = s.networks();
/// for (interface_name, network) in networks {
/// println!("out: {}", network.packets_transmitted());
/// }
/// ```
fn packets_transmitted(&self) -> u64;
/// Returns the total number of outcoming packets.
///
/// ```no_run
/// use sysinfo::{NetworkExt, NetworksExt, System, SystemExt};
///
/// let s = System::new_all();
/// let networks = s.networks();
/// for (interface_name, network) in networks {
/// println!("out: {}", network.total_packets_transmitted());
/// }
/// ```
fn total_packets_transmitted(&self) -> u64;
/// Returns the number of incoming errors since the last refresh.
///
/// ```no_run
/// use sysinfo::{NetworkExt, NetworksExt, System, SystemExt};
///
/// let s = System::new_all();
/// let networks = s.networks();
/// for (interface_name, network) in networks {
/// println!("in: {}", network.errors_on_received());
/// }
/// ```
fn errors_on_received(&self) -> u64;
/// Returns the total number of incoming errors.
///
/// ```no_run
/// use sysinfo::{NetworkExt, NetworksExt, System, SystemExt};
///
/// let s = System::new_all();
/// let networks = s.networks();
/// for (interface_name, network) in networks {
/// println!("in: {}", network.total_errors_on_received());
/// }
/// ```
fn total_errors_on_received(&self) -> u64;
/// Returns the number of outcoming errors since the last refresh.
///
/// ```no_run
/// use sysinfo::{NetworkExt, NetworksExt, System, SystemExt};
///
/// let s = System::new_all();
/// let networks = s.networks();
/// for (interface_name, network) in networks {
/// println!("out: {}", network.errors_on_transmitted());
/// }
/// ```
fn errors_on_transmitted(&self) -> u64;
/// Returns the total number of outcoming errors.
///
/// ```no_run
/// use sysinfo::{NetworkExt, NetworksExt, System, SystemExt};
///
/// let s = System::new_all();
/// let networks = s.networks();
/// for (interface_name, network) in networks {
/// println!("out: {}", network.total_errors_on_transmitted());
/// }
/// ```
fn total_errors_on_transmitted(&self) -> u64;
/// Returns the MAC address associated to current interface.
///
/// ```no_run
/// use sysinfo::{NetworkExt, NetworksExt, System, SystemExt};
///
/// let s = System::new_all();
/// let networks = s.networks();
/// for (interface_name, network) in networks {
/// println!("MAC address: {}", network.mac_address());
/// }
/// ```
fn mac_address(&self) -> MacAddr;
}
/// Interacting with network interfaces.
pub trait NetworksExt: Debug {
/// Returns an iterator over the network interfaces.
///
/// ```no_run
/// use sysinfo::{NetworkExt, NetworksExt, System, SystemExt};
///
/// let s = System::new_all();
/// let networks = s.networks();
/// for (interface_name, network) in networks {
/// println!("in: {} B", network.received());
/// }
/// ```
fn iter(&self) -> NetworksIter;
/// Refreshes the network interfaces list.
///
/// ```no_run
/// use sysinfo::{NetworksExt, System, SystemExt};
///
/// let mut s = System::new_all();
/// let networks = s.networks_mut();
/// networks.refresh_networks_list();
/// ```
fn refresh_networks_list(&mut self);
/// Refreshes the network interfaces' content.
///
/// ```no_run
/// use sysinfo::{NetworksExt, System, SystemExt};
///
/// let mut s = System::new_all();
/// let networks = s.networks_mut();
/// networks.refresh();
/// ```
fn refresh(&mut self);
}
/// Getting a component temperature information.
pub trait ComponentExt: Debug {
/// Returns the temperature of the component (in celsius degree).
///
/// ```no_run
/// use sysinfo::{ComponentExt, System, SystemExt};
///
/// let s = System::new_all();
/// for component in s.components() {
/// println!("{}°C", component.temperature());
/// }
/// ```
///
/// ## Linux
///
/// Returns `f32::NAN` if it failed to retrieve it.
fn temperature(&self) -> f32;
/// Returns the maximum temperature of the component (in celsius degree).
///
/// Note: if `temperature` is higher than the current `max`,
/// `max` value will be updated on refresh.
///
/// ```no_run
/// use sysinfo::{ComponentExt, System, SystemExt};
///
/// let s = System::new_all();
/// for component in s.components() {
/// println!("{}°C", component.max());
/// }
/// ```
///
/// ## Linux
///
/// May be computed by sysinfo from kernel.
/// Returns `f32::NAN` if it failed to retrieve it.
fn max(&self) -> f32;
/// Returns the highest temperature before the component halts (in celsius degree).
///
/// ```no_run
/// use sysinfo::{ComponentExt, System, SystemExt};
///
/// let s = System::new_all();
/// for component in s.components() {
/// println!("{:?}°C", component.critical());
/// }
/// ```
///
/// ## Linux
///
/// Critical threshold defined by chip or kernel.
fn critical(&self) -> Option<f32>;
/// Returns the label of the component.
///
/// ```no_run
/// use sysinfo::{ComponentExt, System, SystemExt};
///
/// let s = System::new_all();
/// for component in s.components() {
/// println!("{}", component.label());
/// }
/// ```
///
/// ## Linux
///
/// Since components informations are retrieved thanks to `hwmon`,
/// the labels are generated as follows.
/// Note: it may change and it was inspired by `sensors` own formatting.
///
/// | name | label | device_model | id_sensor | Computed label by `sysinfo` |
/// |---------|--------|------------|----------|----------------------|
/// | ✓ | ✓ | ✓ | ✓ | `"{name} {label} {device_model} temp{id}"` |
/// | ✓ | ✓ | ✗ | ✓ | `"{name} {label} {id}"` |
/// | ✓ | ✗ | ✓ | ✓ | `"{name} {device_model}"` |
/// | ✓ | ✗ | ✗ | ✓ | `"{name} temp{id}"` |
fn label(&self) -> &str;
/// Refreshes component.
///
/// ```no_run
/// use sysinfo::{ComponentExt, System, SystemExt};
///
/// let mut s = System::new_all();
/// for component in s.components_mut() {
/// component.refresh();
/// }
/// ```
fn refresh(&mut self);
}
/// Getting information for a user.
///
/// It is returned from [`SystemExt::users`].
///
/// ```no_run
/// use sysinfo::{System, SystemExt, UserExt};
///
/// let mut s = System::new_all();
/// for user in s.users() {
/// println!("{} is in {} groups", user.name(), user.groups().len());
/// }
/// ```
pub trait UserExt: Debug {
/// Return the user id of the user.
///
/// ```no_run
/// use sysinfo::{System, SystemExt, UserExt};
///
/// let mut s = System::new_all();
/// for user in s.users() {
/// println!("{:?}", *user.id());
/// }
/// ```
fn id(&self) -> &Uid;
/// Return the group id of the user.
///
/// *NOTE* - On Windows, this value defaults to 0. Windows doesn't have a `username` specific group assigned to the user.
/// They do however have unique [Security Identifiers](https://docs.microsoft.com/en-us/windows/win32/secauthz/security-identifiers)
/// made up of various [Components](https://docs.microsoft.com/en-us/windows/win32/secauthz/sid-components).
/// Pieces of the SID may be a candidate for this field, but it doesn't map well to a single group id.
///
/// ```no_run
/// use sysinfo::{System, SystemExt, UserExt};
///
/// let mut s = System::new_all();
/// for user in s.users() {
/// println!("{}", *user.group_id());
/// }
/// ```
fn group_id(&self) -> Gid;
/// Returns the name of the user.
///
/// ```no_run
/// use sysinfo::{System, SystemExt, UserExt};
///
/// let mut s = System::new_all();
/// for user in s.users() {
/// println!("{}", user.name());
/// }
/// ```
fn name(&self) -> &str;
/// Returns the groups of the user.
///
/// ```no_run
/// use sysinfo::{System, SystemExt, UserExt};
///
/// let mut s = System::new_all();
/// for user in s.users() {
/// println!("{} is in {:?}", user.name(), user.groups());
/// }
/// ```
fn groups(&self) -> &[String];
}