運維監控-Open-Falcon安裝Agent實戰篇

              運維監控-Open-Falcon安裝Agent實戰篇
css

                                       做者:尹正傑 html

版權聲明:原創做品,謝絕轉載!不然將追究法律責任。前端

 

  本文參考連接來自:http://book.open-falcon.org/zh/install_from_src/agent.html node

 

一.介紹jquery

  agent用於採集機器負載監控指標,好比cpu.idle、load.1min、disk.io.util等等,每隔60秒push給Transfer。agent與Transfer創建了長鏈接,數據發送速度比較快,agent提供了一個http接口/v1/push用於接收用戶手工push的一些數據,而後經過長鏈接迅速轉發給Transfer。git

 

二.部署github

  agent須要部署到全部要被監控的機器上,好比公司有10萬臺機器,那就要部署10萬個agent。agent自己資源消耗不多,不用擔憂。web

1>.部署環境json

 

2>.拷貝agent工具包到須要安裝的服務器上bootstrap

[root@node101 ~]# cd /yinzhengjie/open-falcon/workspace/open-falcon
[root@node101 open-falcon]# 
[root@node101 open-falcon]# ll
total 3896
drwxrwxr-x. 7  501  501      72 Aug 15  2017 agent
drwxrwxr-x. 5  501  501      43 Aug 15  2017 aggregator
drwxrwxr-x. 5  501  501      43 Aug 15  2017 alarm
drwxrwxr-x. 6  501  501      55 Aug 15  2017 api
drwxr-xr-x. 3 root root      18 Dec 11 17:33 data
drwxrwxr-x. 5  501  501      43 Aug 15  2017 gateway
drwxrwxr-x. 6  501  501      55 Aug 15  2017 graph
drwxrwxr-x. 5  501  501      43 Aug 15  2017 hbs
drwxrwxr-x. 5  501  501      43 Aug 15  2017 judge
drwxrwxr-x. 5  501  501      43 Aug 15  2017 nodata
-rwxrwxr-x. 1  501  501 3987469 Aug 15  2017 open-falcon
lrwxrwxrwx. 1  501  501      16 Aug 15  2017 plugins -> ./agent/plugins/
lrwxrwxrwx. 1  501  501      15 Aug 15  2017 public -> ./agent/public/
drwxrwxr-x. 5  501  501      43 Aug 15  2017 transfer
[root@node101 open-falcon]# 
[root@node101 ~]# cd /yinzhengjie/open-falcon/workspace/open-falcon            #進入到「node101.yinzhengjie.org.cn」的open-Falcon安裝目錄
[root@node101 open-falcon]# scp -r agent/ root@node102.yinzhengjie.org.cn:~
The authenticity of host 'node102.yinzhengjie.org.cn (172.30.1.102)' can't be established.
ECDSA key fingerprint is SHA256:aGk7Wv77uRVAElcihCH0Zu0sAPp6qEs2sSA1Zsj3o7g.
ECDSA key fingerprint is MD5:2b:74:b8:ad:f8:92:78:04:38:90:f1:28:e7:70:68:fb.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'node102.yinzhengjie.org.cn,172.30.1.102' (ECDSA) to the list of known hosts.
root@node102.yinzhengjie.org.cn's password: 
agent.log                                                                                                                                           100%   41KB 520.6KB/s   00:00    
scheduler.go                                                                                                                                        100% 2479   156.5KB/s   00:00    
reader.go                                                                                                                                           100% 1011   298.4KB/s   00:00    
plugins.go                                                                                                                                          100%  970    61.9KB/s   00:00    
odometer.js                                                                                                                                         100% 7564   192.3KB/s   00:00    
jquery.dataTables.min.js                                                                                                                            100%   69KB   2.9MB/s   00:00    
jquery.js                                                                                                                                           100%   93KB   2.3MB/s   00:00    
jquery-ui.min.js                                                                                                                                    100%  223KB  17.5MB/s   00:00    
dashboard.js                                                                                                                                        100% 7975     2.4MB/s   00:00    
bootstrap.js                                                                                                                                        100%   47KB   8.2MB/s   00:00    
base.js                                                                                                                                             100% 2220   934.5KB/s   00:00    
code.png                                                                                                                                            100%  540    37.9KB/s   00:00    
favicon.ico                                                                                                                                         100%   97KB  18.5MB/s   00:00    
font-awesome.min.css                                                                                                                                100%   22KB   1.0MB/s   00:00    
font-awesome-ie7.min.css                                                                                                                            100%   37KB  10.5MB/s   00:00    
font-awesome-ie7.css                                                                                                                                100%   40KB   5.7MB/s   00:00    
font-awesome.css                                                                                                                                    100%   27KB  12.8MB/s   00:00    
fontawesome-webfont.eot                                                                                                                             100%   37KB 969.0KB/s   00:00    
FontAwesome.otf                                                                                                                                     100%   60KB  12.9MB/s   00:00    
fontawesome-webfont.woff                                                                                                                            100%   43KB  11.5MB/s   00:00    
fontawesome-webfont.svg                                                                                                                             100%  193KB  13.5MB/s   00:00    
fontawesome-webfont.ttf                                                                                                                             100%   77KB   6.9MB/s   00:00    
odometer.css                                                                                                                                        100% 3849     1.8MB/s   00:00    
dashboard.css                                                                                                                                       100% 5150   206.1KB/s   00:00    
bootstrap-responsive.min.css                                                                                                                        100% 9149   500.0KB/s   00:00    
OpenSans-Regular-webfont.woff                                                                                                                       100%   83KB   5.1MB/s   00:00    
OpenSans-Regular-webfont.eot                                                                                                                        100%   71KB   3.4MB/s   00:00    
OpenSans-Regular-webfont.svg                                                                                                                        100%  266KB   6.5MB/s   00:00    
OpenSans-Regular-webfont.ttf                                                                                                                        100%  160KB   9.9MB/s   00:00    
style.css                                                                                                                                           100%   23KB   7.8MB/s   00:00    
bootstrap.min.css                                                                                                                                   100%   88KB  20.3MB/s   00:00    
g.css                                                                                                                                               100% 2637   175.5KB/s   00:00    
index.html                                                                                                                                          100%   15KB  10.1MB/s   00:00    
falcon-agent                                                                                                                                        100% 9849KB  37.1MB/s   00:00    
cfg.json                                                                                                                                            100% 1254    79.8KB/s   00:00    
[root@node101 open-falcon]# 
[root@node101 open-falcon]# scp -r agent/ root@node102.yinzhengjie.org.cn:~        #拷貝agent目錄到須要監控的"node102.yinzhengjie.org.cn"服務器上
[root@node101 open-falcon]# scp -r agent/ root@node103.yinzhengjie.org.cn:~
The authenticity of host 'node103.yinzhengjie.org.cn (172.30.1.103)' can't be established.
ECDSA key fingerprint is SHA256:aGk7Wv77uRVAElcihCH0Zu0sAPp6qEs2sSA1Zsj3o7g.
ECDSA key fingerprint is MD5:2b:74:b8:ad:f8:92:78:04:38:90:f1:28:e7:70:68:fb.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'node103.yinzhengjie.org.cn,172.30.1.103' (ECDSA) to the list of known hosts.
root@node103.yinzhengjie.org.cn's password: 
agent.log                                                                                                                                           100%   47KB   2.1MB/s   00:00    
scheduler.go                                                                                                                                        100% 2479     3.1MB/s   00:00    
reader.go                                                                                                                                           100% 1011     1.7MB/s   00:00    
plugins.go                                                                                                                                          100%  970     1.5MB/s   00:00    
odometer.js                                                                                                                                         100% 7564   408.0KB/s   00:00    
jquery.dataTables.min.js                                                                                                                            100%   69KB   3.0MB/s   00:00    
jquery.js                                                                                                                                           100%   93KB  24.0MB/s   00:00    
jquery-ui.min.js                                                                                                                                    100%  223KB  13.4MB/s   00:00    
dashboard.js                                                                                                                                        100% 7975     5.9MB/s   00:00    
bootstrap.js                                                                                                                                        100%   47KB  32.1MB/s   00:00    
base.js                                                                                                                                             100% 2220     1.2MB/s   00:00    
code.png                                                                                                                                            100%  540   786.0KB/s   00:00    
favicon.ico                                                                                                                                         100%   97KB  29.9MB/s   00:00    
font-awesome.min.css                                                                                                                                100%   22KB  21.8MB/s   00:00    
font-awesome-ie7.min.css                                                                                                                            100%   37KB  12.2MB/s   00:00    
font-awesome-ie7.css                                                                                                                                100%   40KB  15.6MB/s   00:00    
font-awesome.css                                                                                                                                    100%   27KB   8.6MB/s   00:00    
fontawesome-webfont.eot                                                                                                                             100%   37KB   1.7MB/s   00:00    
FontAwesome.otf                                                                                                                                     100%   60KB  18.6MB/s   00:00    
fontawesome-webfont.woff                                                                                                                            100%   43KB  13.8MB/s   00:00    
fontawesome-webfont.svg                                                                                                                             100%  193KB  23.1MB/s   00:00    
fontawesome-webfont.ttf                                                                                                                             100%   77KB   3.4MB/s   00:00    
odometer.css                                                                                                                                        100% 3849     2.1MB/s   00:00    
dashboard.css                                                                                                                                       100% 5150     5.3MB/s   00:00    
bootstrap-responsive.min.css                                                                                                                        100% 9149     8.9MB/s   00:00    
OpenSans-Regular-webfont.woff                                                                                                                       100%   83KB  17.9MB/s   00:00    
OpenSans-Regular-webfont.eot                                                                                                                        100%   71KB  25.4MB/s   00:00    
OpenSans-Regular-webfont.svg                                                                                                                        100%  266KB  30.4MB/s   00:00    
OpenSans-Regular-webfont.ttf                                                                                                                        100%  160KB   6.1MB/s   00:00    
style.css                                                                                                                                           100%   23KB   8.9MB/s   00:00    
bootstrap.min.css                                                                                                                                   100%   88KB  24.3MB/s   00:00    
g.css                                                                                                                                               100% 2637     3.0MB/s   00:00    
index.html                                                                                                                                          100%   15KB  17.0MB/s   00:00    
falcon-agent                                                                                                                                        100% 9849KB  37.5MB/s   00:00    
cfg.json                                                                                                                                            100% 1254   394.1KB/s   00:00    
[root@node101 open-falcon]# 
[root@node101 open-falcon]# scp -r agent/ root@node103.yinzhengjie.org.cn:~        #拷貝agent目錄到須要監控的"node103.yinzhengjie.org.cn"服務器上
[root@node101 open-falcon]# scp open-falcon root@node102.yinzhengjie.org.cn:~
root@node102.yinzhengjie.org.cn's password: 
open-falcon                                                                                                                                         100% 3894KB  34.9MB/s   00:00    
[root@node101 open-falcon]# 
[root@node101 open-falcon]# scp open-falcon root@node102.yinzhengjie.org.cn:~      #拷貝open-falcon腳本到須要監控的服務器上面
[root@node101 open-falcon]# scp open-falcon root@node103.yinzhengjie.org.cn:~
root@node103.yinzhengjie.org.cn's password: 
open-falcon                                                                                                                                         100% 3894KB  56.7MB/s   00:00    
[root@node101 open-falcon]# 
[root@node101 open-falcon]# scp open-falcon root@node103.yinzhengjie.org.cn:~      #拷貝open-falcon腳本到須要監控的服務器上面

