[monitoring] Centos7 cacti percona apache

Cacti percona apache Monitoring

 

Cacti percona template 을 이용하여 apache24 Web-Server  를 모니터링 할수 있습니다.

 

Mariadb 에서 percona-cacti-templates.version.rpm 을 설치 하였다면 아래 내용은 Skip 합니다.

2017.12.22일 기준

percona-cacti-templates Down 및 설치

[root@centos74 ~]# wget https://www.percona.com/downloads/percona-monitoring-plugins/percona-monitoring-plugins-1.1.7/binary/redhat/7/x86_64/percona-cacti-templates-1.1.7-2.noarch.rpm

[root@centos74 ~]# yum install percona-cacti-templates-1.1.7-2.noarch.rpm

perl-Digest , perl-Digest-MD5 Package 필요합니다.

 

Percona Directory 

/usr/share/cacti/resource/percona
[root@centos74 ~]# ls -al /usr/share/cacti/resource/percona/templates/
total 1896
drwxr-xr-x 2 root root   4096 Dec 22 16:57 .
drwxr-xr-x 6 root root     65 Dec 22 16:57 ..
-rw-r--r-- 1 root root  74554 Dec 10  2016 cacti_host_template_percona_apache_server_ht_0.8.6i-sver1.1.7.xml
-rw-r--r-- 1 root root 104933 Dec 10  2016 cacti_host_template_percona_galera_server_ht_0.8.6i-sver1.1.7.xml
-rw-r--r-- 1 root root 273814 Dec 10  2016 cacti_host_template_percona_gnu_linux_server_ht_0.8.6i-sver1.1.7.xml
-rw-r--r-- 1 root root  54091 Dec 10  2016 cacti_host_template_percona_jmx_server_ht_0.8.6i-sver1.1.7.xml
-rw-r--r-- 1 root root  76166 Dec 10  2016 cacti_host_template_percona_memcached_server_ht_0.8.6i-sver1.1.7.xml
-rw-r--r-- 1 root root  93264 Dec 10  2016 cacti_host_template_percona_mongodb_server_ht_0.8.6i-sver1.1.7.xml
-rw-r--r-- 1 root root 888147 Dec 10  2016 cacti_host_template_percona_mysql_server_ht_0.8.6i-sver1.1.7.xml
-rw-r--r-- 1 root root  42607 Dec 10  2016 cacti_host_template_percona_nginx_server_ht_0.8.6i-sver1.1.7.xml
-rw-r--r-- 1 root root 169753 Dec 10  2016 cacti_host_template_percona_openvz_server_ht_0.8.6i-sver1.1.7.xml
-rw-r--r-- 1 root root  99944 Dec 10  2016 cacti_host_template_percona_rds_server_ht_0.8.6i-sver1.1.7.xml
-rw-r--r-- 1 root root  37873 Dec 10  2016 cacti_host_template_percona_redis_server_ht_0.8.6i-sver1.1.7.xml
[root@centos74 ~]#

 

server-status 설정

[root@centos74 ~]# vi /etc/httpd/conf/httpd.conf

<Location /server-status>
SetHandler server-status
 
Order Deny,Allow
Deny from all
Allow from localhost
</Location>

[root@centos74 ~]# systemctl restart httpd

 

apache server-status 확인

[root@centos74 ~]# curl http://localhost/server-status
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<html><head>
<title>Apache Status</title>
</head><body>
<h1>Apache Server Status for localhost (via ::1)</h1>

<dl><dt>Server Version: Apache/2.4.6 (CentOS) PHP/7.1.12</dt>
<dt>Server MPM: worker</dt>
<dt>Server Built: Oct 19 2017 20:39:16
</dt></dl><hr /><dl>
<dt>Current Time: Saturday, 23-Dec-2017 17:53:02 KST</dt>
<dt>Restart Time: Saturday, 23-Dec-2017 17:34:16 KST</dt>
<dt>Parent Server Config. Generation: 1</dt>
<dt>Parent Server MPM Generation: 0</dt>
<dt>Server uptime:  18 minutes 46 seconds</dt>
<dt>Server load: 0.01 0.02 0.01</dt>
<dt>Total accesses: 20 - Total Traffic: 378 kB</dt>
<dt>CPU Usage: u.27 s.06 cu0 cs0 - .0293% CPU load</dt>
<dt>.0178 requests/sec - 343 B/second - 18.9 kB/request</dt>
<dt>1 requests currently being processed, 223 idle workers</dt>
</dl><pre>________________________________________________________________
_W______________________________________________________________
________________________________................................
................................________________________________
________________________________................................
~중략

curl 을 이용하여 apache server-status 를 확인합니다.

 

Percona Apache 템플릿을 import 합니다.

