Skip to content

Commit 244747f

Browse files
authored
feat: Add Keepalived Support (#1286)
* chore: debug mode only print log for node_exporter * feat: add keepalived support * docs: update README for keepalived * fix: keepalived windows build --------- Co-authored-by: peter <>
1 parent 73fd768 commit 244747f

27 files changed

Lines changed: 3131 additions & 0 deletions

agent/metrics_agent.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ import (
4848
_ "flashcat.cloud/categraf/inputs/jolokia_agent"
4949
_ "flashcat.cloud/categraf/inputs/jolokia_proxy"
5050
_ "flashcat.cloud/categraf/inputs/kafka"
51+
_ "flashcat.cloud/categraf/inputs/keepalived"
5152
_ "flashcat.cloud/categraf/inputs/kernel"
5253
_ "flashcat.cloud/categraf/inputs/kernel_vmstat"
5354
_ "flashcat.cloud/categraf/inputs/kubernetes"
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# # collect interval
2+
# interval = 15
3+
4+
# Send SIGJSON and decode JSON file instead of parsing text files, defaults to `false`.
5+
sig_json = false
6+
7+
# A path for Keepalived PID, defaults to `/var/run/keepalived.pid`
8+
pid_path = ""
9+
10+
# Health Check script path to be execute for each VIP.
11+
# Check Script Example:
12+
#!/usr/bin/env bash
13+
#ping $1 -c 1 -W 1
14+
check_script_path = ""
15+
16+
#This is when the keepalived is running with PID 1 in the container so we can use the standard docker API to send signal to the keepalived process.
17+
# Keepalived container name to export metrics from Keepalived container.
18+
container_name = ""
19+
20+
# In case the keepalived process is not running with PID 1, this method will exec to the container and use the provided PID path to send the signal.
21+
container_pid_path = ""
22+
23+
# Keepalived container tmp volume path, defaults to `/tmp`.
24+
container_tmp = ""

go.mod

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,13 +145,15 @@ require (
145145
github.com/bits-and-blooms/bitset v1.13.0
146146
github.com/blang/semver/v4 v4.0.0
147147
github.com/bmatcuk/doublestar/v3 v3.0.0
148+
github.com/cenkalti/backoff/v4 v4.1.3
148149
github.com/coreos/go-systemd/v22 v22.5.0
149150
github.com/dennwc/btrfs v0.0.0-20230312211831-a1f570bd01a1
150151
github.com/ema/qdisc v1.0.0
151152
github.com/go-ldap/ldap/v3 v3.4.6
152153
github.com/godbus/dbus/v5 v5.0.4
153154
github.com/google/gnxi v0.0.0-20240912171544-ef18504847b0
154155
github.com/hashicorp/go-envparse v0.1.0
156+
github.com/hashicorp/go-version v1.2.1-0.20190424083514-192140e6f3e6
155157
github.com/hodgesds/perf-utils v0.7.0
156158
github.com/illumos/go-kstat v0.0.0-20210513183136-173c9b0a9973
157159
github.com/jsimonetti/rtnetlink v1.4.1

go.sum

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -782,6 +782,8 @@ github.com/cenkalti/backoff v2.2.1+incompatible/go.mod h1:90ReRw6GdpyfrHakVjL/QH
782782
github.com/cenkalti/backoff/v4 v4.0.0/go.mod h1:eEew/i+1Q6OrCDZh3WiXYv3+nJwBASZ8Bog/87DQnVg=
783783
github.com/cenkalti/backoff/v4 v4.1.0/go.mod h1:scbssz8iZGpm3xbr14ovlUdkxfGXNInqkPWOWmG2CLw=
784784
github.com/cenkalti/backoff/v4 v4.1.2/go.mod h1:scbssz8iZGpm3xbr14ovlUdkxfGXNInqkPWOWmG2CLw=
785+
github.com/cenkalti/backoff/v4 v4.1.3 h1:cFAlzYUlVYDysBEH2T5hyJZMh3+5+WCBvSnK6Q8UtC4=
786+
github.com/cenkalti/backoff/v4 v4.1.3/go.mod h1:scbssz8iZGpm3xbr14ovlUdkxfGXNInqkPWOWmG2CLw=
785787
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
786788
github.com/census-instrumentation/opencensus-proto v0.3.0/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
787789
github.com/census-instrumentation/opencensus-proto v0.4.1/go.mod h1:4T9NM4+4Vw91VeyqjLS6ao50K5bOcLKN6Q42XnYaRYw=
@@ -1277,6 +1279,8 @@ github.com/hashicorp/go-uuid v1.0.1/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/b
12771279
github.com/hashicorp/go-uuid v1.0.2/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
12781280
github.com/hashicorp/go-uuid v1.0.3 h1:2gKiV6YVmrJ1i2CKKa9obLvRieoRGviZFL26PcT/Co8=
12791281
github.com/hashicorp/go-uuid v1.0.3/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
1282+
github.com/hashicorp/go-version v1.2.1-0.20190424083514-192140e6f3e6 h1:rL76JewpeImeqMtpkAHVZkHrXWt6B5sGSj6sAsL0VnI=
1283+
github.com/hashicorp/go-version v1.2.1-0.20190424083514-192140e6f3e6/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
12801284
github.com/hashicorp/go.net v0.0.1/go.mod h1:hjKkEWcCURg++eb33jQU7oqQcI9XDCnUzHA0oac0k90=
12811285
github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
12821286
github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=

inputs/keepalived/README.md

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
# Keepalived
2+
3+
forked from [keepalived-exporter](https://github.com/mehdy/keepalived-exporter)
4+
5+
## Configuration
6+
7+
请参考配置[示例](../../conf/input.keepalived/keepalived.toml)
8+
9+
```
10+
# # collect interval
11+
# interval = 15
12+
13+
# Send SIGJSON and decode JSON file instead of parsing text files, defaults to `false`.
14+
sig_json = false
15+
16+
# A path for Keepalived PID, defaults to `/var/run/keepalived.pid`
17+
pid_path = ""
18+
19+
# Health Check script path to be execute for each VIP.
20+
# Check Script Example:
21+
#!/usr/bin/env bash
22+
#ping $1 -c 1 -W 1
23+
check_script_path = ""
24+
25+
#This is when the keepalived is running with PID 1 in the container so we can use the standard docker API to send signal to the keepalived process.
26+
# Keepalived container name to export metrics from Keepalived container.
27+
container_name = ""
28+
29+
# In case the keepalived process is not running with PID 1, this method will exec to the container and use the provided PID path to send the signal.
30+
container_pid_path = ""
31+
32+
# Keepalived container tmp volume path, defaults to `/tmp`.
33+
container_tmp = ""
34+
```
35+
36+
#### Using Docker Signal
37+
38+
This is when the keepalived is running with PID 1 in the container so we can use the standard docker API to send signal to the keepalived process.
39+
40+
```bash
41+
docker run -v keepalived-data:/tmp/ ... $KEEPALIVED_IMAGE
42+
```
43+
44+
#### Exec to container with PID path
45+
46+
In case the keepalived process is not running with PID 1, this method will exec to the container and use the provided PID path to send the signal.
47+
48+
```bash
49+
docker run -v keepalived-data:/tmp/ -v keepalived-pid:/var/run/ ... $KEEPALIVED_IMAGE
50+
```
51+
52+
## Metrics
53+
54+
| Metric | Notes
55+
|-------------------------------------------------|------------------------------------
56+
| keepalived_up | Status of Keepalived service
57+
| keepalived_vrrp_state | State of vrrp
58+
| keepalived_vrrp_excluded_state | State of vrrp with excluded VIP
59+
| keepalived_check_script_status | Check Script status for each VIP
60+
| keepalived_gratuitous_arp_delay_total | Gratuitous ARP delay
61+
| keepalived_advertisements_received_total | Advertisements received
62+
| keepalived_advertisements_sent_total | Advertisements sent
63+
| keepalived_become_master_total | Became master
64+
| keepalived_release_master_total | Released master
65+
| keepalived_packet_length_errors_total | Packet length errors
66+
| keepalived_advertisements_interval_errors_total | Advertisement interval errors
67+
| keepalived_ip_ttl_errors_total | TTL errors
68+
| keepalived_invalid_type_received_total | Invalid type errors
69+
| keepalived_address_list_errors_total | Address list errors
70+
| keepalived_authentication_invalid_total | Authentication invalid
71+
| keepalived_authentication_mismatch_total | Authentication mismatch
72+
| keepalived_authentication_failure_total | Authentication failure
73+
| keepalived_priority_zero_received_total | Priority zero received
74+
| keepalived_priority_zero_sent_total | Priority zero sent
75+
| keepalived_script_status | Tracker Script Status
76+
| keepalived_script_state | Tracker Script State
77+
78+
## Check Script
79+
80+
You can specify a check script like Keepalived script check to check if all the things is okay or not.
81+
The script will run for each VIP and gives an arg `$1` that contains VIP.
82+
83+
**Note:** The script should be executable.
84+
85+
```bash
86+
chmod +x check_script.sh
87+
```
88+
89+
### Sample Check Script
90+
91+
```bash
92+
#!/usr/bin/env bash
93+
ping $1 -c 1 -W 1
94+
```
95+
96+
## Example Output
97+
98+
```text
99+
keepalived_up agent_hostname=zy-wh-fat-utils-test-06 1
100+
keepalived_advertisements_received_total agent_hostname=zy-wh-fat-utils-test-06 iname=VI_1 intf=ens3 vrid=51 0
101+
keepalived_advertisements_sent_total agent_hostname=zy-wh-fat-utils-test-06 iname=VI_1 intf=ens3 vrid=51 8869
102+
keepalived_become_master_total agent_hostname=zy-wh-fat-utils-test-06 iname=VI_1 intf=ens3 vrid=51 1
103+
keepalived_release_master_total agent_hostname=zy-wh-fat-utils-test-06 iname=VI_1 intf=ens3 vrid=51 0
104+
keepalived_packet_length_errors_total agent_hostname=zy-wh-fat-utils-test-06 iname=VI_1 intf=ens3 vrid=51 0
105+
keepalived_advertisements_interval_errors_total agent_hostname=zy-wh-fat-utils-test-06 iname=VI_1 intf=ens3 vrid=51 0
106+
keepalived_ip_ttl_errors_total agent_hostname=zy-wh-fat-utils-test-06 iname=VI_1 intf=ens3 vrid=51 0
107+
keepalived_invalid_type_received_total agent_hostname=zy-wh-fat-utils-test-06 iname=VI_1 intf=ens3 vrid=51 0
108+
keepalived_address_list_errors_total agent_hostname=zy-wh-fat-utils-test-06 iname=VI_1 intf=ens3 vrid=51 0
109+
keepalived_authentication_invalid_total agent_hostname=zy-wh-fat-utils-test-06 iname=VI_1 intf=ens3 vrid=51 0
110+
keepalived_authentication_mismatch_total agent_hostname=zy-wh-fat-utils-test-06 iname=VI_1 intf=ens3 vrid=51 0
111+
keepalived_authentication_failure_total agent_hostname=zy-wh-fat-utils-test-06 iname=VI_1 intf=ens3 vrid=51 0
112+
keepalived_priority_zero_received_total agent_hostname=zy-wh-fat-utils-test-06 iname=VI_1 intf=ens3 vrid=51 0
113+
keepalived_priority_zero_sent_total agent_hostname=zy-wh-fat-utils-test-06 iname=VI_1 intf=ens3 vrid=51 0
114+
keepalived_gratuitous_arp_delay_total agent_hostname=zy-wh-fat-utils-test-06 iname=VI_1 intf=ens3 vrid=51 5
115+
keepalived_vrrp_state agent_hostname=zy-wh-fat-utils-test-06 iname=VI_1 intf=ens3 ip_address=172.20.84.253/24 vrid=51 2
116+
keepalived_script_status agent_hostname=zy-wh-fat-utils-test-06 name=chk_nginx 1
117+
keepalived_script_state agent_hostname=zy-wh-fat-utils-test-06 name=chk_nginx 0
118+
keepalived_scrape_use_seconds agent_hostname=zy-wh-fat-utils-test-06 0.000381182
119+
```

0 commit comments

Comments
 (0)