open falcon agent 安装

写在前面的话

每篇一句

爱人者人恒爱之,敬人者人恒敬之。

agent 安装

go 安装(同类操作系统只需第一台编译好agent包,其他机器不必安装go)

1
2
3
cd /data/
wget https://redirector.gvt1.com/edgedl/go/go1.9.2.linux-amd64.tar.gz
tar -C /usr/local -xzf go1.9.2.linux-amd64.tar.gz

/root/.bashrc 文件增加go环境变量配置,针对root用户配置环境变量。如果想所有用户使用可追加在/etc/profile。

1
2
3
export GOROOT=/usr/local/go
export GOPATH=/data/mygoworkspace
export PATH=$PATH:$GOROOT/bin:$GOPATH/bin

使环境变量立即生效

1
source /root/.bashrc

验证

1
2
root@ubuntu:/data/open-falcon# go version
go version go1.9.2 linux/amd64

查看所有go 环境变量可使用go env

agent 编译

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
root@ubuntu:/data/mygoworkspace# mkdir -p $GOPATH/src/github.com/open-falcon
root@ubuntu:/data/mygoworkspace# cd $GOPATH/src/github.com/open-falcon
root@ubuntu:/data/mygoworkspace/src/github.com/open-falcon# git clone https://github.com/open-falcon/falcon-plus.git
Cloning into 'falcon-plus'...
remote: Counting objects: 7990, done.
remote: Compressing objects: 100% (33/33), done.
remote: Total 7990 (delta 7), reused 18 (delta 6), pack-reused 7950
Receiving objects: 100% (7990/7990), 15.43 MiB | 202.00 KiB/s, done.
Resolving deltas: 100% (4110/4110), done.
Checking connectivity... done.
root@ubuntu:/data/mygoworkspace/src/github.com/open-falcon# cd $GOPATH/src/github.com/open-falcon/falcon-plus/
root@ubuntu:/data/mygoworkspace/src/github.com/open-falcon/falcon-plus# make agent
go build -o bin/agent/falcon-agent ./modules/agent
root@ubuntu:/data/mygoworkspace/src/github.com/open-falcon/falcon-plus/modules# cd agent/
root@ubuntu:/data/mygoworkspace/src/github.com/open-falcon/falcon-plus/modules/agent# ll
total 68
drwxr-xr-x 8 root root 4096 Dec 3 16:41 ./
drwxr-xr-x 12 root root 4096 Dec 3 16:41 ../
-rw-r--r-- 1 root root 1288 Dec 3 16:41 cfg.example.json
-rwxr-xr-x 1 root root 2291 Dec 3 16:41 control*
drwxr-xr-x 2 root root 4096 Dec 3 16:41 cron/
drwxr-xr-x 2 root root 4096 Dec 3 16:41 funcs/
drwxr-xr-x 2 root root 4096 Dec 3 16:41 g/
-rw-r--r-- 1 root root 99 Dec 3 16:41 .gitignore
drwxr-xr-x 2 root root 4096 Dec 3 16:41 http/
-rw-r--r-- 1 root root 11358 Dec 3 16:41 LICENSE
-rw-r--r-- 1 root root 1527 Dec 3 16:41 main.go
-rw-r--r-- 1 root root 462 Dec 3 16:41 NOTICE
drwxr-xr-x 2 root root 4096 Dec 3 16:41 plugins/
drwxr-xr-x 5 root root 4096 Dec 3 16:41 public/
-rw-r--r-- 1 root root 698 Dec 3 16:41 README.md
root@ubuntu:/data/mygoworkspace/src/github.com/open-falcon/falcon-plus/modules/agent# ./control build
5.1.2
root@ubuntu:/data/mygoworkspace/src/github.com/open-falcon/falcon-plus/modules/agent# ./control pack
5.1.2
...tar falcon-agent-5.1.2.tar.gz <= public control cfg.example.json falcon-agent
root@ubuntu:/data/mygoworkspace/src/github.com/open-falcon/falcon-plus/modules/agent# ll
total 13744
drwxr-xr-x 9 root root 4096 Dec 3 16:46 ./
drwxr-xr-x 12 root root 4096 Dec 3 16:41 ../
-rw-r--r-- 1 root root 1288 Dec 3 16:41 cfg.example.json
-rwxr-xr-x 1 root root 2291 Dec 3 16:41 control*
drwxr-xr-x 2 root root 4096 Dec 3 16:41 cron/
-rwxr-xr-x 1 root root 9900773 Dec 3 16:46 falcon-agent*
-rw-r--r-- 1 root root 4090171 Dec 3 16:46 falcon-agent-5.1.2.tar.gz
drwxr-xr-x 2 root root 4096 Dec 3 16:41 funcs/
drwxr-xr-x 2 root root 4096 Dec 3 16:41 g/
-rw-r--r-- 1 root root 99 Dec 3 16:41 .gitignore
-rw-r--r-- 1 root root 8 Dec 3 16:46 gitversion
drwxr-xr-x 2 root root 4096 Dec 3 16:41 http/
-rw-r--r-- 1 root root 11358 Dec 3 16:41 LICENSE
-rw-r--r-- 1 root root 1527 Dec 3 16:41 main.go
-rw-r--r-- 1 root root 462 Dec 3 16:41 NOTICE
drwxr-xr-x 2 root root 4096 Dec 3 16:41 plugins/
drwxr-xr-x 5 root root 4096 Dec 3 16:41 public/
-rw-r--r-- 1 root root 698 Dec 3 16:41 README.md
drwxr-xr-x 2 root root 4096 Dec 3 16:46 var/

