一、ganglia簡介php
Ganglia 是一款爲 HPC(高性能計算)集羣而設計的可擴展的分佈式監控系統,它能夠html
監視和顯示集羣中的節點的各類狀態信息,它由運行在各個節點上的 gmond 守護進程來採python
集 CPU 、內存、硬盤利用率、 I/O 負載、網絡流量狀況等方面的數據,而後彙總到 gmetadmysql
守護進程下,使用 rrdtool 存儲數據,最後將歷史數據以曲線方式經過 PHP 頁面呈現。nginx
Ganglia 的特色以下:web
良好的擴展性,分層架構設計可以適應大規模服務器集羣的須要sql
負載開銷低,支持高併發數據庫
普遍支持各類操做系統( UNIX 等)和 cpu 架構,支持虛擬vim
二、ganglia組成
centos
Ganglia 監控系統有三部分組成,分別是 gmond、 gmetad、 webfrontend,做用以下。
gmond: 即爲 ganglia monitoring daemon,是一個守護進程,運行在每個須要監測
的節點上,用於收集本節點的信息併發送到其餘節點,同時也接收其餘節點發過了
的數據,默認的監聽端口爲 8649。
gmetad: 即爲 ganglia meta daemon,是一個守護進程,運行在一個數據匯聚節點上,
按期檢查每一個監測節點的 gmond 進程並從那裏獲取數據,而後將數據指標存儲在
本地 RRD 存儲引擎中。
webfrontend: 是一個基於 web 的圖形化監控界面,須要和 Gmetad 安裝在同一個節
點上,它從 gmetad 取數據,而且讀取 RRD 數據庫,經過 rrdtool 生成圖表,用於
前臺展現,界面美觀、豐富,功能強大。下圖是其結構
環境規劃(centos6.7)
服務器端 172.16.80.117
客戶端 172.16.80.117 172.16.80.116
三、ganglia的安裝
[root@centos02 tools]# wget wget [root@centos02 tools]# rpm -ivh epel-release-6-8.noarch.rpm [root@centos02 tools]# yum install ganglia-gmetad.x86_64 ganglia-gmond.x86_64 ganglia-gmond-python.x86_64 -y 修改服務端配置文件 [root@centos02 tools]# vim /etc/ganglia/gmetad.conf data_source "my cluster" 172.16.80.117 172.16.80.116 gridname "MyGrid" ganglia web的安裝(基於LNMP環境) [root@centos02 tools]# tar xf ganglia-web-3.7.2.tar.gz [root@centos02 tools]# mv ganglia-web-3.7.2 /application/nginx/html/ganglia 修改ganglia web的php配置文件 [root@centos02 tools]# vim /application/nginx/html/ganglia/conf_default.php $conf['gweb_confdir'] = "/application/nginx/html/ganglia"; nginx配置 [root@centos02 ganglia]# cat /application/nginx/conf/nginx.conf worker_processes 2; events { worker_connections 1024; } http { log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; server { listen 80; server_name www.martin.com martin.com; location / { root html/zabbix; index index.php index.html index.htm; } location ~ .*\.(php|php5)?$ { root html/zabbix; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; include fastcgi.conf; } access_log logs/access_zabbix.log main; } server { listen 80; server_name ganglia.martin.com; location / { root html/ganglia; index index.php index.html index.htm; } location ~ .*\.(php|php5)?$ { root html/ganglia; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; include fastcgi.conf; } access_log logs/access_bbs.log main; } ###status server{ listen 80; server_name status.martin.org; location / { stub_status on; access_log off; } } } 訪問測試,報錯以下 Fatal error:Errors were detected in your configuration. DWOO compiled templates directory '/application/nginx/html/ganglia/dwoo/compiled' is not writeable. Please adjust $conf['dwoo_compiled_dir']. DWOO cache directory '/application/nginx/html/ganglia/dwoo/cache' is not writeable. Please adjust $conf['dwoo_cache_dir']. in /application/nginx-1.6.3/html/ganglia/eval_conf.php on line 126 解決辦法: [root@centos02 tools]# mkdir /application/nginx/html/ganglia/dwoo/compiled [root@centos02 tools]# mkdir /application/nginx/html/ganglia/dwoo/cache [root@centos02 tools]# chmod 777 /application/nginx/html/ganglia/dwoo/compiled [root@centos02 tools]# chmod 777 /application/nginx/html/ganglia/dwoo/cache [root@centos02 html]# chmod -R 777 /var/lib/ganglia/rrds 修改客戶端配置文件(全部的客戶端都須要作) [root@centos02 tools]# vim /etc/ganglia/gmond.conf cluster { name = "my cluster" #這個名字要和服務器端定義的data_source後面的名字同樣 owner = "unspecified" latlong = "unspecified" url = "unspecified" } udp_send_channel { #bind_hostname = yes # Highly recommended, soon to be default. # This option tells gmond to use a source address # that resolves to the machine's hostname. Without # this, the metrics may appear to come from any # interface and the DNS names associated with # those IPs will be used to create the RRDs. # mcast_join = 239.2.11.71 host = 172.16.80.117 #這裏咱們採用單播方式,默認是組播 port = 8649 # ttl = 1 } udp_recv_channel { # mcast_join = 239.2.11.71 port = 8649 # bind = 239.2.11.71 retry_bind = true # Size of the UDP buffer. If you are handling lots of metrics you really # should bump it up to e.g. 10MB or even higher. # buffer = 10485760 }
四、再次訪問測試
這裏是整個集羣的一個總的彙總圖,而不是單臺服務器的圖,下面咱們打開單臺服務器的圖看看
再來看看對同一指標,每臺服務器一塊兒顯示的圖
五、擴展 Ganglia 監控功能的方法
默認安裝完成的 Ganglia 僅向咱們提供基礎的系統監控信息,經過 Ganglia 插件能夠實
現兩種擴展 Ganglia 監控功能的方法。
1) 添加帶內( in-band)插件,主要是經過 gmetric 命令來實現。
這是一般使用的一種方法,主要是經過 crontab 方法並調用 Ganglia 的 gmetric 命令來向
gmond 輸入數據,進而實現統一監控。這種方法簡單,對於少許的監控能夠採用,可是對
於大規模自定義監控時,監控數據難以統一管理。
2) 添加一些其餘來源的帶外( out-of-band)插件,主要是經過 C 或者 Python 接口來
實現。
在 Ganglia3.1.x 版本之後,增長了 C 或 Python 接口,經過這個接口能夠自定義數據收集
模塊,而且能夠將這些模塊直接插入到 gmond 中以監控用戶自定義的應用。
這裏咱們舉例經過帶外擴展的方式 來監控nginx的運行狀態
配置 ganglia 客戶端,收集 nginx_status 數據 [root@centos02 nginx_status]# pwd /tools/gmond_python_modules-master/nginx_status [root@centos02 nginx_status]# cp conf.d/nginx_status.pyconf /etc/ganglia/conf.d/ [root@centos02 nginx_status]# cp python_modules/nginx_status.py /usr/lib64/ganglia/python_modules/ [root@centos02 nginx_status]# cp graph.d/nginx_* /application/nginx/html/ganglia/graph.d/ [root@centos02 mysql]# cat /etc/ganglia/conf.d/nginx_status.pyconf # modules { module { name = 'nginx_status' language = 'python' param status_url { value = 'http://status.martin.org/' } param nginx_bin { value = '/application/nginx/sbin/nginx' } param refresh_rate { value = '15' } } } collection_group { collect_once = yes time_threshold = 20 metric { name = 'nginx_server_version' title = "Nginx Version" } } collection_group { collect_every = 10 time_threshold = 20 metric { name = "nginx_active_connections" title = "Total Active Connections" value_threshold = 1.0 } metric { name = "nginx_accepts" title = "Total Connections Accepted" value_threshold = 1.0 } metric { name = "nginx_handled" title = "Total Connections Handled" value_threshold = 1.0 } metric { name = "nginx_requests" title = "Total Requests" value_threshold = 1.0 } metric { name = "nginx_reading" title = "Connections Reading" value_threshold = 1.0 } metric { name = "nginx_writing" title = "Connections Writing" value_threshold = 1.0 } metric { name = "nginx_waiting" title = "Connections Waiting" value_threshold = 1.0 } }
完成上面的全部步驟後,重啓 Ganglia 客戶端 gmond 服務,在客戶端經過「 gmond–m」
命令能夠查看支持的模板,最後就能夠在 Ganglia web 界面查看 Nginx 的運行狀態