Triệu chứng chính: log Telegraf có partial write: field type conflict hoặc points beyond retention policy, Metric buffer overflow; N metrics have been dropped; RAM/disk của influxd tăng liên tục; panel Grafana báo timeout hoặc context deadline exceeded. Trang này giả định InfluxDB 2.x OSS, bucket telemetry, measurement interfaces, tag source/name như InfluxDB Flux.
Lỗi thường gặp
| Triệu chứng | Nguyên nhân | Cách xử lý |
|---|---|---|
partial write: field type conflict: input field "in_octets" on measurement "interfaces" is type float, already exists as type integer |
Cùng field nhưng nguồn khác gửi kiểu khác (int vs float, int vs uint, string) | Ép kiểu ở Telegraf (processors.converter), hoặc ghi sang measurement/bucket mới. Kiểu field cố định trong một shard, chỉ đổi được khi shard cũ hết retention |
partial write: points beyond retention policy dropped=N |
Timestamp quá cũ so với retention, thường do đồng hồ thiết bị sai hoặc sai precision (giây bị hiểu là nano giây → năm 1970) |
Sửa NTP; kiểm tra precision khi ghi tay qua API |
unable to parse ...: invalid field format / missing fields |
Line protocol sai: thiếu dấu ,/khoảng trắng, chuỗi chưa nháy kép, tag có dấu cách chưa escape |
Thử lại bằng influx write với một dòng; escape \ , \,, \= trong tag |
HTTP 401 unauthorized access |
Token sai hoặc không có quyền ghi bucket | influx auth list, tạo token có write cho bucket telemetry |
HTTP 404 bucket "telemetry" not found |
Sai tên bucket/org | influx bucket list --org netops |
Metric buffer overflow; N metrics have been dropped (Telegraf) |
InfluxDB chậm/không tới được, buffer đầy | Sửa phía InfluxDB trước; tăng metric_buffer_limit, giảm tần suất input |
RAM influxd tăng, ghi chậm dần |
Cardinality cao: tag mang giá trị động (description, IP, session id, timestamp) | Tìm tag gây nổ (bên dưới), chuyển thành field hoặc bỏ bằng tagexclude, xoá dữ liệu cũ |
max-values-per-tag limit exceeded / max-series-per-database limit exceeded |
Giới hạn cardinality của InfluxDB 1.x | Như trên; chỉ tăng giới hạn khi đã chắc dữ liệu đúng |
| Disk tăng nhanh dù đã đặt retention | Retention xoá theo shard group, dữ liệu chỉ mất khi cả shard group hết hạn; WAL và compaction cần thêm chỗ | Đặt shard group duration nhỏ hơn cho bucket ngắn ngày, chừa ≥ 20-30% disk trống |
Grafana timeout, context deadline exceeded |
Range quá dài trên dữ liệu raw, filter đặt sau map/pivot, không dùng aggregateWindow |
Đưa filter lên sau range, dùng v.windowPeriod, downsample sang bucket 5 phút |
| Query bị xếp hàng hoặc từ chối khi nhiều người xem | Giới hạn query-concurrency / query-queue-size / query-memory-bytes |
Tăng refresh interval dashboard; chỉnh các tham số này trong config influxd |
Các bước khoanh vùng
- InfluxDB còn sống không:
influx ping,/health, loginfluxd. - Telegraf có ghi được không: log
E! [outputs.influxdb_v2], metricinternal_write(cần[[inputs.internal]]). - Ghi tay một điểm bằng API để tách lỗi Telegraf khỏi lỗi InfluxDB.
- Cardinality: đếm series toàn bucket, rồi đếm giá trị của từng tag để tìm tag gây nổ.
- Disk: dung lượng
engine/datavàengine/wal, retention và shard group duration của bucket. - Query: chạy lại query chậm với range ngắn, kiểm tra thứ tự
filter.
Cấu hình đúng
[agent]
interval = "10s"
metric_batch_size = 5000 # số metric mỗi lần ghi
metric_buffer_limit = 100000 # đệm khi output lỗi; hết chỗ thì drop metric cũ nhất
flush_interval = "10s"
[[inputs.internal]] # tự theo dõi Telegraf: buffer, số metric drop
[[inputs.gnmi]]
# ...
tagexclude = ["path"] # không biến path thành tag
[[processors.converter]] # cố định kiểu field, tránh type conflict
namepass = ["interfaces"]
[processors.converter.fields]
integer = ["in_octets", "out_octets", "in_errors"]Tag chỉ nên là thứ dùng để lọc/gom nhóm và có tập giá trị hữu hạn (source, name, site). Description interface, IP peer, message thì để là field.
Kiểm tra nhanh
influx ping
curl -s http://localhost:8086/health
journalctl -u influxdb -n 100 --no-pager # gói deb/rpm; Docker: docker logs influxdb
journalctl -u telegraf --since '15 min ago' | grep -E 'E!|W!'
# Ghi tay 1 điểm (204 = thành công)
curl -s -i -X POST "http://localhost:8086/api/v2/write?org=netops&bucket=telemetry&precision=s" \
-H "Authorization: Token $INFLUX_TOKEN" \
--data-binary "interfaces,source=lab1,name=Gi0/0/0/0 in_octets=123i $(date +%s)"
# Retention và shard group duration của bucket
influx bucket list --name telemetry
influx bucket update -i <bucket-id> -r 30d --shard-group-duration 1d
# Dung lượng (gói deb: /var/lib/influxdb; image Docker: /var/lib/influxdb2)
du -sh /var/lib/influxdb/engine/data /var/lib/influxdb/engine/wal
df -h /var/lib/influxdb// Tổng số series của bucket trong 30 ngày
import "influxdata/influxdb"
influxdb.cardinality(bucket: "telemetry", start: -30d)// Số giá trị của từng tag (chạy lần lượt cho các tag nghi ngờ)
import "influxdata/influxdb/schema"
schema.tagKeys(bucket: "telemetry", start: -1d) |> yield(name: "tag_keys")
schema.tagValues(bucket: "telemetry", tag: "name", start: -1d) |> count() |> yield(name: "name_count")// Telegraf có đang drop metric không (từ inputs.internal)
from(bucket: "telemetry")
|> range(start: -1h)
|> filter(fn: (r) => r._measurement == "internal_write" and (r._field == "metrics_dropped" or r._field == "buffer_size"))
|> last()Với InfluxDB 1.x (InfluxQL): SHOW SERIES CARDINALITY ON telemetry và SHOW TAG VALUES CARDINALITY ON telemetry WITH KEY = "name". Xoá dữ liệu sai bằng influx delete (xem bảng influx CLI trong InfluxDB Flux); disk đầy ở tầng OS xem disk đầy.