Libvirt 输入插件
此插件使用 libvirt 虚拟化 API,收集有关系统上虚拟化客户机的统计信息。指标直接从主机系统上的虚拟机监视器收集,因此 Telegraf 无需安装和配置在客户机系统上。
引入于: Telegraf v1.25.0 标签: server 操作系统支持: all
要求
插件正常运行需要主机系统已
- 为主机 CPU 启用了虚拟化选项
- 安装并运行了 libvirtd 及其依赖项
- 安装并运行了 qemu hypervisor
- 至少一台虚拟机用于统计监控
全局配置选项
插件支持其他全局和插件配置设置,用于修改指标、标签和字段,创建别名以及配置插件顺序等任务。更多详情请参阅 CONFIGURATION.md。
配置
# The libvirt plugin collects statistics from virtualized guests using virtualization libvirt API.
[[inputs.libvirt]]
## Domain names from which libvirt gather statistics.
## By default (empty or missing array) the plugin gather statistics from each domain registered in the host system.
# domains = []
## Libvirt connection URI with hypervisor.
## The plugin supports multiple transport protocols and approaches which are configurable via the URI.
## The general URI form: driver[+transport]://[username@]()[:port]/[path]()
## Supported transport protocols: ssh, tcp, tls, unix
## URI examples for each type of transport protocol:
## 1. SSH: qemu+ssh://<USER@IP_OR_HOSTNAME>/system?keyfile=/<PATH_TO_PRIVATE_KEY>&known_hosts=/<PATH_TO_known_hosts>
## 2. TCP: qemu+tcp://<IP_OR_HOSTNAME>/system
## 3. TLS: qemu+tls://<HOSTNAME>/system?pkipath=/certs_dir/<COMMON_LOCATION_OF_CACERT_AND_SERVER_CLIENT_CERTS>
## 4. UNIX: qemu+unix:///system?socket=/<PATH_TO_libvirt-sock>
## Default URI is qemu:///system
# libvirt_uri = "qemu:///system"
## Statistics groups for which libvirt plugin will gather statistics.
## Supported statistics groups: state, cpu_total, balloon, vcpu, interface, block, perf, iothread, memory, dirtyrate
## Empty array means no metrics for statistics groups will be exposed by the plugin.
## By default the plugin will gather all available statistics.
# statistics_groups = ["state", "cpu_total", "balloon", "vcpu", "interface", "block", "perf", "iothread", "memory", "dirtyrate"]
## A list containing additional statistics to be exposed by libvirt plugin.
## Supported additional statistics: vcpu_mapping
## By default (empty or missing array) the plugin will not collect additional statistics.
# additional_statistics = []相关链接
在出现以下一种或多种情况时
- 全局 Telegraf 变量
interval设置了较低的值(例如 1s), - 监控了大量虚拟机,
- 连接插件与 hypervisor 的介质效率低下,
日志中可能会出现以下警告:Collection took longer than expected。
在这种情况下,应在插件配置中设置 interval。其值应根据插件的运行时环境进行调整。
示例
[[inputs.libvirt]]
interval = "30s"示例配置
[[inputs.libvirt]]
domain_names = ["ubuntu_20"]
libvirt_uri = "qemu:///system"
libvirt_metrics = ["state", "interface"]
additional_statistics = ["vcpu_mapping"]Metrics
请参阅下表了解插件生成的指标列表。
确切的指标格式取决于 libvirt 报告的统计信息,这可能因您系统上 libvirt 的版本而异。
指标分为以下几组统计信息
- state
- cpu_total
- balloon
- vcpu
- net
- perf
- block
- iothread
- memory
- dirtyrate
- vcpu_mapping - 附加统计信息
插件中的统计信息组对应于使用 virsh domstats 命令直接从 libvirtd 读取的指标分组。有关指标的更多详细信息,请参阅以下链接。
| 统计组 | 指标名称 | 公开的 Telegraf 字段 | 描述 |
|---|---|---|---|
| state | state.state | state | 虚拟机的状态,以 virDomainState 枚举的数字形式返回。 |
| state.reason | 原因 | 进入给定状态的原因,以 virDomain*Reason 枚举的整数形式返回,对应于给定状态。 | |
| cpu_total | cpu.time | time | 此域花费的总 CPU 时间(以纳秒为单位)。 |
| cpu.user | user | 花费的用户 CPU 时间(以纳秒为单位)。 | |
| cpu.system | system | 花费的系统 CPU 时间(以纳秒为单位)。 | |
| cpu.haltpoll.success.time | haltpoll_success_time | CPU halt polling success 时间(以纳秒为单位)。 | |
| cpu.haltpoll.fail.time | haltpoll_fail_time | CPU halt polling fail 时间(以纳秒为单位)。 | |
| cpu.cache.monitor.count | count | 此域的缓存监视器数量。 | |
| cpu.cache.monitor.<num>.name | name | 缓存监视器 <num> 的名称(对于 4.14 及以上版本的内核不可用)。 | |
| cpu.cache.monitor.<num>.vcpus | vcpus | 缓存监视器 <num> 的 vCPU 列表(对于 4.14 及以上版本的内核不可用)。 | |
| cpu.cache.monitor.<num>.bank.count | bank_count | 缓存监视器 <num> 中的缓存银行数量(对于 4.14 及以上版本的内核不可用)。 | |
| cpu.cache.monitor.<num>.bank.<index>.id | id | 主机为缓存监视器 <num> 中的银行 <index> 分配的缓存 ID(对于 4.14 及以上版本的内核不可用)。 | |
| cpu.cache.monitor.<num>.bank.<index>.bytes | bytes | 域在缓存银行 <index> 上使用的最后一级缓存的字节数(对于 4.14 及以上版本的内核不可用)。 | |
| balloon | balloon.current | current | 当前使用的内存量(以 KiB 为单位)。 |
| balloon.maximum | maximum | 允许的最大内存量(以 KiB 为单位)。 | |
| balloon.swap_in | swap_in | 从交换空间读取的数据量(以 KiB 为单位)。 | |
| balloon.swap_out | swap_out | 写入交换空间的总内存量(以 KiB 为单位)。 | |
| balloon.major_fault | major_fault | 需要磁盘 IO 的页面错误次数。 | |
| balloon.minor_fault | minor_fault | 其他页面错误次数。 | |
| balloon.unused | unused | 系统剩余未使用的内存量(以 KiB 为单位)。 | |
| balloon.available | available | 域可见的可用内存量(以 KiB 为单位)。 | |
| balloon.rss | rss | 运行域进程的驻留集大小(以 KiB 为单位)。 | |
| balloon.usable | usable | 可以通过 balloon 恢复且不会导致主机交换的内存量(以 KiB 为单位)。 | |
| balloon.last-update | last_update | 统计信息最后更新的时间戳(以秒为单位)。 | |
| balloon.disk_caches | disk_caches | 无需额外 I/O 即可恢复的内存量,通常为磁盘(以 KiB 为单位)。 | |
| balloon.hugetlb_pgalloc | hugetlb_pgalloc | 通过 virtio balloon 从域内部成功分配的大页数。 | |
| balloon.hugetlb_pgfail | hugetlb_pgfail | 通过 virtio balloon 从域内部分配大页失败的次数。 | |
| vcpu | vcpu.current | current | 当前在线的虚拟 CPU 数量。 |
| vcpu.maximum | maximum | 在线虚拟 CPU 的最大数量。 | |
| vcpu.<num>.state | state | 虚拟 CPU <num> 的状态,以 virVcpuState 枚举的数字形式返回。 | |
| vcpu.<num>.time | time | 虚拟 CPU <num> 花费的时间(以微秒为单位)。 | |
| vcpu.<num>.wait | wait | 虚拟 CPU <num> 等待 I/O 所花费的时间(以微秒为单位)。 | |
| vcpu.<num>.halted | halted | 虚拟 CPU <num> 是否已停止:是或否(可能表示处理器空闲甚至已禁用,具体取决于架构)。 | |
| vcpu.<num>.halted | halted_i | 虚拟 CPU <num> 是否已停止:1(表示“是”)或 0(表示其他值)(可能表示处理器空闲甚至已禁用,具体取决于架构)。 | |
| vcpu.<num>.delay | delay | vCPU <num> 线程被主机调度程序排队但正在队列中等待而不是运行的时间。暴露给 VM 作为窃取时间。 | |
| — | cpu_id | 有关将 vcpu_id 映射到 cpu_id(物理 CPU 的 ID)的信息。仅当 statistics_group 包含 vcpu 且 additional_statistics 包含 vcpu_mapping(在配置中)时才应公开。 | |
| interface | net.count | count | 此域上的网络接口数量。 |
| net.<num>.name | name | 接口 <num> 的名称。 | |
| net.<num>.rx.bytes | rx_bytes | 接收的字节数。 | |
| net.<num>.rx.pkts | rx_pkts | 接收的包数。 | |
| net.<num>.rx.errs | rx_errs | 接收错误数。 | |
| net.<num>.rx.drop | rx_drop | 丢弃的接收包数。 | |
| net.<num>.tx.bytes | tx_bytes | 传输的字节数。 | |
| net.<num>.tx.pkts | tx_pkts | 传输的包数。 | |
| net.<num>.tx.errs | tx_errs | 传输错误数。 | |
| net.<num>.tx.drop | tx_drop | 丢弃的传输包数。 | |
| perf | perf.cmt | cmt | 当前使用的缓存大小(以字节为单位),对于 4.14 及以上版本的内核不可用。 |
| perf.mbmt | mbmt | 来自一个缓存级别的总系统带宽,对于 4.14 及以上版本的内核不可用。 | |
| perf.mbml | mbml | 内存控制器的内存流量带宽,对于 4.14 及以上版本的内核不可用。 | |
| perf.cpu_cycles | cpu_cycles | CPU 周期数(总共/已elapsed)。 | |
| perf.instructions | instructions | 指令数。 | |
| perf.cache_references | cache_references | 缓存命中数。 | |
| perf.cache_misses | cache_misses | 缓存未命中数。 | |
| perf.branch_instructions | branch_instructions | 分支指令数。 | |
| perf.branch_misses | branch_misses | 分支未命中数。 | |
| perf.bus_cycles | bus_cycles | 总线周期数。 | |
| perf.stalled_cycles_frontend | stalled_cycles_frontend | 前端 CPU 停止周期数。 | |
| perf.stalled_cycles_backend | stalled_cycles_backend | 后端 CPU 停止周期数。 | |
| perf.ref_cpu_cycles | ref_cpu_cycles | 参考 CPU 周期数。 | |
| perf.cpu_clock | cpu_clock | CPU 时钟计数。 | |
| perf.task_clock | task_clock | 任务时钟计数。 | |
| perf.page_faults | page_faults | 页面错误计数。 | |
| perf.context_switches | context_switches | 上下文切换计数。 | |
| perf.cpu_migrations | cpu_migrations | CPU 迁移计数。 | |
| perf.page_faults_min | page_faults_min | 次要页面错误计数。 | |
| perf.page_faults_maj | page_faults_maj | 主要页面错误计数。 | |
| perf.alignment_faults | alignment_faults | 对齐错误计数。 | |
| perf.emulation_faults | emulation_faults | 仿真错误计数。 | |
| block | block.count | count | 列出的块设备数量。 |
| block.<num>.name | name | 块设备 <num> 的目标名称(如果存在 --backing,则多个条目具有相同的名称)。 | |
| block.<num>.backingIndex | backingIndex | 当存在 --backing 时,与域 XML 中列出的 backing 文件的 <backingStore> 索引匹配。 | |
| block.<num>.path | path | 块设备 <num> 的文件源,如果它是本地文件或块设备。 | |
| block.<num>.rd.reqs | rd_reqs | 读取请求数。 | |
| block.<num>.rd.bytes | rd_bytes | 读取字节数。 | |
| block.<num>.rd.times | rd_times | 读取花费的总时间(纳秒)。 | |
| block.<num>.wr.reqs | wr_reqs | 写入请求数。 | |
| block.<num>.wr.bytes | wr_bytes | 写入的字节数。 | |
| block.<num>.wr.times | wr_times | 写入花费的总时间(纳秒)。 | |
| block.<num>.fl.reqs | fl_reqs | 总刷新请求数。 | |
| block.<num>.fl.times | fl_times | 缓存刷新花费的总时间(纳秒)。 | |
| block.<num>.errors | errors | 仅 Xen:'oo_req' 值。 | |
| block.<num>.allocation | allocation | 已写入扇区的偏移量(以字节为单位)。 | |
| block.<num>.capacity | capacity | 源文件的逻辑大小(以字节为单位)。 | |
| block.<num>.physical | physical | 源文件的物理大小(以字节为单位)。 | |
| block.<num>.threshold | threshold | 用于触发 VIR_DOMAIN_EVENT_ID_BLOCK_THRESHOLD 事件的阈值(以字节为单位)。请参阅 domblkthreshold。 | |
| iothread | iothread.count | count | 后续列表中 IOThreads 的最大数量(作为无符号整数)。列表中的每个 IOThread 都将使用其 iothread_id 值作为 <id>。如果不支持轮询值,则 <id> 条目可能少于 iothread.count 值。 |
| iothread.<id>.poll-max-ns | poll_max_ns | <id> IOThread 使用的最大轮询时间(以纳秒为单位)。值为 0(零)表示轮询已禁用。 | |
| iothread.<id>.poll-grow | poll_grow | 轮询时间增长值。值为 0(零)表示由 hypervisor 管理增长。 | |
| iothread.<id>.poll-shrink | poll_shrink | 轮询时间收缩值。值为 0(零)表示由 hypervisor 管理收缩。 | |
| memory | memory.bandwidth.monitor.count | count | 此域的内存带宽监视器数量(对于 4.14 及以上版本的内核不可用)。 |
| memory.bandwidth.monitor.<num>.name | name | 监视器 <num> 的名称(对于 4.14 及以上版本的内核不可用)。 | |
| memory.bandwidth.monitor.<num>.vcpus | vcpus | 监视器 <num> 的 vCPU 列表(对于 4.14 及以上版本的内核不可用)。 | |
| memory.bandwidth.monitor.<num>.node.count | node_count | 监视器 <num> 中的内存控制器数量(对于 4.14 及以上版本的内核不可用)。 | |
| memory.bandwidth.monitor.<num>.node.<index>.id | id | 主机为监视器 <num> 中的控制器 <index> 分配的内存控制器 ID(对于 4.14 及以上版本的内核不可用)。 | |
| memory.bandwidth.monitor.<num>.node.<index>.bytes.local | bytes_local | 通过与已安排的主 CPU 关联的同一处理器中的内存控制器传递的 @vcpus 消耗的累积字节数(对于 4.14 及以上版本的内核不可用)。 | |
| memory.bandwidth.monitor.<num>.node.<index>.bytes.total | bytes_total | 通过所有内存控制器(本地或远程控制器)传递的 @vcpus 消耗的总字节数(对于 4.14 及以上版本的内核不可用)。 | |
| dirtyrate | dirtyrate.calc_status | calc_status | 上次内存脏速率计算的状态,以 virDomainDirtyRateStatus 枚举的数字形式返回。 |
| dirtyrate.calc_start_time | calc_start_time the | 上次内存脏速率计算的开始时间。 | |
| dirtyrate.calc_period | calc_period | 上次内存脏速率计算的周期。 | |
| dirtyrate.megabytes_per_second | megabytes_per_second | 计算出的内存脏速率(以 MiB/s 为单位)。 | |
| dirtyrate.calc_mode | calc_mode | 上次测量使用的计算模式(页面采样/脏位图/脏环)。 | |
| dirtyrate.vcpu.<num>.megabytes_per_second | megabytes_per_second | 虚拟 CPU 的计算出的内存脏速率(以 MiB/s 为单位)。 |
附加统计信息
| 统计组 | 公开的 Telegraf 标签 | 公开的 Telegraf 字段 | 描述 |
|---|---|---|---|
| vcpu_mapping | vcpu_id | — | 虚拟 CPU 的 ID。 |
| — | cpu_id | 物理 CPU ID 的逗号分隔列表(作为字符串公开)。 |
示例输出
libvirt_cpu_affinity,domain_name=U22,host=localhost,vcpu_id=0 cpu_id="1,2,3" 1662383707000000000
libvirt_cpu_affinity,domain_name=U22,host=localhost,vcpu_id=1 cpu_id="1,2,3,4,5,6,7,8,9,10" 1662383707000000000
libvirt_balloon,domain_name=U22,host=localhost current=4194304i,maximum=4194304i,swap_in=0i,swap_out=0i,major_fault=0i,minor_fault=0i,unused=3928628i,available=4018480i,rss=1036012i,usable=3808724i,last_update=1654611373i,disk_caches=68820i,hugetlb_pgalloc=0i,hugetlb_pgfail=0i 1662383709000000000
libvirt_vcpu_total,domain_name=U22,host=localhost maximum=2i,current=2i 1662383709000000000
libvirt_vcpu,domain_name=U22,host=localhost,vcpu_id=0 state=1i,time=17943740000000i,wait=0i,halted="no",halted_i=0i,delay=14246609424i,cpu_id=1i 1662383709000000000
libvirt_vcpu,domain_name=U22,host=localhost,vcpu_id=1 state=1i,time=18288400000000i,wait=0i,halted="yes",halted_i=1i,delay=12902231142i,cpu_id=3i 1662383709000000000
libvirt_net_total,domain_name=U22,host=localhost count=1i 1662383709000000000
libvirt_net,domain_name=U22,host=localhost,interface_id=0 name="vnet0",rx_bytes=110i,rx_pkts=1i,rx_errs=0i,rx_drop=31007i,tx_bytes=0i,tx_pkts=0i,tx_errs=0i,tx_drop=0i 1662383709000000000
libvirt_block_total,domain_name=U22,host=localhost count=1i 1662383709000000000
libvirt_block,domain_name=U22,host=localhost,block_id=0 rd=17337818234i,path=name="vda",backingIndex=1i,path="/tmp/ubuntu_image.img",rd_reqs=11354i,rd_bytes=330314752i,rd_times=6240559566i,wr_reqs=52440i,wr_bytes=1183828480i,wr_times=21887150375i,fl_reqs=32250i,fl_times=23158998353i,errors=0i,allocation=770048000i,capacity=2361393152i,physical=770052096i,threshold=2147483648i
libvirt_perf,domain_name=U22,host=localhost cmt=19087360i,mbmt=77168640i,mbml=67788800i,cpu_cycles=29858995122i,instructions=0i,cache_references=3053301695i,cache_misses=609441024i,branch_instructions=2623890194i,branch_misses=103707961i,bus_cycles=188105628i,stalled_cycles_frontend=0i,stalled_cycles_backend=0i,ref_cpu_cycles=30766094039i,cpu_clock=25166642695i,task_clock=25263578917i,page_faults=2670i,context_switches=294284i,cpu_migrations=17949i,page_faults_min=2670i,page_faults_maj=0i,alignment_faults=0i,emulation_faults=0i 1662383709000000000
libvirt_dirtyrate,domain_name=U22,host=localhost calc_status=2i,calc_start_time=348414i,calc_period=1i,dirtyrate.megabytes_per_second=4i,calc_mode="dirty-ring" 1662383709000000000
libvirt_dirtyrate_vcpu,domain_name=U22,host=localhost,vcpu_id=0 megabytes_per_second=2i 1662383709000000000
libvirt_dirtyrate_vcpu,domain_name=U22,host=localhost,vcpu_id=1 megabytes_per_second=2i 1662383709000000000
libvirt_state,domain_name=U22,host=localhost state=1i,reason=5i 1662383709000000000
libvirt_cpu,domain_name=U22,host=localhost time=67419144867000i,user=63886161852000i,system=3532983015000i,haltpoll_success_time=516907915i,haltpoll_fail_time=2727253643i 1662383709000000000
libvirt_cpu_cache_monitor_total,domain_name=U22,host=localhost count=1i 1662383709000000000
libvirt_cpu_cache_monitor,domain_name=U22,host=localhost,cache_monitor_id=0 name="any_name_vcpus_0-3",vcpus="0-3",bank_count=1i 1662383709000000000
libvirt_cpu_cache_monitor_bank,domain_name=U22,host=localhost,cache_monitor_id=0,bank_index=0 id=0i,bytes=5406720i 1662383709000000000
libvirt_iothread_total,domain_name=U22,host=localhost count=1i 1662383709000000000
libvirt_iothread,domain_name=U22,host=localhost,iothread_id=0 poll_max_ns=32768i,poll_grow=0i,poll_shrink=0i 1662383709000000000
libvirt_memory_bandwidth_monitor_total,domain_name=U22,host=localhost count=2i 1662383709000000000
libvirt_memory_bandwidth_monitor,domain_name=U22,host=localhost,memory_bandwidth_monitor_id=0 name="any_name_vcpus_0-4",vcpus="0-4",node_count=2i 1662383709000000000
libvirt_memory_bandwidth_monitor,domain_name=U22,host=localhost,memory_bandwidth_monitor_id=1 name="vcpus_7",vcpus="7",node_count=2i 1662383709000000000
libvirt_memory_bandwidth_monitor_node,domain_name=U22,host=localhost,memory_bandwidth_monitor_id=0,controller_index=0 id=0i,bytes_total=10208067584i,bytes_local=4807114752i 1662383709000000000
libvirt_memory_bandwidth_monitor_node,domain_name=U22,host=localhost,memory_bandwidth_monitor_id=0,controller_index=1 id=1i,bytes_total=8693735424i,bytes_local=5850161152i 1662383709000000000
libvirt_memory_bandwidth_monitor_node,domain_name=U22,host=localhost,memory_bandwidth_monitor_id=1,controller_index=0 id=0i,bytes_total=853811200i,bytes_local=290701312i 1662383709000000000
libvirt_memory_bandwidth_monitor_node,domain_name=U22,host=localhost,memory_bandwidth_monitor_id=1,controller_index=1 id=1i,bytes_total=406044672i,bytes_local=229425152i 1662383709000000000此页面是否有帮助?
感谢您的反馈!
支持和反馈
感谢您成为我们社区的一员!我们欢迎并鼓励您对 Telegraf 和本文档提出反馈和 bug 报告。要获取支持,请使用以下资源
具有年度合同或支持合同的客户可以 联系 InfluxData 支持。