3>.修改node102.yinzhengjie.org.cn的cfg.json配置文件並啓動agent

[root@node102 ~]# ll
total 3896
drwxrwxr-x. 7 root root      72 Dec 12 10:57 agent
-rwxr-xr-x. 1 root root 3987469 Dec 12 11:04 open-falcon
[root@node102 ~]# 
[root@node102 ~]# cat agent/config/cfg.json 
{
    "debug": true,
    "hostname": "node102.yinzhengjie.org.cn",
    "ip": "",
    "plugin": {
        "enabled": false,
        "dir": "./plugin",
        "git": "https://github.com/open-falcon/plugin.git",
        "logs": "./logs"
    },
    "heartbeat": {
        "enabled": true,
        "addr": "node101.yinzhengjie.org.cn:6030",
        "interval": 60,
        "timeout": 1000
    },
    "transfer": {
        "enabled": true,
        "addrs": [
            "node101.yinzhengjie.org.cn:8433"
        ],
        "interval": 60,
        "timeout": 1000
    },
    "http": {
        "enabled": true,
        "listen": ":1988",
        "backdoor": false
    },
    "collector": {
        "ifacePrefix": ["eth", "em"],
        "mountPoint": []
    },
    "default_tags": {
    },
    "ignore": {
        "cpu.busy": true,
        "df.bytes.free": true,
        "df.bytes.total": true,
        "df.bytes.used": true,
        "df.bytes.used.percent": true,
        "df.inodes.total": true,
        "df.inodes.free": true,
        "df.inodes.used": true,
        "df.inodes.used.percent": true,
        "mem.memtotal": true,
        "mem.memused": true,
        "mem.memused.percent": true,
        "mem.memfree": true,
        "mem.swaptotal": true,
        "mem.swapused": true,
        "mem.swapfree": true
    }
}
[root@node102 ~]# 
{
    "debug": true, # 控制一些debug信息的輸出,生產環境一般設置爲false
    "hostname": "", # agent採集了數據發給transfer,endpoint就設置爲了hostname,默認經過`hostname`獲取,若是配置中配置了hostname,就用配置中的
    "ip": "", # agent與hbs心跳的時候會把本身的ip地址發給hbs,agent會自動探測本機ip,若是不想讓agent自動探測,能夠手工修改該配置
    "plugin": {
        "enabled": false, # 默認不開啓插件機制
        "dir": "./plugin", # 把放置插件腳本的git repo clone到這個目錄
        "git": "https://github.com/open-falcon/plugin.git", # 放置插件腳本的git repo地址
        "logs": "./logs" # 插件執行的log,若是插件執行有問題,能夠去這個目錄看log
    },
    "heartbeat": {
        "enabled": true, # 此處enabled要設置爲true
        "addr": "127.0.0.1:6030", # hbs的地址,端口是hbs的rpc端口
        "interval": 60, # 心跳週期,單位是秒
        "timeout": 1000 # 鏈接hbs的超時時間,單位是毫秒
    },
    "transfer": {
        "enabled": true, # 此處enabled要設置爲true
        "addrs": [
            "127.0.0.1:8433",
            "127.0.0.1:8433"
        ], # transfer的地址,端口是transfer的rpc端口, 能夠支持寫多個transfer的地址,agent會保證HA
        "interval": 60, # 採集週期,單位是秒,即agent一分鐘採集一次數據發給transfer
        "timeout": 1000 # 鏈接transfer的超時時間,單位是毫秒
    },
    "http": {
        "enabled": true, # 是否要監聽http端口
        "listen": ":1988" # 若是監聽的話,監聽的地址
    },
    "collector": {
        "ifacePrefix": ["eth", "em"] # 默認配置只會採集網卡名稱前綴是eth、em的網卡流量,配置爲空就會採集全部的,lo的也會採集。能夠從/proc/net/dev看到各個網卡的流量信息
    },
    "ignore": { # 默認採集了200多個metric,能夠經過ignore設置爲不採集
        "cpu.busy": true,
        "mem.swapfree": true
    }
}
配置文件必須叫cfg.json,能夠基於cfg.example.json修改(想要了解上述配置參數說明戳我)
./open-falcon start agent  啓動進程
./open-falcon stop agent  中止進程
./open-falcon monitor agent  查看日誌
看var目錄下的log是否正常,或者瀏覽器訪問其1988端口。另外agent提供了一個--check參數,能夠檢查agent是否能夠正常跑在當前機器上
./falcon-agent --check

