Telegraf Intel PMT 输入插件完全指南:采集 Intel 平台监控遥测数据
【免费下载链接】telegrafAgent for collecting, processing, aggregating, and writing metrics, logs, and other arbitrary data.项目地址: https://gitcode.com/GitHub_Trending/te/telegraf
导读
本文围绕 Telegraf 的intel_pmt输入插件展开,系统讲解如何通过 Linux 内核驱动枚举并读取 Intel 平台监控技术(Platform Monitoring Technology,PMT)硬件遥测空间,将晶振频率、DRAM 能耗、内存带宽、C-State 驻留、温度、频率直方图、PVP 节流计数器等底层样本转化为 Telegraf 指标。读完本文,你将掌握该插件的运行前置条件、配置参数、按数据类型(datatype)与样本名(sample)过滤指标的方法、全部可用指标的含义,以及从 sysfs 读取到变换公式求值的源码级工作原理。该插件仅支持 Linux(amd64),自 Telegraf v1.28.0 起可用。
插件概述:什么是 Intel PMT
Intel 平台监控技术(Intel PMT)是一套用于枚举和访问受支持设备硬件监控能力的架构。intel_pmt插件通过 Linux 内核驱动采集这类遥测指标,属于 Telegraf 的输入插件(input plugin)类型,标签分类为hardware, system,平台限制为linux。
在 Linux 主线内核中,PMT 的支持由平台驱动(drivers/platform/x86/intel/pmt)提供,它会把 Intel PMT 遥测空间以 sysfs 条目的形式暴露在/sys/class/intel_pmt/下。每个被发现的遥测聚合器(telemetry aggregator)都以一个telem前缀的目录形式呈现,目录内包含一个guid文件,用于标识唯一的 PMT 空间。插件会:
- 发现:扫描
/sys/class/intel_pmt下的遥测源; - 解析:依据 XML 规范文件解析遥测数据布局;
- 变换:读取底层样本/计数器,并根据变换公式(transformation formulas)计算高层样本/计数器;
- 上报:将计算结果作为指标写入 Telegraf。
[!IMPORTANT] PMT 空间位于
/sys/class/intel_pmt,其中的telem文件需要root 权限才能读取。如果 Telegraf 不以 root 身份运行,需要为 Telegraf 可执行文件添加以下 capability:sudo setcap cap_dac_read_search+ep /usr/bin/telegraf
运行前置条件(Requirements)
在启用该插件前,请确认以下条件:
- 拥有受支持的 Intel 设备;
- Linux 内核版本 >= 5.11;
- 内核 5.11–5.14 需要加载
intel_pmt_telemetry模块; - 内核 5.14+ 需要加载
intel_pmt模块。
支持暴露 PMT 的设备包括但不限于:
- 第 4 代 Intel Xeon 可扩展处理器(Sapphire Rapids / SPR)
- 第 6 代 Intel Xeon 可扩展处理器(Granite Rapids / GNR)
每个遥测聚合器目录(telem前缀)内的guid文件标识了唯一的 PMT 空间,该文件对应一组 XML 规范文件,可在 Intel-PMT 仓库中找到。XML 规范必须通过spec配置项指定为指向pmt.xml文件的绝对路径。
插件工作原理:从 sysfs 到指标
结合源码 plugins/inputs/intel_pmt/intel_pmt.go,插件的完整数据流如下:
1. 初始化(Init)
Init()依次执行三步(对应 intel_pmt.go):
checkPmtSpec():校验spec非空、文件可读且为绝对路径。由于pmt.xml中通过basedir引用了 Aggregator 与 Aggregator Interface XML 的相对位置,插件会把spec所在目录作为基准目录(pmtBasePath),见 intel_pmt.go;explorePmtInSysfs():遍历默认路径/sys/class/intel_pmt(常量defaultPmtBasePath),只处理以telem前缀命名的目录;读取每个目录下的guid与telem文件,并通过解析device符号链接定位 PCI BDF(Bus:Device.Function)与numa_node,汇总为每个 GUID 对应的遥测文件信息,见 intel_pmt.go。若找不到任何遥测源,会返回错误“no telemetry sources found”,此时应检查平台是否支持 PMT 或权限是否足够;parseXMLs():解析 XML 规范,详见下文。
2. XML 规范解析(parseXMLs)
pmt.xml是总入口,其结构为<pmt><mappings><mapping guid="..."><xmlset><basedir>...。插件先解析总映射文件,然后针对 sysfs 中实际发现的每个 GUID,依据映射读取两类 XML(见 xml_parser.go):
- Aggregator XML:描述低层遥测样本(
SampleGroup/sample),每个样本由lsb/msb位域、datatypeIDREF和sampleID定义; - Aggregator Interface XML:描述高层聚合样本(
T_AggregatorSample)与变换公式(TransFormation),变换输入通过sampleIDREF引用低层样本,transformREF引用公式。
解析后,插件为每个样本调用calculateMasks()依据msb/lsb预计算位掩码(computeMask,见 xml_parser.go),并把变换公式按TransformID建立索引。
3. 指标采集(Gather)
Gather()按 GUID 并发处理(每个 GUID 一个 goroutine,使用sync.WaitGroup同步),对每个遥测文件:
getSampleValues():每个 Sample Group 占 8 字节,以8 * group.SampleID作为起始偏移;getTelemSample()读取该 8 字节(小端序 uint64),应用掩码并右移Lsb位得到原始样本值,见 intel_pmt.go;aggregateSamples():对每个聚合样本,把其变换输入的sampleIDREF对应的低层样本值代入公式,调用eval()求值(基于github.com/PaesslerAG/gval),然后生成字段与标签写入 Accumulator,见 intel_pmt.go。
求值前的公式预处理transformEquation()会移除$前缀符,并解码 XML 实体(如<→<),见 intel_pmt.go。由于gval不支持十六进制字面量,eval()还会用正则把公式中的0x...统一转换为十进制后再求值,见 intel_pmt.go。
配置详解
插件的完整示例配置位于 plugins/inputs/intel_pmt/sample.conf,基本配置如下:
# Intel Platform Monitoring Technology plugin exposes Intel PMT metrics available through the Intel PMT kernel space. # This plugin ONLY supports Linux. [[inputs.intel_pmt]] ## Filepath to PMT XML within local copies of XML files from PMT repository. ## The filepath should be absolute. spec = "/home/telegraf/Intel-PMT/xml/pmt.xml" ## Enable metrics by their datatype. ## See the Enabling Metrics section in README for more details. ## If empty, all metrics are enabled. ## When used, the alternative option samples_enabled should NOT be used. # datatypes_enabled = [] ## Enable metrics by their name. ## See the Enabling Metrics section in README for more details. ## If empty, all metrics are enabled. ## When used, the alternative option datatypes_enabled should NOT be used. # samples_enabled = []| 配置项 | 类型 | 必填 | 说明 |
|---|---|---|---|
spec | string | 是 | PMT XML 文件的绝对路径(本地 Intel-PMT 仓库 XML 副本中的pmt.xml),例如/home/telegraf/Intel-PMT/xml/pmt.xml。插件校验其非空、可读且为绝对路径(源码见 intel_pmt.go) |
datatypes_enabled | []string | 否 | 按数据类型(datatype,即指标分组)启用指标;为空则启用全部指标。使用该选项时不应同时使用samples_enabled |
samples_enabled | []string | 否 | 按样本名(metric name)启用指标;为空则启用全部指标。使用该选项时不应同时使用datatypes_enabled |
此外,插件同样支持 Telegraf 输入插件的通用全局配置,例如指标修改、标签与字段处理、别名以及插件执行顺序等,详见 docs/CONFIGURATION.md。
启用指标(Enabling metrics)
默认情况下,插件采集所有可用指标。若需限制采集范围,提供了两种互斥的选择方式:
- 按数据类型(datatype)启用:datatype 是指标的组/类,启用后会过滤出该类型下的全部相关指标;
- 按名称(sample name)启用:按指标名精确匹配;对形如
Cx_、CHAx_前缀的按资源维度命名的指标,支持正则式匹配(即只填去前缀后的名称也能匹配到所有核心/CHA 实例)。
注意:同一时刻只能选择一种启用方式,二者不可混用。
从源码层面看(filtering.go):
- datatype 过滤分别作用于 Aggregator XML(
filterAggregatorByDatatype)与 Aggregator Interface XML(filterAggInterfaceByDatatype),按DatatypeIDRef匹配;当一个 Sample Group 内仅保留部分样本时,会重建 group 但保留原SampleID(偏移不变); - sample 过滤(
filterAggregatorBySampleName/filterAggInterfaceBySampleName)通过正则(?P<class>(C|CHA))\d+_(?P<var>[A-Z0-9_]+)$拆分名称,支持“精确名”与“去前缀后的通用名”两种匹配,见 filtering.go; - 若配置的 datatype 或 sample 名称在 XML 中未找到,插件会输出 Warn 日志提示(见 xml_parser.go),便于排查拼写错误。
可用 datatype 与相关指标一览
下表完整列出各 datatype 及其对应的指标(摘自 插件 README):
| Datatype | Metric name | Description |
|---|---|---|
txtal_strap | XTAL_FREQ | Clock rate of the crystal oscillator on this silicon |
tdram_energy | DRAM_ENERGY_LOW | DRAM energy consumed by all DIMMS in all Channels (uJ) |
DRAM_ENERGY_HIGH | DRAM energy consumed by all DIMMS in all Channels (uJ) | |
tbandwidth_32b | C2U_BW | Core to Uncore Bandwidth (per core and per uncore) |
U2C_BW | Uncore to Core Bandwidth (per core and per uncore) | |
PC2_LOW | Time spent in the Package C-State 2 (PC2) | |
PC2_HIGH | Time spent in the Package C-State 2 (PC2) | |
PC6_LOW | Time spent in the Package C-State 6 (PC6) | |
PC6_HIGH | Time spent in the Package C-State 6 (PC6) | |
MEM_RD_BW | Memory Read Bandwidth (per channel) | |
MEM_WR_BW | Memory Write Bandwidth (per channel) | |
DDRT_READ_BW | DDRT Read Bandwidth (per channel) | |
DDRT_WR_BW | DDRT Write Bandwidth (per channel) | |
THRT_COUNT | Number of clock ticks when throttling occurred on IMC channel (per channel) | |
PMSUM | Energy accumulated by IMC channel (per channel) | |
CMD_CNT_CH0 | Command count for IMC channel subchannel 0 (per channel) | |
CMD_CNT_CH1 | Command count for IMC channel subchannel 1 (per channel) | |
tU32.0 | PEM_ANY | Duration for which a core frequency excursion occurred due to a listed or unlisted reason |
PEM_THERMAL | Duration for which a core frequency excursion occurred due to EMTTM | |
PEM_EXT_PROCHOT | Duration for which a core frequency excursion occurred due to an external PROCHOT assertion | |
PEM_PBM | Duration for which a core frequency excursion occurred due to PBM | |
PEM_PL1 | Duration for which a core frequency excursion occurred due to PL1 | |
PEM_RESERVED | PEM Reserved Counter | |
PEM_PL2 | Duration for which a core frequency excursion occurred due to PL2 | |
PEM_PMAX | Duration for which a core frequency excursion occurred due to PMAX | |
tbandwidth_28b | C0Residency | Core C0 Residency (per core) |
C1Residency | Core C1 Residency (per core) | |
tratio | FET | Current Frequency Excursion Threshold. Ratio of the core frequency. |
tbandwidth_24b | UFS_MAX_RING_TRAFFIC | IO Bandwidth for DMI or PCIE port (per port) |
ttemperature | TEMP | Current temperature of a core (per core) |
tU8.0 | VERSION | For SPR, it's 0. New feature versions will uprev this. |
tebb_energy | FIVR_HBM_ENERGY | FIVR HBM Energy in uJ (per HBM) |
tBOOL | OOB_PEM_ENABLE | 0x0 (Default)=Inband interface for PEM is enabled. 0x1=OOB interface for PEM is enabled. |
ENABLE_PEM | 0 (Default): Disable PEM. 1: Enable PEM | |
ANY | Set if a core frequency excursion occurs due to a listed or unlisted reason | |
THERMAL | Set if a core frequency excursion occurs due to any thermal event in core/uncore | |
EXT_PROCHOT | Set if a core frequency excursion occurs due to external PROCHOT assertion | |
PBM | Set if a core frequency excursion occurs due to a power limit (socket RAPL and/or platform RAPL) | |
PL1 | Set if a core frequency excursion occurs due to PL1 input from any interfaces | |
PL2 | Set if a core frequency excursion occurs due to PL2 input from any interfaces | |
PMAX | Set if a core frequency excursion occurs due to PMAX | |
ttsc | ART | TSC Delta HBM (per HBM) |
tproduct_id | PRODUCT_ID | Product ID |
tstring | LOCAL_REVISION | Local Revision ID for this product |
RECORD_TYPE | Record Type | |
tcore_state | EN | Core x is enabled (per core) |
thist_counter | FREQ_HIST_R0 | Frequency histogram range 0 (core in C6) counter (per core) |
FREQ_HIST_R1 | Frequency histogram range 1 (16.67-800 MHz) counter (per core) | |
FREQ_HIST_R2 | Frequency histogram range 2 (801-1200 MHz) counter (per core) | |
FREQ_HIST_R3 | Frequency histogram range 3 (1201-1600 MHz) counter (per core) | |
FREQ_HIST_R4 | Frequency histogram range 4 (1601-2000 MHz) counter (per core) | |
FREQ_HIST_R5 | Frequency histogram range 5 (2001-2400 MHz) counter (per core) | |
FREQ_HIST_R6 | Frequency histogram range 6 (2401-2800 MHz) counter (per core) | |
FREQ_HIST_R7 | Frequency histogram range 7 (2801-3200 MHz) counter (per core) | |
FREQ_HIST_R8 | Frequency histogram range 8 (3201-3600 MHz) counter (per core) | |
FREQ_HIST_R9 | Frequency histogram range 9 (3601-4000 MHz) counter (per core) | |
FREQ_HIST_R10 | Frequency histogram range 10 (4001-4400 MHz) counter (per core) | |
FREQ_HIST_R11 | Frequency histogram range 11 (greater then 4400 MHz) (per core) | |
VOLT_HIST_R0 | Voltage histogram range 0 (less then 602 mV) counter (per core) | |
VOLT_HIST_R1 | Voltage histogram range 1 (602.5-657 mV) counter (per core) | |
VOLT_HIST_R2 | Voltage histogram range 2 (657.5-712 mV) counter (per core) | |
VOLT_HIST_R3 | Voltage histogram range 3 (712.5-767 mV) counter (per core) | |
VOLT_HIST_R4 | Voltage histogram range 4 (767.5-822 mV) counter (per core) | |
VOLT_HIST_R5 | Voltage histogram range 5 (822.5-877 mV) counter (per core) | |
VOLT_HIST_R6 | Voltage histogram range 6 (877.5-932 mV) counter (per core) | |
VOLT_HIST_R7 | Voltage histogram range 7 (932.5-987 mV) counter (per core) | |
VOLT_HIST_R8 | Voltage histogram range 8 (987.5-1042 mV) counter (per core) | |
VOLT_HIST_R9 | Voltage histogram range 9 (1042.5-1097 mV) counter (per core) | |
VOLT_HIST_R10 | Voltage histogram range 10 (1097.5-1152 mV) counter (per core) | |
VOLT_HIST_R11 | Voltage histogram range 11 (greater then 1152 mV) counter (per core) | |
TEMP_HIST_R0 | Temperature histogram range 0 (less then 20°C) counter | |
TEMP_HIST_R1 | Temperature histogram range 1 (20.5-27.5°C) counter | |
TEMP_HIST_R2 | Temperature histogram range 2 (28-35°C) counter | |
TEMP_HIST_R3 | Temperature histogram range 3 (35.5-42.5°C) counter | |
TEMP_HIST_R4 | Temperature histogram range 4 (43-50°C) counter | |
TEMP_HIST_R5 | Temperature histogram range 5 (50.5-57.5°C) counter | |
TEMP_HIST_R6 | Temperature histogram range 6 (58-65°C) counter | |
TEMP_HIST_R7 | Temperature histogram range 7 (65.5-72.5°C) counter | |
TEMP_HIST_R8 | Temperature histogram range 8 (73-80°C) counter | |
TEMP_HIST_R9 | Temperature histogram range 9 (80.5-87.5°C) counter | |
TEMP_HIST_R10 | Temperature histogram range 10 (88-95°C) counter | |
TEMP_HIST_R11 | Temperature histogram range 11 (greater then 95°C) counter | |
tpvp_throttle_counter | PVP_THROTTLE_64 | Counter indicating the number of times the core x was throttled in the last 64 cycles window |
PVP_THROTTLE_1024 | Counter indicating the number of times the core x was throttled in the last 1024 cycles window | |
tpvp_level_res | PVP_LEVEL_RES_128_L0 | Counter indicating the percentage of residency during the last 2 ms measurement for level 0 of this type of CPU instruction |
PVP_LEVEL_RES_128_L1 | Counter indicating the percentage of residency during the last 2 ms measurement for level 1 of this type of CPU instruction | |
PVP_LEVEL_RES_128_L2 | Counter indicating the percentage of residency during the last 2 ms measurement for level 2 of this type of CPU instruction | |
PVP_LEVEL_RES_128_L3 | Counter indicating the percentage of residency during the last 2 ms measurement for level 3 of this type of CPU instruction | |
PVP_LEVEL_RES_256_L0 | Counter indicating the percentage of residency during the last 2 ms measurement for level 0 of AVX256 CPU instructions | |
PVP_LEVEL_RES_256_L1 | Counter indicating the percentage of residency during the last 2 ms measurement for level 1 of AVX256 CPU instructions | |
PVP_LEVEL_RES_256_L2 | Counter indicating the percentage of residency during the last 2 ms measurement for level 2 of AVX256 CPU instructions | |
PVP_LEVEL_RES_256_L3 | Counter indicating the percentage of residency during the last 2 ms measurement for level 3 of AVX256 CPU instructions | |
PVP_LEVEL_RES_512_L0 | Counter indicating the percentage of residency during the last 2 ms measurement for level 0 of AVX512 CPU instructions | |
PVP_LEVEL_RES_512_L1 | Counter indicating the percentage of residency during the last 2 ms measurement for level 1 of AVX512 CPU instructions | |
PVP_LEVEL_RES_512_L2 | Counter indicating the percentage of residency during the last 2 ms measurement for level 2 of AVX512 CPU instructions | |
PVP_LEVEL_RES_512_L3 | Counter indicating the percentage of residency during the last 2 ms measurement for level 3 of AVX512 CPU instructions | |
PVP_LEVEL_RES_TMUL_L0 | Counter indicating the percentage of residency during the last 2 ms measurement for level 0 of TMUL CPU instructions | |
PVP_LEVEL_RES_TMUL_L1 | Counter indicating the percentage of residency during the last 2 ms measurement for level 1 of TMUL CPU instructions | |
PVP_LEVEL_RES_TMUL_L2 | Counter indicating the percentage of residency during the last 2 ms measurement for level 2 of TMUL CPU instructions | |
PVP_LEVEL_RES_TMUL_L3 | Counter indicating the percentage of residency during the last 2 ms measurement for level 3 of TMUL CPU instructions | |
ttsc_timer | TSC_TIMER | OOBMSM TSC (Time Stamp Counter) value |
tnum_en_cha | NUM_EN_CHA | Number of enabled CHAs |
trmid_usage_counter | RMID0_RDT_CMT | CHA x RMID 0 LLC cache line usage counter (per CHA) |
RMID1_RDT_CMT | CHA x RMID 1 LLC cache line usage counter (per CHA) | |
RMID2_RDT_CMT | CHA x RMID 2 LLC cache line usage counter (per CHA) | |
RMID3_RDT_CMT | CHA x RMID 3 LLC cache line usage counter (per CHA) | |
RMID4_RDT_CMT | CHA x RMID 4 LLC cache line usage counter (per CHA) | |
RMID5_RDT_CMT | CHA x RMID 5 LLC cache line usage counter (per CHA) | |
RMID6_RDT_CMT | CHA x RMID 6 LLC cache line usage counter (per CHA) | |
RMID7_RDT_CMT | CHA x RMID 7 LLC cache line usage counter (per CHA) | |
RMID0_RDT_MBM_TOTAL | CHA x RMID 0 total memory transactions counter (per CHA) | |
RMID1_RDT_MBM_TOTAL | CHA x RMID 1 total memory transactions counter (per CHA) | |
RMID2_RDT_MBM_TOTAL | CHA x RMID 2 total memory transactions counter (per CHA) | |
RMID3_RDT_MBM_TOTAL | CHA x RMID 3 total memory transactions counter (per CHA) | |
RMID4_RDT_MBM_TOTAL | CHA x RMID 4 total memory transactions counter (per CHA) | |
RMID5_RDT_MBM_TOTAL | CHA x RMID 5 total memory transactions counter (per CHA) | |
RMID6_RDT_MBM_TOTAL | CHA x RMID 6 total memory transactions counter (per CHA) | |
RMID7_RDT_MBM_TOTAL | CHA x RMID 7 total memory transactions counter (per CHA) | |
RMID0_RDT_MBM_LOCAL | CHA x RMID 0 local memory transactions counter (per CHA) | |
RMID1_RDT_MBM_LOCAL | CHA x RMID 1 local memory transactions counter (per CHA) | |
RMID2_RDT_MBM_LOCAL | CHA x RMID 2 local memory transactions counter (per CHA) | |
RMID3_RDT_MBM_LOCAL | CHA x RMID 3 local memory transactions counter (per CHA) | |
RMID4_RDT_MBM_LOCAL | CHA x RMID 4 local memory transactions counter (per CHA) | |
RMID5_RDT_MBM_LOCAL | CHA x RMID 5 local memory transactions counter (per CHA) | |
RMID6_RDT_MBM_LOCAL | CHA x RMID 6 local memory transactions counter (per CHA) | |
RMID7_RDT_MBM_LOCAL | CHA x RMID 7 local memory transactions counter (per CHA) | |
ttw_unit | TW | Time window. Valid TW range is 0 to 17. The unit is calculated as2.3 * 2^TWms (e.g.2.3 * 2^17ms = ~302 seconds). |
tcore_stress_level | STRESS_LEVEL | Accumulating counter indicating relative stress level for a core (per core) |
过滤配置示例
示例 1:按 datatype 过滤获取 C-State 驻留与温度
以下配置仅启用tbandwidth_28b(C0/C1 驻留)与ttemperature(核心温度)两个数据类型的指标:
[[inputs.intel_pmt]] spec = "/home/telegraf/Intel-PMT/xml/pmt.xml" datatypes_enabled = ["tbandwidth_28b","ttemperature"]示例 2:按 sample 名称过滤获取 C-State 驻留与温度
以下配置仅采集名为C0Residency、C1Residency与Cx_TEMP的样本(其中Cx_TEMP的Cx_前缀表示会匹配到所有核心的 TEMP 样本):
[[inputs.intel_pmt]] spec = "/home/telegraf/Intel-PMT/xml/pmt.xml" samples_enabled = ["C0Residency","C1Residency", "Cx_TEMP"]输出指标与标签(Metrics)
所有指标均携带以下标签:
guid:Intel PMT 空间的唯一 ID;numa_node:采集该样本的 NUMA 节点;pci_bdf:采集该样本的 PCI Bus:Device.Function(BDF);sample_name:采集到的样本名称;sample_group:样本所属的组名;datatype_idref:样本所属的 datatype。
对于 XML 中以Cx_为前缀的样本名(x为核心编号),还会附加标签:
core:该指标对应的核心编号。
对于 XML 中以CHAx_为前缀的样本名(x为 CHA 编号),还会附加标签:
cha:该指标对应的 Caching and Home Agent(CHA)编号。
从实现上看,标签提取由 tags_extraction.go 完成:解析时通过正则^C([0-9]+)_与^CHA([0-9]+)_从样本名中剥离前缀,分别写入core与cha标签,同时把去掉前缀后的名字保留为sample_name,从而让同一资源维度的指标共享一个通用sample_name。字段则统一为value,对应变换公式求值结果。
示例输出
以tpvp_throttle_counter作为 datatype 过滤条件时的输出示例如下(每核心两个指标:PVP_THROTTLE_64与PVP_THROTTLE_1024):
intel_pmt,core=0,datatype_idref=tpvp_throttle_counter,guid=0x87b6fef1,pmt,numa_node=0,pci_bdf=0000:e7:03.1,sample_group=C0_PVP_THROTTLE_64,sample_name=PVP_THROTTLE_64 value=1886465i 1693766334000000000 intel_pmt,core=1,datatype_idref=tpvp_throttle_counter,guid=0x87b6fef1,pmt,numa_node=0,pci_bdf=0000:e7:03.1,sample_group=C1_PVP_THROTTLE_64,sample_name=PVP_THROTTLE_64 value=0i 1693766334000000000 intel_pmt,core=2,datatype_idref=tpvp_throttle_counter,guid=0x87b6fef1,pmt,numa_node=0,pci_bdf=0000:e7:03.1,sample_group=C2_PVP_THROTTLE_64,sample_name=PVP_THROTTLE_64 value=0i 1693766334000000000 intel_pmt,core=4,datatype_idref=tpvp_throttle_counter,guid=0x87b6fef1,pmt,numa_node=0,pci_bdf=0000:e7:03.1,sample_group=C4_PVP_THROTTLE_64,sample_name=PVP_THROTTLE_64 value=1357578i 1693766334000000000 intel_pmt,core=6,datatype_idref=tpvp_throttle_counter,guid=0x87b6fef1,pmt,numa_node=0,pci_bdf=0000:e7:03.1,sample_group=C6_PVP_THROTTLE_64,sample_name=PVP_THROTTLE_64 value=2024801i 1693766334000000000 intel_pmt,core=8,datatype_idref=tpvp_throttle_counter,guid=0x87b6fef1,pmt,numa_node=0,pci_bdf=0000:e7:03.1,sample_group=C8_PVP_THROTTLE_64,sample_name=PVP_THROTTLE_64 value=1390741i 1693766334000000000 intel_pmt,core=0,datatype_idref=tpvp_throttle_counter,guid=0x87b6fef1,pmt,numa_node=0,pci_bdf=0000:e7:03.1,sample_group=C0_PVP_THROTTLE_1024,sample_name=PVP_THROTTLE_1024 value=12977949i 1693766334000000000 intel_pmt,core=4,datatype_idref=tpvp_throttle_counter,guid=0x87b6fef1,pmt,numa_node=0,pci_bdf=0000:e7:03.1,sample_group=C4_PVP_THROTTLE_1024,sample_name=PVP_THROTTLE_1024 value=7180524i 1693766334000000000 intel_pmt,core=6,datatype_idref=tpvp_throttle_counter,guid=0x87b6fef1,pmt,numa_node=0,pci_bdf=0000:e7:03.1,sample_group=C6_PVP_THROTTLE_1024,sample_name=PVP_THROTTLE_1024 value=8667263i 1693766334000000000 intel_pmt,core=8,datatype_idref=tpvp_throttle_counter,guid=0x87b6fef1,pmt,numa_node=0,pci_bdf=0000:e7:03.1,sample_group=C8_PVP_THROTTLE_1024,sample_name=PVP_THROTTLE_1024 value=5945851i 1693766334000000000从输出可以看到,guid、numa_node、pci_bdf标识了具体的遥测空间与物理位置,core标签区分核心维度,未产生采样的核心(值为0)同样会被上报,便于下游做整体聚合与离群检测。
源码级深入:过滤、求值与位域解析
- 位域解析:低层样本按 8 字节对齐存放在遥测缓冲区中,插件依据 XML 中每个样本的
lsb/msb计算掩码mask(见 xml_parser.go),读取时执行(data & mask) >> lsb提取有效位(见 intel_pmt.go)。这保证了不同位宽、不同起始位的样本可以被精确切分。 - 变换公式求值:高层指标并非直接读取,而是通过
TransFormation公式对若干低层样本计算得到。公式中的变量以$前缀占位(如$a),XML 中的实体(&、<、>)在预处理阶段被解码,十六进制常量被转换为十进制,最终交由 gval 表达式引擎求值(见 intel_pmt.go)。相关行为在 intel_pmt_test.go 中有TestTransformEquation与TestEval等用例覆盖。 - 指标过滤:datatype 与 sample 两种过滤在解析 XML 时即生效(见 xml_parser.go),未被选中的样本不会进入后续求值,从而在采集阶段就减少计算与输出量。
- 平台降级:插件通过构建标签限定仅在
linux && amd64下实现真正逻辑;在非 Linux 或非 amd64 平台,intel_pmt_notamd64linux.go 提供空实现并输出“Current platform is not supported”警告,避免启动失败。 - 插件注册:插件通过 plugins/inputs/all/intel_pmt.go 以
intel_pmt名称注册进 Telegraf 输入插件集合,编译时可借助自定义构建(custom build)按需裁剪。
使用注意事项
- 权限:非 root 运行 Telegraf 时,务必通过
sudo setcap cap_dac_read_search+ep /usr/bin/telegraf赋予读取 PMT 空间所需的 capability,否则会因无法读取telem文件而采集失败; - 内核与模块:内核需 >= 5.11,且依据内核版本加载
intel_pmt_telemetry(5.11–5.14)或intel_pmt(5.14+)模块; - spec 路径:
spec必须指向绝对路径下的pmt.xml,且该 XML 引用的 Aggregator / Aggregator Interface XML 需按basedir相对布局放置在同一目录树内; - 过滤互斥:
datatypes_enabled与samples_enabled不可同时启用;配置的名称未匹配到时,插件会输出 Warn 日志,应核对 XML 中实际的 datatype 与样本名拼写; - 平台限制:该插件只支持 Linux 平台,且实际采集逻辑仅面向 amd64 架构。
至此,你已经可以从零开始配置intel_pmt插件,按需裁剪指标,并理解其从内核 sysfs 到 Telegraf 指标输出的完整链路。更多关于输入插件通用配置(标签、字段处理、采样间隔、别名等)的说明可参考 docs/CONFIGURATION.md。
【免费下载链接】telegrafAgent for collecting, processing, aggregating, and writing metrics, logs, and other arbitrary data.项目地址: https://gitcode.com/GitHub_Trending/te/telegraf
创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考