2.linux monitor cpu&mem收集資料
oracle6機器是收集cpu&mem的機器,訪問其他的linux伺服器
1.在/etc/hosts新增IP和hostname對應關係
[root@oracle6 ~]# more /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
172.16.99.35 oracle6
172.16.99.19 oracle
172.16.99.20 xxxxx
192.168.xxx.xxx standby
192.168.xxx.xxx xxxxxxx1
192.168.xxx.xxx xxxxxxx2
2.在所有對應的機器建立相應的user
[root@oracle6 ~]# useradd mon
[root@oracle6 ~]# passwd mon
Changing password for user mon.
New password:
BAD PASSWORD: it is WAY too short
BAD PASSWORD: is too simple
Retype new password:
passwd: all authentication tokens updated successfully.
3.配置ssh
[root@oracle6 .ssh]# su - mon
[mon@oracle6 ~]$ ll .ssh
ls: cannot access .ssh: No such file or directory
[mon@oracle6 ~]$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/mon/.ssh/id_rsa):
Created directory '/home/mon/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/mon/.ssh/id_rsa.
Your public key has been saved in /home/mon/.ssh/id_rsa.pub.
The key fingerprint is:
5c:0e:06:09:64:aa:ae:47:1d:9e:11:e9:58:d8:9c:36 mon@oracle6
The key's randomart image is:
+--[ RSA 2048]----+
| =++.. |
| .oE .. |
| .= o o . |
| .. + o + |
|. o + S . |
|. . + |
| o |
|. . |
|.. |
+-----------------+
[mon@oracle6 ~]$ ll .ssh
total 12
-rw-------. 1 mon mon 1675 Feb 21 17:16 id_rsa
-rw-r--r--. 1 mon mon 393 Feb 21 17:16 id_rsa.pub
-rw-r--r--. 1 mon mon 401 Feb 21 17:17 known_hosts
[mon@oracle6 ~]$ ssh mon@oracle "cat >> ~/.ssh/authorized_keys" < ~/.ssh/id_rsa.pub
The authenticity of host 'oracle (172.16.99.19)' can't be established.
RSA key fingerprint is b6:9f:be:8a:ad:1e:e8:c8:1f:b4:75:04:01:69:0e:5e.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'oracle,172.16.99.19' (RSA) to the list of known hosts.
mon@oracle's password: mon
[mon@oracle6 ~]$ ssh mon@oracle
Last login: Sun Feb 21 17:18:33 2016 from s-file-backend.domain.com
其中遇到過問題就是ssh免密碼登入配置了,但是ssh mon@topaz還是需要輸入密碼.
設定topaz:/home/mon/.ssh/authorized_keys的屬性為600(原來為664)之後,就可以了。
authorized_keys的正確屬性為600
.ssh的正確屬性為700
4.建立收集資料的tablespace,schema,table
SQL> create tablespace mon datafile '/home/oracle/data/mon.dbf' size 8G autoextend off;
Tablespace created.
SQL> create user mon identified by mon default tablespace mon;
User created.
SQL> grant connect,resource to mon;
Grant succeeded.
SQL> conn mon/mon
Connected.
SQL> create table mon_cpumem(
2 hostname varchar2(20),
3 datetime varchar2(30),
4 processrun int,
5 mem_used_pct number(10,2),
6 swapin int,
7 swapout int,
8 cpu_user int,
9 cpu_sys int,
10 cpu_idle int,
11 cpu_wait int,
12 cpu_stole int);
5.收集資料的shell script
[mon@oracle6 source]$ more mon_cpumem
#!/bin/bash
export ORACLE_BASE=/u01/oracle
export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/dbhome_1
export ORACLE_SID=wlcspdb
HOSTNAME=/home/mon/source/mon_cpumem_hostname
MEM_TOTAL=0
MEM_FREE=0
DATETIME=`date +"%Y/%m/%d %H:%M:%S"`
echo $DATETIME
cat $HOSTNAME | while
read LINE
do
MEM_TOTAL=`echo "cat /proc/meminfo | grep -i memtotal" | ssh -Tq mon@$LINE`
VMSTATS=`echo "vmstat 1 3 | tail -1" | ssh -Tq mon@$LINE`
MEM_TOTAL=`echo $MEM_TOTAL | awk '{print $2}'`
MEM_FREE=`echo $VMSTATS | awk '{print $4}'`
let MEM_FREE_PCT=$MEM_FREE*100/$MEM_TOTAL
let MEM_USED_PCT=100-$MEM_FREE_PCT
PROCESS_RUN=`echo $VMSTATS | awk '{print $1}'`
SWAP_IN=`echo $VMSTATS | awk '{print $7}'`
SWAP_OUT=`echo $VMSTATS | awk '{print $8}'`
CPU_USER=`echo $VMSTATS | awk '{print $13}'`
CPU_SYS=`echo $VMSTATS | awk '{print $14}'`
CPU_IDLE=`echo $VMSTATS | awk '{print $15}'`
CPU_WAIT=`echo $VMSTATS | awk '{print $16}'`
CPU_STOLE=`echo $VMSTATS | awk '{print $17}'`
$ORACLE_HOME/bin/sqlplus -s mon/mon << EOF >> /home/mon/log/mon_cpumem.log
insert into mon_cpumem values ('$LINE','$DATETIME','$PROCESS_RUN','$MEM_USED_PCT','$SWAP_IN','$SWAP_OUT','$CPU_USER','$CPU_SYS','$CPU_IDLE','$CPU_WAIT','$CPU_STOLE');
commit;
exit;
EOF
done
6.定時任務crontab
[mon@oracle6 source]$ crontab -l
* * * * * /home/mon/source/mon_cpumem > /dev/null 2>&1
1.在/etc/hosts新增IP和hostname對應關係
[root@oracle6 ~]# more /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
172.16.99.35 oracle6
172.16.99.19 oracle
172.16.99.20 xxxxx
192.168.xxx.xxx standby
192.168.xxx.xxx xxxxxxx1
192.168.xxx.xxx xxxxxxx2
2.在所有對應的機器建立相應的user
[root@oracle6 ~]# useradd mon
[root@oracle6 ~]# passwd mon
Changing password for user mon.
New password:
BAD PASSWORD: it is WAY too short
BAD PASSWORD: is too simple
Retype new password:
passwd: all authentication tokens updated successfully.
3.配置ssh
[root@oracle6 .ssh]# su - mon
[mon@oracle6 ~]$ ll .ssh
ls: cannot access .ssh: No such file or directory
[mon@oracle6 ~]$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/mon/.ssh/id_rsa):
Created directory '/home/mon/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/mon/.ssh/id_rsa.
Your public key has been saved in /home/mon/.ssh/id_rsa.pub.
The key fingerprint is:
5c:0e:06:09:64:aa:ae:47:1d:9e:11:e9:58:d8:9c:36 mon@oracle6
The key's randomart image is:
+--[ RSA 2048]----+
| =++.. |
| .oE .. |
| .= o o . |
| .. + o + |
|. o + S . |
|. . + |
| o |
|. . |
|.. |
+-----------------+
[mon@oracle6 ~]$ ll .ssh
total 12
-rw-------. 1 mon mon 1675 Feb 21 17:16 id_rsa
-rw-r--r--. 1 mon mon 393 Feb 21 17:16 id_rsa.pub
-rw-r--r--. 1 mon mon 401 Feb 21 17:17 known_hosts
[mon@oracle6 ~]$ ssh mon@oracle "cat >> ~/.ssh/authorized_keys" < ~/.ssh/id_rsa.pub
The authenticity of host 'oracle (172.16.99.19)' can't be established.
RSA key fingerprint is b6:9f:be:8a:ad:1e:e8:c8:1f:b4:75:04:01:69:0e:5e.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'oracle,172.16.99.19' (RSA) to the list of known hosts.
mon@oracle's password: mon
[mon@oracle6 ~]$ ssh mon@oracle
Last login: Sun Feb 21 17:18:33 2016 from s-file-backend.domain.com
其中遇到過問題就是ssh免密碼登入配置了,但是ssh mon@topaz還是需要輸入密碼.
設定topaz:/home/mon/.ssh/authorized_keys的屬性為600(原來為664)之後,就可以了。
authorized_keys的正確屬性為600
.ssh的正確屬性為700
4.建立收集資料的tablespace,schema,table
SQL> create tablespace mon datafile '/home/oracle/data/mon.dbf' size 8G autoextend off;
Tablespace created.
SQL> create user mon identified by mon default tablespace mon;
User created.
SQL> grant connect,resource to mon;
Grant succeeded.
SQL> conn mon/mon
Connected.
SQL> create table mon_cpumem(
2 hostname varchar2(20),
3 datetime varchar2(30),
4 processrun int,
5 mem_used_pct number(10,2),
6 swapin int,
7 swapout int,
8 cpu_user int,
9 cpu_sys int,
10 cpu_idle int,
11 cpu_wait int,
12 cpu_stole int);
5.收集資料的shell script
[mon@oracle6 source]$ more mon_cpumem
#!/bin/bash
export ORACLE_BASE=/u01/oracle
export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/dbhome_1
export ORACLE_SID=wlcspdb
HOSTNAME=/home/mon/source/mon_cpumem_hostname
MEM_TOTAL=0
MEM_FREE=0
DATETIME=`date +"%Y/%m/%d %H:%M:%S"`
echo $DATETIME
cat $HOSTNAME | while
read LINE
do
MEM_TOTAL=`echo "cat /proc/meminfo | grep -i memtotal" | ssh -Tq mon@$LINE`
VMSTATS=`echo "vmstat 1 3 | tail -1" | ssh -Tq mon@$LINE`
MEM_TOTAL=`echo $MEM_TOTAL | awk '{print $2}'`
MEM_FREE=`echo $VMSTATS | awk '{print $4}'`
let MEM_FREE_PCT=$MEM_FREE*100/$MEM_TOTAL
let MEM_USED_PCT=100-$MEM_FREE_PCT
PROCESS_RUN=`echo $VMSTATS | awk '{print $1}'`
SWAP_IN=`echo $VMSTATS | awk '{print $7}'`
SWAP_OUT=`echo $VMSTATS | awk '{print $8}'`
CPU_USER=`echo $VMSTATS | awk '{print $13}'`
CPU_SYS=`echo $VMSTATS | awk '{print $14}'`
CPU_IDLE=`echo $VMSTATS | awk '{print $15}'`
CPU_WAIT=`echo $VMSTATS | awk '{print $16}'`
CPU_STOLE=`echo $VMSTATS | awk '{print $17}'`
$ORACLE_HOME/bin/sqlplus -s mon/mon << EOF >> /home/mon/log/mon_cpumem.log
insert into mon_cpumem values ('$LINE','$DATETIME','$PROCESS_RUN','$MEM_USED_PCT','$SWAP_IN','$SWAP_OUT','$CPU_USER','$CPU_SYS','$CPU_IDLE','$CPU_WAIT','$CPU_STOLE');
commit;
exit;
EOF
done
6.定時任務crontab
[mon@oracle6 source]$ crontab -l
* * * * * /home/mon/source/mon_cpumem > /dev/null 2>&1
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/24237320/viewspace-2006113/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- [Shell] monitor cpu&mem收集資料
- 收集資料
- 大資料資料收集大資料
- osw的資料收集
- matplotlib 資料收集
- android 資料收集Android
- python收集jvm資料PythonJVM
- VERITAS Storage Foundation資料收集
- 038 收集表單資料
- SQL SERVER收集資料庫使用增量資料SQLServer資料庫
- faker 資料填充常用指令收集
- 個人資料收集(長期更新)
- 資料庫收集 - 收藏集 - 掘金資料庫
- 資料庫收集 – 收藏集 – 掘金資料庫
- Python相關資料收集Python
- 資料安全新聞收集(一)
- 大資料3-Flume收集資料+落地HDFS大資料
- Python資料科學(四) 資料收集系列Python資料科學
- 收集資料庫統計資訊需要收集直方圖資訊.資料庫直方圖
- 6 收集資料庫統計資訊資料庫
- 蘋果收集了你的哪些資料?蘋果
- 資料庫分割槽的文章收集資料庫
- oracle的一些資料收集Oracle
- 網上收集的部分java資料Java
- 日常監測分析資料庫的DBA_Monitor.sql程式資料庫SQL
- 【SQL】Oracle資料庫資料量及效能資訊收集SQLOracle資料庫
- 自己收集的部分Angular學習資料Angular
- 大資料01-Flume 日誌收集大資料
- go資料和部落格收集(常看看)Go
- ICI選擇Woolpert收集資料和影像
- 精心收集的Hadoop學習資料Hadoop
- DB2_收集表統計資料DB2
- DB健康檢查使用RDA收集資料
- DIGIDAY:營銷大資料時代,資料收集火熱大資料
- Golang 學習寶庫,各種資料收集Golang
- 【SCRIPT】Oracle資料庫基本資訊收集指令碼Oracle資料庫指令碼
- 收集、分析線上日誌資料實戰——ELK
- 爬蟲資料是如何收集和整理的?爬蟲