יום ראשון, 16 ביוני 2013

How to generate CPU load?


Sometimes, system administrators are asked to generate 'dummy' load on CPU to test the load vs performance. Here is a short example which shows how to generate load per CPU or per Core basis (actually threads):



 # perl -e 'while (--$ARGV[0] and fork) {}; while () {}' 4


The last digit "4" in this case indicates how many CPUs or threads or cores you want to load by this method. This indeed is a good idea to test the CPU performance when some of the threaded/virtual CPUs are loaded.

When I gave the above command, in other terminal window for same server, I can observe something like this:

# mpstat 5
CPU minf mjf xcal  intr ithr  csw icsw migr smtx  srw syscl  usr sys  wt idl
  0    0   0   10   213  105   17    0    0    0    0    38    0   2   0  98
  1    0   0    0     1    0    0    0    0    0    0     0    0   0   0 100
  2    0   0    0     2    0    2    0    0    0    0     0    0   0   0 100
  3    0   0    0     1    0    0    0    0    0    0     0    0   0   0 100
  4    0   0    0     2    0    2    0    0    0    0     5    0   0   0 100
  5    0   0    3     4    0    6    0    0    0    0     0    0   0   0 100
  6    0   0    1    13    6   11    0    0    0    0     0    0   0   0 100
  7    0   0    4     3    0    4    0    0    0    0    10    0   0   0 100
CPU minf mjf xcal  intr ithr  csw icsw migr smtx  srw syscl  usr sys  wt idl
  0   21   7  139   227  118   18    9    0    1    0    53   85   1   0  14
  1    4   0    7     9    0   16    0    4    0    0     4    1   1   0  98
  2   10   0    0     8    0    5    5    0    1    0     1   85   0   0  15
  3    0   1   34     7    0   11    0    1    0    0     3    0   0   0 100
  4    6   0    0     6    0    2    4    0    0    0     4   84   0   0  16
  5    7   0    0     2    0    1    0    1    1    0     1    0   0   0 100
  6   10   0    4    12    5    3    5    0    0    0     1   85   0   0  15
  7    0   0   21    16    0   31    0    0    0    0    10    0   0   0 100
CPU minf mjf xcal  intr ithr  csw icsw migr smtx  srw syscl  usr sys  wt idl
  0    0   0   30   207  106    0    8    0    0    0     0  100   0   0   0
  1    0   0    0     9    0   15    0    1    0    0    23    0   1   0  99
  2    0   0    0     6    0    0    5    0    0    0     0  100   0   0   0
  3    0   0    3     8    0   13    0    1    0    0    12    0   0   0 100
  4    0   0    0     6    0    0    5    0    0    0     0  100   0   0   0
  5    0   0    0     2    0    0    0    0    0    0     0    0   0   0 100
  6    0   0    1    10    3    2    7    0    0    0     0  100   0   0   0
  7    0   0    0     1    0    0    0    0    0    0     0    0   0   0 100
^C


The 'top' command output in this case will look like following:
# top
last pid:   698;  load avg:  1.61,  0.44,  0.19;       up 25+19:31:24                                                                             10:59:01
34 processes: 29 sleeping, 5 on cpu
CPU states: 49.8% idle, 50.0% user,  0.2% kernel,  0.0% iowait,  0.0% swap
Memory: 8192M phys mem, 6680M free mem, 4099M total swap, 4099M free swap

   PID USERNAME LWP PRI NICE  SIZE   RES STATE    TIME    CPU COMMAND
   694 root       1   0    0 6368K 3256K cpu/0    0:35 12.50% perl
   696 root       1   0    0 6360K 1672K cpu/7    0:35 12.45% perl
   697 root       1   0    0 6360K 1672K cpu/1    0:35 12.45% perl
   695 root       1   0    0 6360K 1800K cpu/6    0:35 12.14% perl
   698 root       1  59    0 2944K 2104K cpu/3    0:00  0.03% top
   679 root       1  59    0   10M 3576K sleep    0:00  0.00% sshd
   119 root      24  59    0 4576K 4232K sleep    1:25  0.00% nscd
     9 root      15  59    0   10M 9704K sleep    0:42  0.00% svc.configd
   238 root       4  59    0 7888K 4664K sleep    0:29  0.00% inetd
     7 root      12  59    0   13M 9904K sleep    0:34  0.00% svc.startd
   302 root      16  59    0   15M 9400K sleep    0:27  0.00% fmd
   202 root       1  59    0 1360K 1176K sleep    0:04  0.00% utmpd
   183 daemon     1  59    0 2848K 2360K sleep    0:11  0.00% rpcbind
   253 root       3  59    0 7464K 3160K sleep    0:08  0.00% automountd
     1 root       1  59    0 2512K 1920K sleep    0:05  0.00% init

