4.2 アイテムとデータタイプ
Zabbixにおけるデータ項目の定義と多様なデータ形式の処理方法
概要
**アイテム(Items)**は、Zabbixにおいて収集する個々のデータ要素を定義するオブジェクトです。各アイテムは特定のメトリクス(CPU使用率、メモリ消費量、ログエントリなど)を表し、データタイプに応じて適切な処理と保存が行われます。
アイテムの基本構成要素
要素 | 説明 | 例 |
---|---|---|
名前 | 人間が読める形式の項目名 | "CPU utilization" |
キー | システム内で一意な識別子 | system.cpu.util[,idle] |
タイプ | データ収集方法 | Zabbix agent, SNMP, HTTP |
値タイプ | データの形式 | 数値、文字列、ログ、テキスト |
更新間隔 | データ収集頻度 | 60s, 5m, 1h |
数値データタイプ
数値(浮動小数点)
特徴と用途
- 小数点を含む数値データ
- パフォーマンス指標やパーセンテージに適用
- 高精度の測定値に使用
設定例
ini
# CPU使用率監視
Name: CPU utilization
Type: Zabbix agent
Key: system.cpu.util[,idle]
Value type: Numeric (float)
Units: %
Update interval: 60s
# データ型変換
Formula: 100-{ITEM.VALUE}
実践的な使用例
ini
# メモリ使用率(パーセンテージ)
Name: Memory utilization
Key: vm.memory.util
Value type: Numeric (float)
Units: %
Preprocessing:
- Type: Custom multiplier
- Parameter: 0.01
# ディスク使用率(GB単位)
Name: Disk space usage
Key: vfs.fs.size[/,used]
Value type: Numeric (float)
Units: GB
Preprocessing:
- Type: Custom multiplier
- Parameter: 1.073741824e-9
数値(符号なし整数)
特徴と用途
- 負の値を持たない整数
- カウンター値やリソース量に使用
- メモリ効率が良好
設定例
ini
# プロセス数
Name: Number of httpd processes
Type: Zabbix agent
Key: proc.num[httpd]
Value type: Numeric (unsigned)
Update interval: 300s
# ネットワーク送信バイト数
Name: Network interface bytes sent
Key: net.if.out[eth0]
Value type: Numeric (unsigned)
Units: B
Update interval: 60s
大容量データの扱い
ini
# ディスク使用量(バイト)
Name: Disk total space
Key: vfs.fs.size[/,total]
Value type: Numeric (unsigned)
Units: B
Description: Total disk space in bytes
# ネットワーク累積トラフィック
Name: Interface total bytes
Key: net.if.total[eth0]
Value type: Numeric (unsigned)
Units: B
Type: Calculated
Formula: last(net.if.in[eth0])+last(net.if.out[eth0])
文字列・テキストデータタイプ
文字列データ
特徴と用途
- 短い文字データ(通常256文字以内)
- システム情報やステータス値に使用
- パターンマッチングに適用
設定例
ini
# システム名
Name: System name
Type: Zabbix agent
Key: system.uname
Value type: Character
Update interval: 86400s
# サービス状態
Name: HTTP service status
Type: HTTP agent
Key: web.service.status
Value type: Character
URL: https://api.example.com/status
Preprocessing:
- Type: JSONPath
- Parameter: $.status
値マッピングの活用
ini
# サービス状態の値マッピング
Value mapping: Service Status
Mappings:
0 → Down
1 → Up
2 → Warning
3 → Unknown
# トリガーでの活用
Trigger: Service is down
Expression: {host:service.status.last()}=0
テキストデータ
特徴と用途
- 長い文字データ(65KB以内)
- 設定ファイルや詳細情報の保存
- ログデータの詳細内容
設定例
ini
# システム設定情報
Name: System configuration
Type: Zabbix agent
Key: system.config.dump
Value type: Text
Update interval: 3600s
# アプリケーション詳細状態
Name: Application detailed status
Type: HTTP agent
Key: app.status.detailed
Value type: Text
URL: https://api.example.com/status/detailed
Headers: Authorization: Bearer {$API_TOKEN}
構造化データの処理
ini
# JSON形式の設定取得
Name: Database configuration
Type: Database monitor
Key: db.config.json
Value type: Text
SQL query: SELECT JSON_OBJECT('host', @@hostname, 'version', @@version, 'uptime', @@uptime)
# XML形式の状態取得
Name: Service XML status
Type: HTTP agent
Key: service.xml.status
Value type: Text
URL: https://api.example.com/status.xml
ログデータ監視
ログファイル監視の基礎
基本設定
ini
# アクセスログ監視
Name: Apache access log
Type: Zabbix agent (active)
Key: log[/var/log/httpd/access_log]
Value type: Log
Update interval: 30s
# エラーログ監視
Name: Apache error log
Type: Zabbix agent (active)
Key: log[/var/log/httpd/error_log,"ERROR|FATAL"]
Value type: Log
Update interval: 30s
高度なログ監視設定
ログローテーション対応
ini
# ログローテーション対応設定
Name: Application log monitoring
Key: logrt[/var/log/myapp*.log,"ERROR|WARN|FATAL"]
Value type: Log
Update interval: 10s
Description: Monitor application logs with rotation support
複雑なパターンマッチング
ini
# Apache アクセスログから4xx/5xxエラー抽出
Name: HTTP error detection
Key: log[/var/log/httpd/access_log," (4[0-9][0-9]|5[0-9][0-9]) "]
Value type: Log
# MySQL スロークエリログ監視
Name: MySQL slow query detection
Key: logrt[/var/log/mysql/slow*.log,"Query_time: ([0-9]+\.[0-9]+)"]
Value type: Log
Windowsイベントログ監視
ini
# Windows システムイベント
Name: Windows System Events
Key: eventlog[System,,"Error|Warning"]
Value type: Log
# Windows セキュリティイベント
Name: Windows Security Events
Key: eventlog[Security,,"Information",,"Logon|Logoff"]
Value type: Log
# Windows アプリケーションイベント
Name: Application Events
Key: eventlog[Application,,"Error"]
Value type: Log
カスタムログ解析
構造化ログの処理
bash
#!/bin/bash
# /etc/zabbix/scripts/parse_json_log.sh
LOG_FILE="/var/log/myapp/app.log"
LEVEL=$1
# JSON形式ログから特定レベルのメッセージを抽出
tail -f "$LOG_FILE" | while read line; do
echo "$line" | jq -r "select(.level == \"$LEVEL\") | .message"
done
ini
# カスタムログ解析アイテム
Name: Custom JSON log parser
Type: Zabbix agent (active)
Key: log.custom[error]
UserParameter: log.custom[*],/etc/zabbix/scripts/parse_json_log.sh $1
Value type: Log
バイナリデータ監視
ファイル整合性監視
ファイルチェックサム監視
ini
# MD5チェックサム監視
Name: Configuration file checksum
Type: Zabbix agent
Key: vfs.file.cksum[/etc/passwd,md5]
Value type: Character
Update interval: 300s
# SHA256チェックサム監視
Name: Binary file integrity
Type: Zabbix agent
Key: vfs.file.cksum[/usr/bin/sshd,sha256]
Value type: Character
Update interval: 3600s
ファイル属性監視
ini
# ファイルサイズ監視
Name: Configuration file size
Key: vfs.file.size[/etc/myapp.conf]
Value type: Numeric (unsigned)
Units: B
# ファイル更新時刻監視
Name: File modification time
Key: vfs.file.time[/etc/passwd,modify]
Value type: Numeric (unsigned)
Description: Unix timestamp of last modification
# ファイル存在確認
Name: Important file exists
Key: vfs.file.exists[/etc/critical.conf]
Value type: Numeric (unsigned)
Value mapping:
0 → Missing
1 → Present
前処理ステップ
数値データの前処理
単位変換と計算
ini
# バイトからGBへの変換
Preprocessing steps:
1. Type: Custom multiplier
Parameter: 1.073741824e-9
2. Type: Round to decimal places
Parameter: 2
# パーセンテージ計算
Preprocessing steps:
1. Type: Custom multiplier
Parameter: 100
2. Type: Round to decimal places
Parameter: 1
統計処理
ini
# 移動平均計算
Preprocessing steps:
1. Type: Simple change
Parameter: (none)
2. Type: Custom multiplier
Parameter: 60
# 変化率計算(per second)
Preprocessing steps:
1. Type: Change per second
Parameter: (none)
文字列データの前処理
正規表現による抽出
ini
# ログから数値抽出
Preprocessing steps:
1. Type: Regular expression
Parameter: "Load average: ([0-9\.]+)"
Output: \1
2. Type: Trim
Parameter: " \t\r\n"
# JSON パスによるデータ抽出
Preprocessing steps:
1. Type: JSONPath
Parameter: $.metrics.cpu.usage
2. Type: Custom multiplier
Parameter: 0.01
テキスト処理
ini
# 文字列の正規化
Preprocessing steps:
1. Type: Replace
Parameter: "([A-Z]+)" → "\1"
2. Type: Trim
Parameter: " "
3. Type: Right trim
Parameter: ","
XMLとJSON処理
JSON データ処理
json
{
"response": {
"server": {
"cpu": {
"usage": 75.5,
"cores": 8
},
"memory": {
"total": 16777216,
"used": 8388608
}
}
}
}
ini
# CPU使用率抽出
Preprocessing steps:
1. Type: JSONPath
Parameter: $.response.server.cpu.usage
# メモリ使用率計算
Preprocessing steps:
1. Type: JSONPath
Parameter: $.response.server.memory
2. Type: JavaScript
Parameter: |
var data = JSON.parse(value);
return (data.used / data.total * 100).toFixed(2);
XML データ処理
xml
<server>
<status>running</status>
<cpu usage="65.2" />
<memory total="16384" used="8192" />
</server>
ini
# XML パス抽出
Preprocessing steps:
1. Type: XPath
Parameter: /server/cpu/@usage
# 属性値の抽出と変換
Preprocessing steps:
1. Type: XPath
Parameter: /server/memory/@used
2. Type: Custom multiplier
Parameter: 1048576 # MB to bytes
JavaScriptによる高度な前処理
複雑な計算処理
javascript
// CPU使用率の正規化(複数コア平均)
var cores = [75.5, 68.2, 82.1, 71.8];
var total = cores.reduce(function(sum, core) {
return sum + core;
}, 0);
return (total / cores.length).toFixed(2);
javascript
// ネットワーク使用率計算
var input = JSON.parse(value);
var utilization = (input.bytes_in + input.bytes_out) * 8 / input.speed * 100;
return Math.min(utilization, 100).toFixed(2);
エラーハンドリング
javascript
// 安全なJSON解析
try {
var data = JSON.parse(value);
return data.metrics ? data.metrics.cpu : 0;
} catch (e) {
return 0; // デフォルト値を返す
}
javascript
// 条件分岐処理
var status = value.toLowerCase();
switch(status) {
case 'running':
return 1;
case 'stopped':
return 0;
case 'error':
return -1;
default:
return 2; // unknown
}
値マッピング
基本的な値マッピング
数値マッピング
ini
# サービス状態マッピング
Value mapping: Service Status
0 → Stopped
1 → Running
2 → Starting
3 → Stopping
4 → Error
# ディスク使用率マッピング
Value mapping: Disk Usage Level
0-69 → Normal
70-84 → Warning
85-94 → High
95-100 → Critical
文字列マッピング
ini
# HTTPステータスコードマッピング
Value mapping: HTTP Status
200 → OK
301 → Moved Permanently
400 → Bad Request
401 → Unauthorized
403 → Forbidden
404 → Not Found
500 → Internal Server Error
503 → Service Unavailable
範囲マッピング
パフォーマンスレベル
ini
# CPU使用率レベル
Value mapping: CPU Usage Level
Ranges:
0-30 → Low
31-60 → Normal
61-80 → High
81-90 → Very High
91-100 → Critical
# 温度レベル(摂氏)
Value mapping: Temperature Level
Ranges:
-40-10 → Very Cold
11-25 → Cold
26-35 → Normal
36-45 → Warm
46-60 → Hot
61-100 → Very Hot
高度なアイテム設定
計算アイテム
基本計算式
ini
# CPU総使用率(複数コア)
Name: Total CPU utilization
Type: Calculated
Key: cpu.total.util
Formula: (last(system.cpu.util[,user])+last(system.cpu.util[,system])+last(system.cpu.util[,iowait]))
# メモリ使用率
Name: Memory utilization percentage
Type: Calculated
Key: memory.util.percent
Formula: last(vm.memory.size[used])/last(vm.memory.size[total])*100
条件付き計算
ini
# ディスク使用率(安全チェック付き)
Name: Safe disk utilization
Type: Calculated
Key: disk.util.safe
Formula: last(vfs.fs.size[/,total])>0?last(vfs.fs.size[/,used])/last(vfs.fs.size[/,total])*100:0
# ネットワーク効率(エラー率考慮)
Name: Network efficiency
Type: Calculated
Key: net.efficiency
Formula: (last(net.if.in[eth0])+last(net.if.out[eth0]))>0?100-(last(net.if.in.errors[eth0])+last(net.if.out.errors[eth0]))/(last(net.if.in[eth0])+last(net.if.out[eth0]))*100:100
依存アイテム
マスターアイテムとの連携
ini
# マスターアイテム(SNMP バルク取得)
Name: SNMP bulk interface data
Type: SNMP agent
Key: snmp.bulk.interfaces
SNMP OID: 1.3.6.1.2.1.2.2.1
# 依存アイテム(インターフェース名)
Name: Interface {#IFINDEX} name
Type: Dependent item
Key: if.name[{#IFINDEX}]
Master item: snmp.bulk.interfaces
Preprocessing:
- Type: JSONPath
- Parameter: $.[{#IFINDEX}].name
パフォーマンス最適化
更新間隔の最適化
ini
# 高頻度監視(重要なメトリクス)
CPU utilization: 30s
Memory usage: 30s
Network traffic: 30s
# 中頻度監視(一般的なメトリクス)
Disk space: 300s (5分)
Process count: 300s
Load average: 60s
# 低頻度監視(静的情報)
System information: 86400s (24時間)
Software versions: 86400s
Hardware information: 86400s
データ保持期間の設定
ini
# 履歴データ保持期間
History storage period: 90d
# トレンドデータ保持期間
Trend storage period: 5y
# 高頻度データの短期保持
High-frequency data: 7d
Medium-frequency data: 30d
Low-frequency data: 365d
まとめ
Zabbixのアイテムとデータタイプシステムは、多様な監視要件に対応する柔軟性を提供します。適切なデータタイプの選択、効果的な前処理設定、最適化されたパフォーマンス設定により、効率的で正確な監視システムを構築できます。
次のセクションでは、収集したデータを基にした問題検知の仕組みであるトリガーシステムについて詳しく説明します。
参考リンク