리눅스

Zabbix에서 UserParameter를 사용하여 사용자 정의 메트릭을 수집하는 방법

변군이글루 2025. 2. 7. 21:25
반응형

Zabbix에서 UserParameter를 사용하여 사용자 정의 메트릭을 수집하는 방법

Zabbix에서 UserParameter를 사용하면 기본 제공되지 않는 사용자 정의 항목(커스텀 메트릭) 데이터를 수집할 수 있습니다.

이를 통해 서버에서 실행할 사용자 정의 스크립트나 명령어를 지정할 수 있습니다.

1. UserParameter 설정

Zabbix 에이전트 설정 파일 수정

  • Zabbix 에이전트 설정 파일에 UserParameter를 정의합니다.
    • /etc/zabbix/zabbix_agentd2.conf
    • /etc/zabbix/zabbix_agent2.d/*.conf
vim /etc/zabbix/zabbix_agent2.conf
Include=/etc/zabbix/zabbix_agent2.d/*.conf
더보기

---

sudo tee /etc/zabbix/zabbix_agent2.conf > /dev/null <<EOF
PidFile=/run/zabbix/zabbix_agent2.pid
LogFile=/var/log/zabbix/zabbix_agent2.log
LogFileSize=10

Server=zabbix.sangchul.kr,zabbix.scbyun.com
ServerActive=zabbix.sangchul.kr,zabbix.scbyun.com
  
Hostname=system.hostname

Include=/etc/zabbix/zabbix_agent2.d/*.conf
PluginSocket=/run/zabbix/agent.plugin.sock
ControlSocket=/run/zabbix/agent.sock
Include=/etc/zabbix/zabbix_agent2.d/plugins.d/*.conf
EOF

---

UserParameter 정의

UserParameter=<키 이름>,<실행할 명령어>
vim /etc/zabbix/zabbix_agent2.d/userparameter_custom.conf
# Echo the input argument
UserParameter=custom.echo[*],echo $1

# Check TCP port status using netcat (return 0 if open, 1 if closed)
UserParameter=custom.nc.tcp.port[*],nc -4 -z -w "$3" "$1" "$2"; echo $?

# Check UDP port status using netcat (return 0 if open, 1 if closed)
UserParameter=custom.nc.udp.port[*],nc -4u -z -w "$3" "$1" "$2"; echo $?

UserParameter=custom.log.check,grep -c 'ERROR' /var/log/syslog

UserParameter=network.ethernet.get,ip -o -4 addr show $(ip route show default | awk '/default/ {print $5}') | awk '/inet / {print $2}' | cut -d/ -f1
UserParameter=network.ipaddr.get,ip -o -4 addr show $(ip route show default | awk '/default/ {print $5}') | awk '{print $4}' | cut -d/ -f1
더보기

---

cat <<'EOF'> /etc/zabbix/zabbix_agent2.d/userparameter.conf
# Echo the input argument
UserParameter=custom.echo[*],echo $1

# Check TCP port status using netcat (return 0 if open, 1 if closed)
UserParameter=custom.nc.tcp.port[*],nc -4 -z -w "$3" "$1" "$2"; echo $?

# Check UDP port status using netcat (return 0 if open, 1 if closed)
UserParameter=custom.nc.udp.port[*],nc -4u -z -w "$3" "$1" "$2"; echo $?

UserParameter=custom.log.check,grep -c 'ERROR' /var/log/syslog

UserParameter=network.ethernet.get,ip -o -4 addr show $(ip route show default | awk '/default/ {print $5}') | awk '/inet / {print $2}' | cut -d/ -f1
UserParameter=network.ipaddr.get,ip -o -4 addr show $(ip route show default | awk '/default/ {print $5}') | awk '{print $4}' | cut -d/ -f1
EOF

---

Zabbix Agent 2 설정 파일의 유효성 확인

zabbix_agent2 -T /etc/zabbix/zabbix_agent2.conf
더보기

---

Zabbix Agent 설정 파일의 유효성 확인

zabbix_agentd -c /etc/zabbix/zabbix_agentd.conf

---

zabbix_agent2 [12345]: using configuration file: /etc/zabbix/zabbix_agent2.conf
zabbix_agent2 [12345]: configuration file is valid

Zabbix 에이전트 재시작

  • Zabbix 에이전트를 재시작하여 변경 사항을 적용합니다.
sudo systemctl restart zabbix-agent2

2. Zabbix UI에서 아이템 생성

Zabbix 웹 인터페이스에서 새로운 아이템을 생성하여 사용자 정의 메트릭을 수집할 수 있습니다.

아이템 생성

1. Configuration > Hosts에서 호스트 선택

2. Items > Create Item 클릭

3. Item 설정

  • Name: Network Ethernet IP
  • Type: Zabbix agent
  • Key: network.ethernet.get 또는 network.ipaddr.get
  • Type of information: Text
  • Update interval: 60s (원하는 대로 설정)

4. Save 클릭

아이템 값 확인

Monitoring > Latest data에서 해당 호스트의 IP 주소 정보를 확인합니다.

테스트 방법 (Zabbix 서버에서)

zabbix_get -s <agent_ip> -k network.ethernet.get

 

참고URL

- ZABBIX Documentation : zabbix_agent2(7.0 LTS)

- ZABBIX Documentation : zabbix_agentd(5.0 LTS)

- ZABBIX Documentation : 4 Zabbix agent 2(7.0 LTS)

- ZABBIX Documentation : 3 Zabbix agent(5.0 LTS)

- Zabbix Official Repository : Index of /zabbix/7.0/ubuntu/pool/main/z/zabbix/

 

728x90
반응형