4>.修改node103.yinzhengjie.org.cn的cfg.json配置文件並啓動agent

[root@node103 ~]# ll
total 3896
drwxrwxr-x. 7 root root      72 Dec 12 11:02 agent
-rwxr-xr-x. 1 root root 3987469 Dec 12 11:04 open-falcon
[root@node103 ~]# 
[root@node103 ~]# cat agent/config/cfg.json 
{
    "debug": true,
    "hostname": "node103.yinzhengjie.org.cn",
    "ip": "",
    "plugin": {
        "enabled": false,
        "dir": "./plugin",
        "git": "https://github.com/open-falcon/plugin.git",
        "logs": "./logs"
    },
    "heartbeat": {
        "enabled": true,
        "addr": "node101.yinzhengjie.org.cn:6030",
        "interval": 60,
        "timeout": 1000
    },
    "transfer": {
        "enabled": true,
        "addrs": [
            "node101.yinzhengjie.org.cn:8433"
        ],
        "interval": 60,
        "timeout": 1000
    },
    "http": {
        "enabled": true,
        "listen": ":1988",
        "backdoor": false
    },
    "collector": {
        "ifacePrefix": ["eth", "em"],
        "mountPoint": []
    },
    "default_tags": {
    },
    "ignore": {
        "cpu.busy": true,
        "df.bytes.free": true,
        "df.bytes.total": true,
        "df.bytes.used": true,
        "df.bytes.used.percent": true,
        "df.inodes.total": true,
        "df.inodes.free": true,
        "df.inodes.used": true,
        "df.inodes.used.percent": true,
        "mem.memtotal": true,
        "mem.memused": true,
        "mem.memused.percent": true,
        "mem.memfree": true,
        "mem.swaptotal": true,
        "mem.swapused": true,
        "mem.swapfree": true
    }
}
[root@node103 ~]# 
[root@node103 ~]# ./open-falcon start agent
[falcon-agent] 8639
[root@node103 ~]# .
[root@node103 ~]# ./open-falcon start agent            #在node103.yinzhengjie.org.cn節點上啓動agent
[root@node103 ~]# ./open-falcon monitor agent 
2018/12/12 11:01:48 var.go:95: <= <Total=7, Invalid:0, Latency=0ms, Message:ok>
2018/12/12 11:01:48 var.go:88: => <Total=6> <Endpoint:node101.yinzhengjie.org.cn, Metric:ss.estab, Type:GAUGE, Tags:, Step:60, Time:1544630508, Value:53>
2018/12/12 11:01:48 var.go:95: <= <Total=68, Invalid:0, Latency=0ms, Message:ok>
2018/12/12 11:01:48 var.go:95: <= <Total=6, Invalid:0, Latency=0ms, Message:ok>
2018/12/12 11:02:00 var.go:88: => <Total=4> <Endpoint:node101.yinzhengjie.org.cn, Metric:rate, Type:GAUGE, Tags:name=pfc.push.cnt, Step:60, Time:1544630520, Value:0.016666781240232065>
2018/12/12 11:02:00 var.go:88: => <Total=5> <Endpoint:node101.yinzhengjie.org.cn, Metric:rate, Type:GAUGE, Tags:name=pfc.push.cnt, Step:60, Time:1544630520, Value:0.01666669039142266>
2018/12/12 11:02:00 var.go:95: <= <Total=4, Invalid:0, Latency=0ms, Message:ok>
2018/12/12 11:02:00 var.go:95: <= <Total=5, Invalid:0, Latency=0ms, Message:ok>
2018/12/12 11:18:07 cfg.go:128: read config file: /root/agent/config/cfg.json successfully
2018/12/12 11:18:07 http.go:74: listening :1988
2018/12/12 11:19:07 var.go:88: => <Total=7> <Endpoint:node101.yinzhengjie.org.cn, Metric:df.bytes.free.percent, Type:GAUGE, Tags:mount=/,fstype=xfs, Step:60, Time:1544631547, Value:97.8937870429458>
2018/12/12 11:19:07 var.go:88: => <Total=68> <Endpoint:node101.yinzhengjie.org.cn, Metric:agent.alive, Type:GAUGE, Tags:, Step:60, Time:1544631547, Value:1>
2018/12/12 11:19:07 var.go:95: <= <Total=7, Invalid:0, Latency=0ms, Message:ok>
2018/12/12 11:19:07 var.go:95: <= <Total=68, Invalid:0, Latency=0ms, Message:ok>
2018/12/12 11:19:07 var.go:88: => <Total=6> <Endpoint:node101.yinzhengjie.org.cn, Metric:ss.estab, Type:GAUGE, Tags:, Step:60, Time:1544631547, Value:3>
2018/12/12 11:19:07 var.go:95: <= <Total=6, Invalid:0, Latency=0ms, Message:ok>
[root@node103 ~]# ./open-falcon monitor agent          #查看agent端的日誌信息

 

三.在open-falcon中的前端界面查看是否有對應的主機列表

1>.刷新前端頁面,會看到2臺監控的主機信息,以下圖所示:

 

2>.以Endpoint視角查看agent採集的監控項目

3>.點擊後可查看到的視圖信息以下:

相關文章
相關標籤/搜索