diff --git a/34_checking_resources/CGROUPS.md b/34_checking_resources/CGROUPS.md new file mode 100644 index 0000000..75bb6dc --- /dev/null +++ b/34_checking_resources/CGROUPS.md @@ -0,0 +1,53 @@ +# README +Demonstrate how to work with cgroups + +## cgroups +```sh +# man pages +man cgroups + +# list filesystems and look at cgroups +cat /proc/filesystems + +# see where they a virtually mounted +mount +``` + +## Install tooling +```sh +# install tooling +sudo apt install cgroup-tools + +# list cgroup tools +dpkg -L cgroup-tools | grep bin + +``` + +## Walk the filesystem +```sh +# cgroups v1 +ls /sys/fs/cgroup/ + +# cgroups v2 +ls /sys/fs/cgroup/unified +``` + + +## Resources +https://medium.com/nttlabs/cgroup-v2-596d035be4d7 + + +https://opensource.com/article/20/10/cgroups + +https://www.linuxjournal.com/content/everything-you-need-know-about-linux-containers-part-i-linux-control-groups-and-process + +https://www.linuxjournal.com/content/everything-you-need-know-about-linux-containers-part-ii-working-linux-containers-lxc + + +SSH in a cgroup +https://unix.stackexchange.com/questions/209199/how-to-ensure-ssh-via-cgroups-on-centos + +https://unix.stackexchange.com/questions/56538/controlling-priority-of-applications-using-cgroups + +cgroupsv2 +https://unix.stackexchange.com/questions/471476/how-do-i-check-cgroup-v2-is-installed-on-my-machine diff --git a/34_checking_resources/README.md b/34_checking_resources/README.md new file mode 100644 index 0000000..b844c20 --- /dev/null +++ b/34_checking_resources/README.md @@ -0,0 +1,101 @@ +# Checking Resources + +Demonstrate how to use various commands to verify resource usage in the OS. + +REF: [14_interrogate_resources](https://github.com/chrisguest75/sysadmin_examples/tree/master/14_interrogate_resources) + +TODO: + +* cgroups +* Open sockets +* Free memory +* File handles +* Look at the brenden gregg resources http://www.brendangregg.com/linuxperf.html +* Filesystem +* Procfs +* debugfs +* https://github.com/raboof/nethogs + + +```sh +# booted with +cat /proc/cmdline + +# built with +cat /boot/config-5.8.0-49-generic | grep CGROUP + +# global limits +systemctl show +``` + +## Check limits + +```sh +# limits inside a container +docker run -it ubuntu:20.04 /bin/bash -c "ulimit -a" + +# limits on host +ulimit -a + +# limits for current pid +cat /proc/$$/limits + +# show global config +systemctl show +``` + +## Disk + +```sh +# free space +df -h +``` + +## Sockets + +```sh +# summary of all the sockets +ss -s + +# listening sockets +ss -l + +# listening sockets with processes +sudo ss -lp + +# tcp connections with information +ss -ti +``` + + +## Memory + +```sh +free -h + +vmstat +``` + +## IO + +[sysstat](https://www.linux.com/training-tutorials/sysstat-howto-deployment-and-configuration-guide-linux-servers/) + +```sh + +sudo apt install sysstat + +# cpu usage +mpstat -A + + + +``` + + + +top +systemd-cgtop +systemd-analyze blame + +systemctl list-units -t service + diff --git a/README.md b/README.md index 5ebfda6..9add2e7 100644 --- a/README.md +++ b/README.md @@ -215,6 +215,11 @@ Steps [README.md](./32_jq/README.md) Demonstrates using awscli to query resources in an AWS account. Steps [README.md](./33_awscli/README.md) +## Example 34 - Checking Resources + +Demonstrate how to use various commands to verify resource usage in the OS. +Steps [README.md](./34_checking_resources/README.md) + ## Example 35 - APT and DPKG Demonstrate examples of working with APT and DPKG @@ -285,9 +290,9 @@ Steps [README.md](./53_sync_files/README.md) Demonstrate date handling in shell. Steps [README.md](./54_date_handling/README.md) -## TODO - +## TODO: * oh-my-zsh and oh-my-bash + * Globbing * Process Substition versus command substitution < <() < $() * Detecting dotsourcing. https://stackoverflow.com/questions/2683279/how-to-detect-if-a-script-is-being-sourced