| 1 |
# Examples |
| 2 |
|
| 3 |
These examples can be run by running `cargo run --example example_name` |
| 4 |
|
| 5 |
## dump.rs |
| 6 |
|
| 7 |
Prints out details about the current process (the dumper itself), or a process specifed by PID |
| 8 |
|
| 9 |
## interface_stats.rs |
| 10 |
|
| 11 |
Runs continually and prints out how many bytes/packets are sent/received. Press ctrl-c to exit the example: |
| 12 |
|
| 13 |
```text |
| 14 |
Interface: bytes recv bytes sent |
| 15 |
================ ==================== ==================== |
| 16 |
br-883c4c992deb: 823307769 0.2 kbps 1537694158 0.5 kbps |
| 17 |
br-d73af6e6d094: 9137600399 0.9 kbps 2334717319 0.4 kbps |
| 18 |
docker0: 2938964881 0.6 kbps 19291691656 11.4 kbps |
| 19 |
docker_gwbridge: 1172300 0.0 kbps 15649536 0.0 kbps |
| 20 |
enp5s0f0: 44643307888420 5599.8 kbps 1509415976135 99.0 kbps |
| 21 |
enp5s0f1: 0 0.0 kbps 0 0.0 kbps |
| 22 |
lo: 161143108162 0.4 kbps 161143108162 0.4 kbps |
| 23 |
veth3154ff3: 3809619534 1.0 kbps 867529906 0.4 kbps |
| 24 |
veth487bc9b: 2650532684 0.8 kbps 2992458899 0.9 kbps |
| 25 |
veth8cb8ca8: 3234030733 0.7 kbps 16921098378 11.4 kbps |
| 26 |
vethbadbe14: 12007615348 3.8 kbps 15583195644 5.0 kbps |
| 27 |
vethc152f93: 978828 0.0 kbps 3839134 0.0 kbps |
| 28 |
vethe481f30: 1637142 0.0 kbps 15805768 0.0 kbps |
| 29 |
vethfac2e83: 19445827683 6.2 kbps 16194181515 5.1 kbps |
| 30 |
|
| 31 |
``` |
| 32 |
|
| 33 |
## netstat.rs |
| 34 |
|
| 35 |
Prints out all open and listening TCP/UDP sockets, along with the owning process. The |
| 36 |
output format is very similar to the standard `netstat` linux utility: |
| 37 |
|
| 38 |
```text |
| 39 |
Local address Remote address State Inode PID/Program name |
| 40 |
0.0.0.0:53 0.0.0.0:0 Listen 30883 1409/pdns_server |
| 41 |
0.0.0.0:51413 0.0.0.0:0 Listen 24263 927/transmission-da |
| 42 |
0.0.0.0:35445 0.0.0.0:0 Listen 21777 942/rpc.mountd |
| 43 |
0.0.0.0:22 0.0.0.0:0 Listen 27973 1149/sshd |
| 44 |
0.0.0.0:25 0.0.0.0:0 Listen 28295 1612/master |
| 45 |
``` |
| 46 |
|
| 47 |
## pressure.rs |
| 48 |
|
| 49 |
Prints out CPU/IO/Memory pressure information |
| 50 |
|
| 51 |
## ps.rs |
| 52 |
|
| 53 |
Prints out all processes that share the same tty as the current terminal. This is very similar to the standard |
| 54 |
`ps` utility on linux when run with no arguments: |
| 55 |
|
| 56 |
```text |
| 57 |
PID TTY TIME CMD |
| 58 |
8369 pty/13 4.05 bash |
| 59 |
23124 pty/13 0.23 basic-http-serv |
| 60 |
24206 pty/13 0.11 ps |
| 61 |
``` |
| 62 |
|
| 63 |
## self_memory.rs |
| 64 |
|
| 65 |
Shows several ways to get the current memory usage of the current process |
| 66 |
|
| 67 |
```text |
| 68 |
PID: 21867 |
| 69 |
Memory page size: 4096 |
| 70 |
== Data from /proc/self/stat: |
| 71 |
Total virtual memory used: 3436544 bytes |
| 72 |
Total resident set: 220 pages (901120 bytes) |
| 73 |
|
| 74 |
== Data from /proc/self/statm: |
| 75 |
Total virtual memory used: 839 pages (3436544 bytes) |
| 76 |
Total resident set: 220 pages (901120 byte)s |
| 77 |
Total shared memory: 191 pages (782336 bytes) |
| 78 |
|
| 79 |
== Data from /proc/self/status: |
| 80 |
Total virtual memory used: 3436544 bytes |
| 81 |
Total resident set: 901120 bytes |
| 82 |
Total shared memory: 782336 bytes |
| 83 |
``` |
| 84 |
|
| 85 |
## lsmod.rs |
| 86 |
|
| 87 |
This lists all the loaded kernel modules, in a simple tree format. |
| 88 |
|
| 89 |
## diskstat.rs |
| 90 |
|
| 91 |
Lists IO information for local disks: |
| 92 |
|
| 93 |
```text |
| 94 |
sda1 mounted on /: |
| 95 |
total reads: 7325390 (13640070 ms) |
| 96 |
total writes: 124191552 (119109541 ms) |
| 97 |
total flushes: 0 (0 ms) |
| 98 |
``` |
| 99 |
|
| 100 |
Note: only local disks will be shown (not NFS mounts, |
| 101 |
and disks used for ZFS will not be shown either). |
| 102 |
|
| 103 |
## lslocks.rs |
| 104 |
|
| 105 |
Shows current file locks in a format that is similiar to the `lslocks` utility. |
| 106 |
|
| 107 |
## mountinfo.rs |
| 108 |
|
| 109 |
Lists all mountpoints, along with their type and options: |
| 110 |
|
| 111 |
```text |
| 112 |
sysfs on /sys type sysfs (noexec,relatime,nodev,rw,nosuid) |
| 113 |
proc on /proc type proc (noexec,rw,nodev,relatime,nosuid) |
| 114 |
udev on /dev type devtmpfs (rw,nosuid,relatime) |
| 115 |
mode = 755 |
| 116 |
nr_inodes = 4109298 |
| 117 |
size = 16437192k |
| 118 |
devpts on /dev/pts type devpts (nosuid,rw,noexec,relatime) |
| 119 |
gid = 5 |
| 120 |
ptmxmode = 000 |
| 121 |
mode = 620 |
| 122 |
tmpfs on /run type tmpfs (rw,nosuid,noexec,relatime) |
| 123 |
size = 3291852k |
| 124 |
mode = 755 |
| 125 |
/dev/sda1 on / type ext4 (rw,relatime) |
| 126 |
errors = remount-ro |
| 127 |
``` |
| 128 |
|
| 129 |
## process_hierarchy.rs |
| 130 |
|
| 131 |
Lists all processes as a tree. Sub-processes will be hierarchically ordered beneath their parents. |
| 132 |
|
| 133 |
```text |
| 134 |
1 /usr/lib/systemd/systemd --system --deserialize 54 |
| 135 |
366 /usr/lib/systemd/systemd-journald |
| 136 |
375 /usr/lib/systemd/systemd-udevd |
| 137 |
383 /usr/bin/lvmetad -f |
| 138 |
525 /usr/bin/dbus-daemon --system --address=systemd: --nofork --nopidfile --systemd-activation --syslog-only |
| 139 |
529 /usr/bin/syncthing -no-browser -no-restart -logflags=0 |
| 140 |
608 /usr/bin/syncthing -no-browser -no-restart -logflags=0 |
| 141 |
530 /usr/lib/systemd/systemd-logind |
| 142 |
... |
| 143 |
``` |
| 144 |
|
| 145 |
## pfn.rs |
| 146 |
|
| 147 |
List memory mapping, and physical address for each virtual address. Must be run as root, see [pagemap.txt](https://www.kernel.org/doc/Documentation/vm/pagemap.txt) |
| 148 |
|
| 149 |
```text |
| 150 |
Memory mapping MemoryMap { address: (140561525968896, 140561525972992), perms: "r--p", offset: 884736, dev: (252, 0), inode: 18221539, pathname: Path("/usr/lib64/libm.so.6") } |
| 151 |
virt_mem: 0x7fd707d31000, pfn: 0x1fd37d, phys_addr: 0x1fd37d000 |
| 152 |
Memory mapping MemoryMap { address: (140561525972992, 140561525977088), perms: "rw-p", offset: 888832, dev: (252, 0), inode: 18221539, pathname: Path("/usr/lib64/libm.so.6") } |
| 153 |
virt_mem: 0x7fd707d32000, pfn: 0x1fcb97, phys_addr: 0x1fcb97000 |
| 154 |
``` |
| 155 |
|
| 156 |
## process_kpageflags.rs |
| 157 |
|
| 158 |
Search for a pointer (virtual address) in physical memory. Display physical page flags |
| 159 |
|
| 160 |
Requires root or sudo |
| 161 |
|
| 162 |
```text |
| 163 |
Virtual address of `variable`: 0x7ffd2de4708f |
| 164 |
Found memory mapping |
| 165 |
MemoryMap { address: (140725373272064, 140725373407232), perms: "rw-p", offset: 0, dev: (0, 0), inode: 0, pathname: Stack } |
| 166 |
Found page |
| 167 |
virt_mem: 0x7ffd2de47000, pfn: 0x107b06, phys_addr: 0x107b06000, flags: UPTODATE | LRU | MMAP | ANON | SWAPBACKED |
| 168 |
``` |
| 169 |
|
| 170 |
## kpagecount |
| 171 |
|
| 172 |
List physical memory pages by reading /proc/iomem, and find the page with the most references |
| 173 |
|
| 174 |
Require root or CAP_SYS_ADMIN |
| 175 |
|
| 176 |
```text |
| 177 |
Found RAM here: 0x1000-0x9fbff |
| 178 |
Lots of references to this locations: addr=0x9d000, pfn=157, refs=0 |
| 179 |
Found RAM here: 0x100000-0xdffeffff |
| 180 |
Lots of references to this locations: addr=0x81ba3000, pfn=531363, refs=128 |
| 181 |
Found RAM here: 0x100000000-0x11fffffff |
| 182 |
Lots of references to this locations: addr=0x1b575000, pfn=111989, refs=134 |
| 183 |
``` |
| 184 |
|
| 185 |
|
| 186 |
## Crypto |
| 187 |
|
| 188 |
List available crypto algorithms, along with details. Passing an algorithm as an argument will show only that algorithms |
| 189 |
|
| 190 |
implementations (this can potentially be multiple). Partial arguments (i.e "sha") will return all algorithms that match. |
| 191 |
|
| 192 |
```text |
| 193 |
Type: sha256 |
| 194 |
Name: sha256 |
| 195 |
Driver: sha256-avx2 |
| 196 |
Module: sha256_ssse3 |
| 197 |
Priority: 170 |
| 198 |
Ref Count: 2 |
| 199 |
Self Test: Passed |
| 200 |
Internal: false |
| 201 |
fips enabled: false |
| 202 |
Type Details: Shash(Shash { block_size: 64, digest_size: 32 }) |
| 203 |
``` |