From afcd79f90b51907c23e12ed354ef2c901b73bb85 Mon Sep 17 00:00:00 2001 From: Chris Guest Date: Tue, 26 Jan 2021 22:51:19 +0000 Subject: [PATCH 1/8] Start a look at resource checking examples --- 27_checking_resources/README.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 27_checking_resources/README.md diff --git a/27_checking_resources/README.md b/27_checking_resources/README.md new file mode 100644 index 0000000..4dc6765 --- /dev/null +++ b/27_checking_resources/README.md @@ -0,0 +1,17 @@ +# Checking Resources + +TODO: +Open sockets +Free memory +File handles +Look at the brenden greigg resources + +## Sockets + +```sh +# listening sockets +ss -l +``` + +free -h + From 3027eed814334eb7ab35633709ef85a2ad268e08 Mon Sep 17 00:00:00 2001 From: Chris Guest Date: Thu, 28 Jan 2021 00:01:10 +0000 Subject: [PATCH 2/8] Update some of tools --- 27_checking_resources/README.md | 49 ++++++++++++++++++++++++++++++--- README.md | 6 +++- 2 files changed, 50 insertions(+), 5 deletions(-) diff --git a/27_checking_resources/README.md b/27_checking_resources/README.md index 4dc6765..385a863 100644 --- a/27_checking_resources/README.md +++ b/27_checking_resources/README.md @@ -1,10 +1,23 @@ # Checking Resources +Demonstrate how to use various commands to verify resource usage in the OS. + TODO: -Open sockets -Free memory -File handles -Look at the brenden greigg resources +* 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 + +## Disk + +```sh +# free space +df -h +``` ## Sockets @@ -12,6 +25,34 @@ Look at the brenden greigg resources # listening sockets ss -l ``` +## 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..017565f 100644 --- a/README.md +++ b/README.md @@ -285,9 +285,13 @@ Steps [README.md](./53_sync_files/README.md) Demonstrate date handling in shell. Steps [README.md](./54_date_handling/README.md) -## TODO +## Example 55 - Checking Resources +Demonstrate how to use various commands to verify resource usage in the OS. +Steps [README.md](./55_checking_resources/README.md) +## 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 From 600f2c1c4260e44ed6b030eb011e26ad45303eee Mon Sep 17 00:00:00 2001 From: Chris Guest Date: Sun, 31 Jan 2021 22:31:01 +0000 Subject: [PATCH 3/8] fix checking resources folder after rebase. --- {27_checking_resources => 28_checking_resources}/README.md | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename {27_checking_resources => 28_checking_resources}/README.md (100%) diff --git a/27_checking_resources/README.md b/28_checking_resources/README.md similarity index 100% rename from 27_checking_resources/README.md rename to 28_checking_resources/README.md From e5ee251841c9fefd92c04022526d54643acd9051 Mon Sep 17 00:00:00 2001 From: Chris Guest Date: Wed, 14 Apr 2021 16:18:53 +0100 Subject: [PATCH 4/8] add start to cgroups --- 28_checking_resources/README.md | 15 +++++++++++++++ 34_checking_resources/CGROUPS.md | 30 ++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 34_checking_resources/CGROUPS.md diff --git a/28_checking_resources/README.md b/28_checking_resources/README.md index 385a863..ba3b653 100644 --- a/28_checking_resources/README.md +++ b/28_checking_resources/README.md @@ -12,6 +12,10 @@ TODO: * debugfs https://github.com/raboof/nethogs +## Check limits +```sh +ulimit -a +``` ## Disk ```sh @@ -22,9 +26,20 @@ 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 diff --git a/34_checking_resources/CGROUPS.md b/34_checking_resources/CGROUPS.md new file mode 100644 index 0000000..1392887 --- /dev/null +++ b/34_checking_resources/CGROUPS.md @@ -0,0 +1,30 @@ +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 + +## Limits +docker run -it ubuntu:20.04 /bin/bash -c "ulimit -a" + +ulimit -a + +cat /proc/$$/limits + +## Cgroups +```sh +cat /proc/filesystems +mount +``` + +```sh +ls /sys/fs/cgroup/ +``` + From 1acdce7fda7eb022193959bc145b417bd74bba2f Mon Sep 17 00:00:00 2001 From: Chris Guest Date: Wed, 14 Apr 2021 17:50:30 +0100 Subject: [PATCH 5/8] update --- 28_checking_resources/README.md | 26 +++++++++++++- 34_checking_resources/CGROUPS.md | 59 ++++++++++++++++++++++---------- 2 files changed, 66 insertions(+), 19 deletions(-) diff --git a/28_checking_resources/README.md b/28_checking_resources/README.md index ba3b653..46cdb84 100644 --- a/28_checking_resources/README.md +++ b/28_checking_resources/README.md @@ -3,6 +3,7 @@ Demonstrate how to use various commands to verify resource usage in the OS. TODO: +* cgroups * Open sockets * Free memory * File handles @@ -12,10 +13,33 @@ TODO: * 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 -ulimit -a +# 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 diff --git a/34_checking_resources/CGROUPS.md b/34_checking_resources/CGROUPS.md index 1392887..75bb6dc 100644 --- a/34_checking_resources/CGROUPS.md +++ b/34_checking_resources/CGROUPS.md @@ -1,30 +1,53 @@ -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 +# README +Demonstrate how to work with cgroups +## cgroups +```sh +# man pages +man cgroups -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 +# list filesystems and look at cgroups +cat /proc/filesystems -## Limits -docker run -it ubuntu:20.04 /bin/bash -c "ulimit -a" +# see where they a virtually mounted +mount +``` -ulimit -a +## Install tooling +```sh +# install tooling +sudo apt install cgroup-tools -cat /proc/$$/limits +# list cgroup tools +dpkg -L cgroup-tools | grep bin -## Cgroups -```sh -cat /proc/filesystems -mount ``` +## 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 From 7965fca0a17dce22a7a924451a9683efce36e3f4 Mon Sep 17 00:00:00 2001 From: Chris Guest Date: Tue, 5 Apr 2022 20:56:18 +0000 Subject: [PATCH 6/8] update resource checks --- .../README.md | 0 README.md | 8 ++++---- 2 files changed, 4 insertions(+), 4 deletions(-) rename {28_checking_resources => 34_checking_resources}/README.md (100%) diff --git a/28_checking_resources/README.md b/34_checking_resources/README.md similarity index 100% rename from 28_checking_resources/README.md rename to 34_checking_resources/README.md diff --git a/README.md b/README.md index 017565f..8b1868f 100644 --- a/README.md +++ b/README.md @@ -215,6 +215,10 @@ 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,10 +289,6 @@ Steps [README.md](./53_sync_files/README.md) Demonstrate date handling in shell. Steps [README.md](./54_date_handling/README.md) -## Example 55 - Checking Resources -Demonstrate how to use various commands to verify resource usage in the OS. -Steps [README.md](./55_checking_resources/README.md) - ## TODO: * oh-my-zsh and oh-my-bash * Globbing From 70ab8d7f05a0940c00ff10e06f93bccc4dbeeed0 Mon Sep 17 00:00:00 2001 From: Chris Guest Date: Tue, 5 Apr 2022 20:57:39 +0000 Subject: [PATCH 7/8] Add extra line to readme --- README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 8b1868f..9add2e7 100644 --- a/README.md +++ b/README.md @@ -216,8 +216,9 @@ 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) + +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 From ffdd07e248c3a86b02c209981d29a77a0cf6bede Mon Sep 17 00:00:00 2001 From: Chris Guest Date: Thu, 28 Apr 2022 08:56:42 +0100 Subject: [PATCH 8/8] Update readme --- 34_checking_resources/README.md | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/34_checking_resources/README.md b/34_checking_resources/README.md index 46cdb84..b844c20 100644 --- a/34_checking_resources/README.md +++ b/34_checking_resources/README.md @@ -1,17 +1,20 @@ -# Checking Resources +# 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 +* Free memory * File handles * Look at the brenden gregg resources http://www.brendangregg.com/linuxperf.html * Filesystem * Procfs * debugfs -https://github.com/raboof/nethogs +* https://github.com/raboof/nethogs ```sh @@ -26,6 +29,7 @@ systemctl show ``` ## Check limits + ```sh # limits inside a container docker run -it ubuntu:20.04 /bin/bash -c "ulimit -a"