安装agent 修改配置文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
root@ubuntu:/data/open-falcon# pwd
/data/open-falcon
root@ubuntu:/data/open-falcon# cp /data/mygoworkspace/src/github.com/open-falcon/falcon-plus/modules/agent/falcon-agent-5.1.2.tar.gz ./
root@ubuntu:/data/open-falcon# ll
total 4004
drwxr-xr-x 2 root root 4096 Dec 3 16:49 ./
drw------- 9 root root 4096 Dec 3 14:08 ../
-rw-r--r-- 1 root root 4090171 Dec 3 16:49 falcon-agent-5.1.2.tar.gz
root@ubuntu:/data/open-falcon# tar -xzvf falcon-agent-5.1.2.tar.gz
root@ubuntu:/data/open-falcon# ll
total 13700
drwxr-xr-x 4 root root 4096 Dec 3 16:50 ./
drw------- 9 root root 4096 Dec 3 14:08 ../
-rw-r--r-- 1 root root 1288 Dec 3 16:41 cfg.example.json
-rw-r--r-- 1 root root 1266 Dec 3 16:49 cfg.json
-rwxr-xr-x 1 root root 2291 Dec 3 16:41 control*
-rwxr-xr-x 1 root root 9900773 Dec 3 16:46 falcon-agent*
-rw-r--r-- 1 root root 4090171 Dec 3 16:49 falcon-agent-5.1.2.tar.gz
-rw-r--r-- 1 root root 8 Dec 3 16:46 gitversion
drwxr-xr-x 5 root root 4096 Dec 3 16:41 public/
drwxr-xr-x 2 root root 4096 Dec 3 16:50 var/
root@ubuntu:/data/open-falcon# cat cfg.json
{
"debug": true,
"hostname": "",
"ip": "",
"plugin": {
"enabled": false,
"dir": "./plugin",
"git": "https://github.com/open-falcon/plugin.git",
"logs": "./logs"
},
"heartbeat": {
"enabled": true,
"addr": "192.168.2.104:6030",
"interval": 60,
"timeout": 1000
},
"transfer": {
"enabled": true,
"addrs": [
"192.168.2.104: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
}
}

启动运行

1
2
3
4
5
6
7
8
9
10
11
12
13
14
root@ubuntu:/data/open-falcon# ./control start
falcon-agent started..., pid=30913
root@ubuntu:/data/open-falcon# ./control status
started
root@ubuntu:/data/open-falcon# ./control tail
2017/12/03 16:50:36 cfg.go:142: read config file: cfg.json successfully
2017/12/03 16:50:36 http.go:88: listening :1988
2017/12/03 16:51:36 var.go:102: => <Total=69> <Endpoint:ubuntu, Metric:agent.alive, Type:GAUGE, Tags:, Step:60, Time:1512291096, Value:1>
2017/12/03 16:51:36 var.go:102: => <Total=25> <Endpoint:ubuntu, Metric:df.bytes.free.percent, Type:GAUGE, Tags:mount=/,fstype=ext4, Step:60, Time:1512291096, Value:87.72145698728876>
2017/12/03 16:51:36 plugin.go:78: <Plugins:[sys/disk sys/ntp], Timestamp:1512291096>
2017/12/03 16:51:36 var.go:109: <= <Total=69, Invalid:0, Latency=0ms, Message:ok>
2017/12/03 16:51:36 var.go:109: <= <Total=25, Invalid:0, Latency=0ms, Message:ok>
2017/12/03 16:51:36 var.go:102: => <Total=6> <Endpoint:ubuntu, Metric:ss.timewait, Type:GAUGE, Tags:, Step:60, Time:1512291096, Value:0>
2017/12/03 16:51:36 var.go:109: <= <Total=6, Invalid:0, Latency=0ms, Message:ok>

验证

1
2
3
4
root@ubuntu:/data/open-falcon# curl http://127.0.0.1:1988/proc/cpu/num
{"msg":"success","data":1}root@ubuntu:/data/open-falcon#
root@ubuntu:/data/open-falcon# curl http://127.0.0.1:1988/page/system/uptime
{"msg":"success","data":"0 days 3 hours 8 minutes"}root@ubuntu:/data/open-falcon#

默认接口

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
http://127.0.0.1:1988/exit
http://127.0.0.1:1988/config/reload
http://127.0.0.1:1988/workdir
http://127.0.0.1:1988/ips
http://127.0.0.1:1988/proc/cpu/num
http://127.0.0.1:1988/proc/cpu/mhz
http://127.0.0.1:1988/page/cpu/usage
http://127.0.0.1:1988/proc/cpu/usage
http://127.0.0.1:1988/page/df
http://127.0.0.1:1988/health
http://127.0.0.1:1988/version
http://127.0.0.1:1988/page/diskio
http://127.0.0.1:1988/proc/kernel/hostname
http://127.0.0.1:1988/proc/kernel/maxproc
http://127.0.0.1:1988/proc/kernel/maxfiles
http://127.0.0.1:1988/proc/kernel/version
http://127.0.0.1:1988/page/memory
http://127.0.0.1:1988/proc/memory
http://127.0.0.1:1988/
http://127.0.0.1:1988/plugin/update
http://127.0.0.1:1988/plugin/reset
http://127.0.0.1:1988/plugins
http://127.0.0.1:1988/v1/push
http://127.0.0.1:1988/system/date
http://127.0.0.1:1988/page/system/uptime
http://127.0.0.1:1988/proc/system/uptime
http://127.0.0.1:1988/page/system/loadavg
http://127.0.0.1:1988/proc/system/loadavg

浏览器直接访问

插件安装

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
root@ubuntu:/data/open-falcon# mkdir plugins
root@ubuntu:/data/open-falcon# cd plugins/
root@ubuntu:/data/open-falcon/plugins# pwd
/data/open-falcon/plugins
root@ubuntu:/data/open-falcon/plugins# git clone https://github.com/open-falcon/plugin.git
Cloning into 'plugin'...
remote: Counting objects: 21, done.
remote: Total 21 (delta 0), reused 0 (delta 0), pack-reused 21
Unpacking objects: 100% (21/21), done.
Checking connectivity... done.
root@ubuntu:/data/open-falcon/plugins# ll
total 12
drwxr-xr-x 3 root root 4096 Dec 3 17:02 ./
drwxr-xr-x 5 root root 4096 Dec 3 17:01 ../
drwxr-xr-x 6 root root 4096 Dec 3 17:02 plugin/
root@ubuntu:/data/open-falcon/plugins# mv plugin/* ./
root@ubuntu:/data/open-falcon/plugins# ll
total 24
drwxr-xr-x 6 root root 4096 Dec 3 17:02 ./
drwxr-xr-x 5 root root 4096 Dec 3 17:01 ../
drwxr-xr-x 2 root root 4096 Dec 3 17:02 common/
drwxr-xr-x 2 root root 4096 Dec 3 17:02 demo/
drwxr-xr-x 3 root root 4096 Dec 3 17:02 plugin/
drwxr-xr-x 5 root root 4096 Dec 3 17:02 sys/
root@ubuntu:/data/open-falcon/plugins# rm -rf plugin/
root@ubuntu:/data/open-falcon/plugins# cd ..
root@ubuntu:/data/open-falcon# ./control restart
falcon-agent stoped...
falcon-agent started..., pid=27606
root@ubuntu:/data/open-falcon# ll
total 13704
drwxr-xr-x 5 root root 4096 Dec 3 17:01 ./
drw------- 9 root root 4096 Dec 3 14:08 ../
-rw-r--r-- 1 root root 1288 Dec 3 16:41 cfg.example.json
-rw-r--r-- 1 root root 1266 Dec 3 16:49 cfg.json
-rwxr-xr-x 1 root root 2291 Dec 3 16:41 control*
-rwxr-xr-x 1 root root 9900773 Dec 3 16:46 falcon-agent*
-rw-r--r-- 1 root root 4090171 Dec 3 16:49 falcon-agent-5.1.2.tar.gz
-rw-r--r-- 1 root root 8 Dec 3 16:46 gitversion
drwxr-xr-x 5 root root 4096 Dec 3 17:02 plugins/
drwxr-xr-x 5 root root 4096 Dec 3 16:41 public/
drwxr-xr-x 2 root root 4096 Dec 3 17:02 var/
root@ubuntu:/data/open-falcon# pwd
/data/open-falcon

浏览器设置插件目录

大概等5分钟看到图,ntp 插件名是600_ntp.py 意味着每10分钟上报一次数据

ntp没有数据是ubuntu没有ntpq 这个命令

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
root@ubuntu:/data/open-falcon/plugins# apt install ntp
root@ubuntu:/data/open-falcon/plugins# ntpq -pn
remote refid st t when poll reach delay offset jitter
==============================================================================
0.ubuntu.pool.n .POOL. 16 p - 64 0 0.000 0.000 0.000
1.ubuntu.pool.n .POOL. 16 p - 64 0 0.000 0.000 0.000
2.ubuntu.pool.n .POOL. 16 p - 64 0 0.000 0.000 0.000
3.ubuntu.pool.n .POOL. 16 p - 64 0 0.000 0.000 0.000
ntp.ubuntu.com .POOL. 16 p - 64 0 0.000 0.000 0.000
-192.33.96.102 .PPS. 1 u 51 64 1 371.469 -32.679 28.738
-161.53.131.232 46.54.224.12 2 u 50 64 1 490.003 -43.253 57.495
-213.209.109.45 10.129.40.211 2 u 47 64 1 310.142 -27.899 34.489
-91.103.163.212 195.113.144.238 2 u 48 64 1 323.156 -18.509 23.309
*202.108.6.95 10.6.63.22 2 u 42 64 1 42.048 15.320 6.469
-85.199.214.101 .GPS. 1 u 45 64 1 327.656 -21.258 32.228
+217.147.223.78 194.242.34.149 2 u 44 64 1 254.132 26.142 20.354
91.189.91.157 132.246.11.231 2 u 55 64 1 286.789 8.344 0.000
202.112.10.36 10.3.8.150 5 u 43 64 1 42.043 17.437 8.001
91.189.94.4 17.253.34.253 2 u 54 64 1 276.483 46.736 0.000
+173.255.246.13 204.123.2.72 2 u 40 64 1 264.252 11.578 23.180
91.189.89.199 193.79.237.14 2 u 52 64 1 351.735 0.323 0.000
91.189.89.198 140.203.204.77 2 u 52 64 1 355.954 5.709 0.000

同版本的操作系统只需拿这个编译好的包并修改正确的heartbeat\transfer地址重新打包好,用ansible 批量拷贝、解压、启动,全部客户端将自己上报监控数据到服务端,非常方便简单。

----纸上得来终觉浅绝知此事要躬行----
最好的赞赏是您的阅读!
0%