Difference between revisions of "Resource Monitoring Tools"
(→iotop) |
|||
Line 1: | Line 1: | ||
<small>There are programs available to watch various aspects of your system. | <small>There are programs available to watch various aspects of your system. | ||
− | ==iftop== | + | ==Network== |
+ | ===iftop=== | ||
See active internet connections. | See active internet connections. | ||
e.g. | e.g. | ||
Line 9: | Line 10: | ||
alt: | alt: | ||
netstat | head -n 20 | netstat | head -n 20 | ||
+ | ===Speed/Bandwidth=== | ||
+ | iperf3 | ||
+ | iperf | ||
− | == | + | ==RAM== |
See RAM usage. Can be watched, to monitor swapping. | See RAM usage. Can be watched, to monitor swapping. | ||
e.g. | e.g. | ||
Line 16: | Line 20: | ||
Leave it running. It will update every 3 seconds. | Leave it running. It will update every 3 seconds. | ||
− | ==iotop== | + | ==Filesystem== |
+ | ===iotop=== | ||
See HDD accesses. | See HDD accesses. | ||
e.g. | e.g. | ||
Line 28: | Line 33: | ||
See also: | See also: | ||
https://hackaday.com/2020/11/05/linux-fu-monitor-disks/ | https://hackaday.com/2020/11/05/linux-fu-monitor-disks/ | ||
+ | https://en.wikipedia.org/wiki/Bonnie%2B%2B | ||
+ | i can't remember how often i test file system speed though. I am not working in a data center. It's | ||
+ | never been necessary. | ||
+ | |||
+ | ===List Open Files=== | ||
+ | lsof | ||
+ | Note: there are different types of lsof (e.g. busybox's) | ||
+ | |||
==Monitor Library Reads from PID== | ==Monitor Library Reads from PID== | ||
Line 84: | Line 97: | ||
− | |||
− | |||
− | |||
− | + | ||
− | |||
− | |||
</small> | </small> |
Revision as of 23:12, 7 November 2020
There are programs available to watch various aspects of your system.
Network
iftop
See active internet connections. e.g.
# iftop -i eth1
Will show you websites that don't close a connection, when the tab is left open. A privacy and security nightmare. This is a reason why Javascript is bad.
alt:
netstat | head -n 20
Speed/Bandwidth
iperf3 iperf
RAM
See RAM usage. Can be watched, to monitor swapping. e.g.
$ vmstat 3
Leave it running. It will update every 3 seconds.
Filesystem
iotop
See HDD accesses. e.g.
# iotop --only # iotop -o
only flag will show active processes only
# iotop -d 0.01 or -d 0.1
delay flag can be set to be faster than 1 second. Some writes are missed otherwise.
See also:
https://hackaday.com/2020/11/05/linux-fu-monitor-disks/
https://en.wikipedia.org/wiki/Bonnie%2B%2B
i can't remember how often i test file system speed though. I am not working in a data center. It's
never been necessary.
List Open Files
lsof Note: there are different types of lsof (e.g. busybox's)
Monitor Library Reads from PID
$ ltrace -p -pidhere-
See what a program is doing. (Note: not available on ARM deb repos)
Monitor IP address up/down via ping
#!/bin/bash SERVERIP=$1 LOGFILE=$1_$(date +%A)_LOG HISTORYFILE=$1_$(date +%A)_LOCKFILE NOTIFYEMAIL=myemail@address.com #setup this script in cron each minute, and also #crontab requires historyfile / lockfile to be blanked (echo "" > file) each day or each hour, whatever you prefer. #mkdir /var/log/networkalerts #e.g. $ script.sh <ipaddress> # in /etc/crontab #*/3 * * * * root /root/email_alerts/test_up.sh 192.168.1.1 #tune this frequency based on your priority #0 */2 * * * root rm /var/log/networkalerts/*LOCKFILE #0 0 * * * root rm /var/log/networkalerts/*$(date +%A)*LOG #keep track of time date >> /var/log/networkalerts/$LOGFILE ping -c 6 $SERVERIP >> /var/log/networkalerts/$LOGFILE #nothing after ping, as we need return value #if return val is error (see man on ping regarding count and deadline) # == or -eq can be used. == is intuitive, therefore better if test $? == 1 then #if file empty #[ -s FILE ] True if FILE exists and has a size greater than zero. Thus, you get "empty.txt" if "diff.txt" is not e> #https://stackoverflow.com/questions/9964823/how-to-check-if-a-file-is-empty-in-bash #https://mywiki.wooledge.org/BashGuide/TestsAndConditionals for all the other tests like -s # [! -s file] to invert didn't work because of missing spaces (i think) # must be space between [ and -s and also last bracket. test brackets are unintuitive so don't use them. # if [ -s /var/log/networkalerts/$HISTORYFILE ] if test -s /var/log/networkalerts/$HISTORYFILE then exit 5 else # Use your favorite mailer here: # wiki.zoneminder.com/Email explains how to configure email for devuan echo "alert" | mutt -s "Network Down" -- $NOTIFYEMAIL #lock file / history file echo "alertsent" > /var/log/networkalerts/$HISTORYFILE fi fi