「PVE」- 通过 Telegraf + InfluxDB 监控(存在困难)

  CREATED BY JENKINSBOT

问题描述

该笔记将记录:通过 Telegraf 与 InfluxDB 监控 PVE Cluster 的方法,以及相关问题的解决办法。

解决方案

补充说明

我们目前(10/19/2022)还未配置成功,原因如下:
1)但是,我们没有找到合适的 Dashboard 来显示指标数据;
2)并且 Telegraf 提示 E! [inputs.proxmox] Error in plugin: search domain is not set 错误,暂时未找到解决办法;

原理简述

Telegraf Proxmox 插件能够访问 PVE Cluster 并从中采集指标,并发送到 InfluxDB 服务中;

服务部署

第零步、创建 PVE Token 参数

Can’t create API Token – Error 400 | Proxmox Support Forum

在 PVE Cluster 中:
1)Permissions / API Tokens / Add
2)Token ID:[A-Za-z][A-Za-z0-9\.\-_]+
3)Privilege Separation:是否进行独立的权限管理;

第一步、部署 InfluxDB 服务

InfluxDB v2.4.0,通过 APT 直接安装:Install InfluxDB as a service with systemd

1)创建用户名密码,以完成首次初始化;
2)创建 Bucket 实例,进行数据存储;
2)配置 Token 授予 Bucket 访问全新;

第二步、部署 Telegraf 组件

Telegraf 1.24.2,通过 APT 直接安装(与 InfluxDB 使用相同仓库):Telegraf open source data collector

...
[[inputs.proxmox]]
  ## API connection configuration. The API token was introduced in Proxmox v6.2. Required permissions for user and token: PVEAuditor role on /.
  base_url = "https://172.31.253.254:8006/api2/json"
  api_token = "root@pam!A123A56.123zde=361d1328-XXXXXXXXXXXXXXXXXX-a765bbc4e574"
  ## Node name, defaults to OS hostname
  node_name = "testing-space"

  ## Optional TLS Config
  # tls_ca = "/etc/telegraf/ca.pem"
  # tls_cert = "/etc/telegraf/cert.pem"
  # tls_key = "/etc/telegraf/key.pem"
  ## Use TLS but skip chain & host verification
  insecure_skip_verify = true

  # HTTP response timeout (default: 5s)
  response_timeout = "5s"
...
...
[[outputs.influxdb_v2]]
#   ## The URLs of the InfluxDB cluster nodes.
#   ##
#   ## Multiple URLs can be specified for a single cluster, only ONE of the
#   ## urls will be written to each interval.
#   ##   ex: urls = ["https://us-west-2-1.aws.cloud2.influxdata.com"]
    urls = ["http://127.0.0.1:8086"]
#
#   ## Token for authentication.
    token = "L23Sko-XH4JSnCFXXXXXXXXXXXXXXXXXXXXXXXqMju2WxKGnH3PSMUOSJjKqtlLA=="
#
#   ## Organization is the name of the organization you wish to write to.
    organization = "example.org"
#
#   ## Destination bucket to write into.
    bucket = "pve-from-telegraf"

常见问题处理

[Telegraf] … E! [inputs.proxmox] Error in plugin: search domain is not set ..

未解决

[Telegraf] … unexpected end of JSON input …

Proxmox plugin returns – Error in plugin: unexpected end of JSON input · Issue #8298 · influxdata/telegraf

原因分析:产生该错误的原因很多;

解决方案:在我们场景中,留意 api_token 格式:api_token = “root@pam:5F9DDEEA:KWgo687wl/2CbfvPCFwqs72Q9MCrwc+Af0zedRr7lWo”

参考文献