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/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- python收集jvm資料PythonJVM
- 038 收集表單資料
- faker 資料填充常用指令收集
- 大資料3-Flume收集資料+落地HDFS大資料
- 6 收集資料庫統計資訊資料庫
- 個人資料收集(長期更新)
- 【SQL】Oracle資料庫資料量及效能資訊收集SQLOracle資料庫
- 自己收集的部分Angular學習資料Angular
- 蘋果收集了你的哪些資料?蘋果
- 大資料01-Flume 日誌收集大資料
- ICI選擇Woolpert收集資料和影像
- go資料和部落格收集(常看看)Go
- 收集 Kubernetes 資源統計資料的新工具
- 【SCRIPT】Oracle資料庫基本資訊收集指令碼Oracle資料庫指令碼
- 2788647047_monitor
- 資訊收集
- 手動收集——收集統計資訊
- 收集、分析線上日誌資料實戰——ELK
- Golang 學習寶庫,各種資料收集Golang
- 爬蟲資料是如何收集和整理的?爬蟲
- 系統日誌及資料庫相關資訊收集資料庫
- 不要讓資料毀了ERP,基礎資料收集8個步驟!
- Postman的Monitor功能Postman
- Verilog 監控 Monitor
- Swoft 資源收集
- 在企業 CRM 中應收集哪些有用資料?
- 用一行Python進行資料收集探索Python
- 爬蟲可以通過代理ip收集哪些資料?爬蟲
- Android無埋點資料收集SDK關鍵技術Android
- 如何用 Python 和 API 收集與分析網路資料?PythonAPI
- Google 要求 Chrome 擴充套件最小化資料收集GoChrome套件
- SQLServer 如何收集資料以排除 SQL 死鎖問題SQLServer
- 如何建立SQL Server分析系統資料收集組BSSQLServer
- 大資料03-整合 Flume 和 Kafka 收集日誌大資料Kafka
- Azure Monitor(二)Log Analytics
- Linux本地資訊收集Linux
- 資訊收集流程
- 資訊收集11——nmap
- 內網資訊收集內網