Postfix: fatal: parameter inet_interfaces [solved]

Postfix: fatal: parameter inet_interfaces: no local interface found for IP

Edit the file /etc/postfix/main.cf (sudo nano /etc/postfix/main.cf), search for the line:
inet_interfaces = all
And change it to:
inet_interfaces = 127.0.0.1, 66.66.66.66, 66.66.66.67
Save, exit and restart postfix (sudo service postfix restart).

Zabbix configuration

1. Install Zabbix Agent on Cent-OS 6.X
cd /etc/yum.repos.d/ ; wget "http://download.opensuse.org/repositories/home:/ericgearhart:/zabbix/CentOS_CentOS-6/home:ericgearhart:zabbix.repo"
yum install zabbix-agent -y
chkconfig --add zabbix-agentd
chkconfig zabbix-agentd on
vi /usr/local/etc/zabbix_agentd.conf
service zabbix-agentd start

* Update CLI - Install Zabbix Agent:
# rpm -ivh http://repo.zabbix.com/zabbix/2.2/rhel/6/x86_64/zabbix-release-2.2-1.el6.noarch.rpm
# yum install zabbix-agent
# chkconfig zabbix-agent on
# vi /etc/zabbix/zabbix_agentd.conf
# /etc/init.d/zabbix-agent start

MySQL Monitor:
  http://vmhacks.com/how-to-setup-mysql-enterprise-monitoring-with-zabbix/
  • [root@vmhacks.com ~]# mkdir /var/lib/zabbix
  • Right, now you can place your MySQL client connection information into this directory.  When the Zabbix agent runs the UserParameter commands, it will check the /var/lib/zabbix/.my.cnf  for a username and password.  So that means you need something like the following in your /var/lib/zabbix/.my.cnf file:
    • [client]
    • user=zabbix_boy
    • password=boyimtired


  http://blog.themilkyway.org/2013/11/how-to-monitor-mysql-using-the-new-zabbix-template-app-mysql/

# mysql -uroot -p<mysql root password goes here> -e"GRANT USAGE ON *.* TO 'zabbix'@'127.0.0.1' IDENTIFIED BY '123456'";
# mysql -uroot -p<mysql root password goes here> -e"GRANT USAGE ON *.* TO 'zabbix'@'localhost' IDENTIFIED BY '123456'";
# mysql -uroot -p<mysql root password goes here> -e"flush privileges"
# mysql -uzabbix -p123456 -e"status"

Create a new /etc/zabbix/.my.cnf config file with the mysql login (created above) to be used by zabbix to connect to the mysql server for monitoring purpose.
1
2
3
4
5
6
[mysql]
user=zabbix
password=123456
[mysqladmin]
user=zabbix
password=123456
Your zabbix agent config file should already have the line "Include=/etc/zabbix/zabbix_agentd.d/" which will automatically load all config files under that folder by default (including theuserparameter_mysql.conf file). If not then you will need to do the below to load the config file.
In the main zabbix config file include the below line to enable loading of the mysql file.

Include=/etc/zabbix/zabbix_agentd.d/
Restart the zabbix agent to load the new config file.

service zabbix-agent restart

2.Set time and date on Zabbix server in the BIOS and on the OS with the command:
date MMDDhhmmYYYY
OR use "yast"

3. How to set "date.timezone" option in php.ini - Change the date.timezone value in PHP:

#vi /etc/php5/apache2/php.ini
find&change:  date.timezone = "Asia/Jerusalem"

#/etc/init.d/apache2 restart