tcler's blog --- 其实我是一个程序员
Show me your flowcharts and conceal your tables, and I shall continue to be mystified. Show me your tables, and I won’t usually need your flowcharts; they’ll be obvious.

RH442(性能调优) 学习笔记

sar & gnuplot & pcp

learning practice

LANG=C sar -n DEV >/tmp/sar-n-dev.log
awk 'BEGIN {OFS="\t"} $1 ~ /^[0-9]/ && $2 == "eth0" {print $1, $3}' /tmp/sar-n-dev.log >/tmp/sar-eth0-rx.data
awk 'BEGIN {OFS="\t"} $1 ~ /^[0-9]/ && $2 == "eth0" {print $1, $4}' /tmp/sar-n-dev.log >/tmp/sar-eth0-tx.data

cat <<EOF >net-pkg.gp
set xdata time
set timefmt "%H:%M:%S"
set format x "%H:%M"
set xtics rotate
set xlabel "Time"
set ylabel "packages/s"
plot if using 1:2 title "received" with lines
EOF

gnuplot -persist -e 'if="/tmp/sar-eth0-rx.data"' net-pkg.gp

cat <<EOF >net-pkg.gp
set term png crop
set output of

set xdata time
set timefmt "%H:%M:%S"
set format x "%H:%M"
set xtics rotate
set xlabel "Time"
set ylabel "packages/s"
plot if using 1:2 title "rx" with lines, \
if2 using 1:2 linecolor 3 title "tx" with lines
EOF

gnuplot -persist -e 'if="/tmp/sar-eth0-rx.data"' -e 'if2="/tmp/sar-eth0-tx.data"' -e 'of="net-pkg.png"' net-pkg.gp
eog net-pkg.png

#ref: https://www.codelast.com/%E5%8E%9F%E5%88%9B-gnuplot%E8%B0%83%E6%95%99%E8%AE%B0/

lab practice

#> 1. Edit the cron definition that collects sar data to run sa1 every minute.
vi /etc/cron.d/sysstat
head -n 2 /etc/cron.d/sysstat
## Run system activity accounting tool every 10 minutes
# * * * * * root /usr/lib64/sa/sa1 1 1

#> 2. Run lab graphing setup
lab graphing setup

#> 3. 4. 5. 6. see 'learning practice'

#> 7. Install Performance Co-Pilot. (pcp)
yum -y install pcp-gui

#> 8. Start Performance Co-Pilot.
service pcp start;
chkconfig pcp on;
service pcp status;

#> 9. Capture 10 samples of the mem.util.used metric from Performance Co-Pilot.
pmval -s 10 mem.util.used > /tmp/pcp-mem.util.used.data

#> 10.  Create a view using pmchart that includes the following charts: mem.util.used, disk.all.aveq, and proc.nprocs.
pmchart &

Click the New Chart button. On the Metrics tab, select mem > util > used. Click OK.
Click the New Chart button. On the Metrics tab, select disk > all > aveq. Click OK.
Click the New Chart button. On the Metrics tab, select proc > nprocs. Click OK.

#> 11.  Save your chart as graphtest.
Open the File menu, select Save View ... On the resulting dialog window, in the Filename: field, enter graphtest. Click Save.

#> 12. Download the sampleserver.tgz
wget http://content.example.com/courses/rh442/rhel7.0/materials/sampleserver.tgz
tar -xf sampleserver.tgz
# Determine the parameter which would provide the one-minute load average.
pminfo | grep load
pminfo -t kernel.all.load
# Determine the highest one-minute load average experienced.
pmval -a sampleserver.log/20150223.12.24.0 kernel.all.load | tail -n +11 | awk '{print $2}' | sort -rn | head -n 5
# Determine the first time that the one-minute load average reached 19.12.
pmval -a sampleserver.log/20150223.12.24.0 kernel.all.load | grep 19\.12 | head -n 1

GENERAL TUNING

The Linux kernel exposes information and tunables to user space through the /proc directory.
/proc is a user space-accessible area of kernel memory attached into the file system. 
/proc holds information about the system, as seen by the kernel, such as:
- /proc/cpuinfo, /proc/meminfo, /proc/swaps, /proc/<PID>, /proc/sys

Userspace utilities often use the data in /proc to gather the information they display. For
example, the uptime command gathers its data from /proc/uptime and /proc/loadavg.
Sometimes the data in /proc is used directly, like with /proc/loadavg, though sometimes the
user space utility needs to do some additional processing to convert the data into human-friendly
format, as with /proc/uptime.

One of the directories in /proc, /proc/sys, shows data relating to how the kernel handles
many low-level operating system activities, but unlike most of the files in /proc, files in
/proc/sys are generally writable by root. Through making changes to files in /proc/sys, 
administrators can make changes to their running Linux kernel to change its behavior. This is
an incredibly powerful feature offered by the Linux kernel.

learning practice

yum install -y tuned
systemctl enable tuned
systemctl start tuned
tuned-adm active
tuned-adm list
tuned-adm profile powersave && tuned-adm active

ls /usr/lib/tuned
ls /etc/tuned

mkdir /etc/tuned/myprofile
vi /etc/tuned/myprofile/tuned.conf
[main]
include=powersave

#[NAME]
#type=<pluginname>  #omitted if section <NAME> == <pluginname>
#devices=<devices>

[vm]
transparent_hugepages=never

[all_sd_disks]
type=disk
devices=sd*
readahead=4096

[not_all_sd_disks]
type=disk
devices=!sda, !sdc
readahead=4096

#ls /usr/lib/tuned/functions
#create /etc/tuned/profilename/scriptxxx.sh
[script]
script=scriptxxx.sh

[sysctl]
net.ipv4.icmp_echo_ignore_all=1
# end vi

yum install -y tuna

lab practice

#> 1. Create a new custom tuned profile on serverX called virt-guest-lab.
mkdir /etc/tuned/virt-guest-lab
vi    /etc/tuned/virt-guest-lab/tuned.conf
cat   /etc/tuned/virt-guest-lab/tuned.conf
[main]
include=virtual-guest

[sysctl]
vm.swappiness=10

[vm]
transparent_hugepages=never

#> 2. Enable the newly created tuned profile virt-guest-lab.
tuned-adm profile virt-guest-lab