[root@centos74 ~]# php /usr/share/cacti/cli/import_template.php --filename=/usr/share/cacti/resource/percona/templates/cacti_host_template_percona_apache_server_ht_0.8.6i-sver1.1.7.xml
Read 74554 bytes of XML data
Import ResultsCacti has imported the following items for the Template:
CDEF
[success] Percona Turn Into Bits CDEF [unchanged]
[success] Percona Negate CDEF [unchanged]
GPRINT Preset
[success] Percona Apache Server Checksum c3ed3746e08aa02111016407424dea59 [new]
[success] Percona Apache Server Version t1.1.7:s1.1.7 [new]
[success] Percona Normal [unchanged]
Data Input Method
[success] Percona Get Apache Stats/Apache Requests IM [new]
[success] Percona Get Apache Stats/Apache Bytes IM [new]
[success] Percona Get Apache Stats/Apache CPU Load IM [new]
[success] Percona Get Apache Stats/Apache Workers IM [new]
[success] Percona Get Apache Stats/Apache Scoreboard IM [new]
Data Template
[success] Percona Apache Requests DT [new]
[success] Percona Apache Bytes DT [new]
[success] Percona Apache CPU Load DT [new]
[success] Percona Apache Workers DT [new]
[success] Percona Apache Scoreboard DT [new]
Graph Template
[success] Percona Apache Requests GT [new]
[success] Percona Apache Bytes GT [new]
[success] Percona Apache CPU Load GT [new]
[success] Percona Apache Workers GT [new]
[success] Percona Apache Scoreboard GT [new]
Device Template
[success] Percona Apache Server HT [new]
[root@centos74 ~]#

 

ss_get_by_ssh.php 사용을 위한 .ssh 디렉토리 생성

위치 /usr/share/cacti/.ssh/id_rsa

[root@centos74 cacti]# cd /usr/share/cacti/
[root@centos74 cacti]# mkdir .ssh
[root@centos74 cacti]# chown cacti:cacti .ssh/

ss_get_by_ssh.php 퍼미션변경
[root@centos74 ~]# cd /usr/share/cacti/scripts/
[root@centos74 scripts]# chown cacti:cacti ss_get_by_ssh.php

 

cacti User 의 shell 변경 및 ssh-keygen 생성

[root@centos74 cacti]# chsh cacti
Changing shell for cacti.
New shell [/sbin/nologin]: /bin/bash
Shell changed.
[root@centos74 cacti]# su - cacti
-bash-4.2$ pwd
/usr/share/cacti
-bash-4.2$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/usr/share/cacti/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /usr/share/cacti/.ssh/id_rsa.
Your public key has been saved in /usr/share/cacti/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:zPCJ7lAgw+l+whEHg8QJVsDYka/NDsThFIxMvB//dL8 cacti@centos74
The key's randomart image is:
+---[RSA 2048]----+
|@XO=             |
|=B*+             |
| +Boo .          |
| o+*.. * .       |
| .++o o S        |
| oooo+ . .       |
|  +oo + . .      |
|   o.o .   .     |
|      .    E.    |
+----[SHA256]-----+
-bash-4.2$ cd .ssh/
-bash-4.2$ cat id_rsa.pub >> authorized_keys
-bash-4.2$ chmod 600 authorized_keys

 

ssh-keygen 확인

[root@centos74 scripts]# su - cacti
Last login: Sat Dec 23 17:22:33 KST 2017 on pts/0
-bash-4.2$ ssh localhost
The authenticity of host 'localhost (::1)' can't be established.
ECDSA key fingerprint is SHA256:8Bd7pSELT4CL6EJH/pt7GoxUVSA9K+ggXSMyI0uy67Q.
ECDSA key fingerprint is MD5:cb:85:04:a0:75:5c:e2:40:b6:a0:a1:73:c2:0c:1a:44.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'localhost' (ECDSA) to the list of known hosts.
Last login: Sat Dec 23 17:25:51 2017
-bash-4.2$ logout
Connection to localhost closed.
-bash-4.2$

(cacti 유저로 변경후 정상적으로 password 없이 로그인 할수 있는지 확인 합니다.)

 

ss_get_by_ssh.php 스크립트 테스트

-bash-4.2$ php /usr/share/cacti/scripts/ss_get_by_ssh.php --type apache --host 127.0.0.1 --items gg,gh
gg:1 gh:8192
-bash-4.2$

비정상일 경우 gg:-1 , gh: -1 로 값이 표기 됩니다.

 

cacti 설정

Templates -> Data Source 에서 apache 템플릿을 검색 합니다.

 

Percona Apache Template 를 수정 합니다. 아래와 같이 Custom Data 부분의 Hostname 부분을 localhost 로 변경 하면 됩니다.

 

Management -> Devices 로 이동후 새로운 Device 를 추가 합니다.

+ 버튼을 클릭하면 새로운 Device 를 추가 할수 있습니다.

 

새로운 Device 를 아래와 같이 추가 합니다.

Description : Web-Server

Hostname : ip 또는 hostname

Device Template : Percona Apache Server HT

Create 버튼을 클릭하여 설정을 저장 합니다.

 

화면상단의 Create Graphs for this Device 버튼을 클릭하여 그래프를 생성 합니다.

 

모니터링을 진행할 템플릿을 선택 합니다. Test 를 위하여 전부다 선택 하였습니다. 🙂

Create 버튼을 클릭하여 템플릿을 생성 합니다.

 

Graphs -> List View 로 이동 합니다.  새로 추가한 Web-Server Device 를 확인 할수 있습니다.

모니터링할 템플릿을 선택후 View 버튼을 클릭합니다.

 

Preview 로 이동후 Device 항목에서 Web-Server 를 선택 합니다.

최초 그래프 생성시까지 약 5~10 분 정도 시간이 소요 됩니다.

 

수고하셨습니다. 이상으로 모든 설정이 완료 되었습니다. 🙂

 

약 5~10분 정도 지나면 아래와 같은 그래프를 확인 할수 있습니다.

 

댓글 남기기