Windows Management Instrumentation 输入插件
此插件使用 Windows Management Instrumentation 类查询信息或调用方法。这允许捕获和过滤通过 WMI 公开的几乎任何配置或度量值。
Telegraf 服务用户至少必须具有 读取 要查询的 WMI 命名空间的权限。
引入于: Telegraf v1.26.0 标签: system OS 支持: windows
全局配置选项
插件支持其他全局和插件配置设置,用于修改指标、标签和字段,创建别名以及配置插件顺序等任务。更多详情请参阅 CONFIGURATION.md。
Secret-store 支持
此插件支持从 secret-stores 获取 username 和 password 选项的密钥。有关如何使用它们的更多详细信息,请参阅 secret-store 文档。
配置
# Input plugin to query Windows Management Instrumentation
# This plugin ONLY supports Windows
[[inputs.win_wmi]]
## Hostname or IP for remote connections, by default the local machine is queried
# host = ""
## Credentials for the connection, by default no credentials are used
# username = ""
# password = ""
## WMI query to execute, multiple methods are possible
[[inputs.win_wmi.query]]
## Namespace, class and a list of properties to use in the WMI query
namespace = "root\\cimv2"
class_name = "Win32_Volume"
properties = ["Name", "Capacity", "FreeSpace"]
## Optional WHERE clause for the WQL query
# filter = 'NOT Name LIKE "\\\\?\\%"'
## Returned properties to use as tags instead of fields
# tag_properties = ["Name"]
# ## WMI method to invoke, multiple methods are possible
# [[inputs.win_wmi.method]]
# ## WMI namespace, class and method to use
# namespace = 'root\default'
# class_name = "StdRegProv"
# method = "GetStringValue"
# ## Returned WMI method values to use as tags instead of fields
# # tag_properties = ["ReturnValue"]
# ## Named arguments for the method call
# [inputs.win_wmi.method.arguments]
# hDefKey = '2147483650'
# sSubKeyName = 'Software\Microsoft\windows NT\CurrentVersion'
# sValueName = 'ProductName'
# ## Mapping of the name of the returned property to a field-name
# [inputs.win_wmi.method.fields]
# sValue = "product_name"远程执行
此插件允许在远程主机上执行查询和方法。为此,您需要提供 host(主机名或 IP 地址)以及执行查询或方法所需的凭据。
请注意,远程计算机必须配置为允许远程执行,并且用户需要具有执行查询或方法的足够权限!请参阅 Microsoft 指南了解如何执行此操作,并首先使用 Get-WmiObject 方法测试连接。
查询设置
要发出查询,您需要为 WMI 查询提供 namespace(例如 root\cimv2)和 class_name(例如 Win32_Processor)。此外,您还需要定义要输出的 properties。星号(*)将输出查询提供的所有值。
filter 设置指定一个将在 WMI 查询语言 (WQL) 中传递给查询的 WHERE 子句。有关更多信息,请参阅 WHERE 子句。
tag_properties 允许提供一个已返回的属性列表,这些属性将被用作度量值的标签而不是字段。
举个例子
[[inputs.win_wmi]]
[[inputs.win_wmi.query]]
namespace = "root\\cimv2"
class_name = "Win32_Processor"
properties = ["Name"]相当于执行
Get-WmiObject -Namespace "root\cimv2" -Class "Win32_Processor" -Property "Name"方法设置
要调用方法,您需要提供 namespace(例如 root\default)、class_name(例如 StdRegProv)和 method 名称(例如 GetStringValue)以便调用该方法。此外,您可能需要将 arguments 作为键值对提供给该方法。参数的数量和类型取决于上面指定的方法。
请参阅 WMI 参考了解可用的方法及其参数。
tag_properties 允许提供一个已返回的属性列表,这些属性将被用作度量值的标签而不是字段。
举个例子
[[inputs.win_wmi]]
[[inputs.win_wmi.method]]
namespace = 'root\default'
class_name = "StdRegProv"
method = "GetStringValue"
[inputs.win_wmi.method.arguments]
hDefKey = '2147483650'
sSubKeyName = 'Software\Microsoft\windows NT\CurrentVersion'
sValueName = 'ProductName'相当于执行
Invoke-WmiMethod -Namespace "root\default" -Class "StdRegProv" -Name "GetStringValue" @(2147483650,"Software\Microsoft\windows NT\CurrentVersion", "ProductName")故障排除
错误
如果您收到关于无效 WMI 命名空间、类或属性的错误,请使用 Get-WmiObject 或 Get-CimInstance PowerShell 命令来验证其有效性。例如
Get-WmiObject -Namespace root\cimv2 -Class Win32_Volume -Property Capacity, FreeSpace, Name -Filter 'NOT Name LIKE "\\\\?\\%"'Get-CimInstance -Namespace root\cimv2 -ClassName Win32_Volume -Property Capacity, FreeSpace, Name -Filter 'NOT Name LIKE "\\\\?\\%"'数据类型
某些 WMI 类将为字段返回不正确的数据类型。在这些情况下,有必要使用处理器来转换数据类型。例如,Win32_Volume 类的 Capacity 和 FreeSpace 属性必须转换为整数
[[processors.converter]]
namepass = ["win_wmi_Win32_Volume"]
[processors.converter.fields]
integer = ["Capacity", "FreeSpace"]Metrics
默认情况下,WMI 类属性的值用作度量字段。如果类属性的值在 tag_properties 中指定,则该值将作为标签包含在度量值中。
示例输出
物理内存
此查询提供每个物理内存设备的速率和容量的度量,以及描述每个设备的制造商、部件号和设备定位器的标签。
[[inputs.win_wmi]]
name_prefix = "win_wmi_"
[[inputs.win_wmi.query]]
namespace = "root\\cimv2"
class_name = "Win32_PhysicalMemory"
properties = [
"Name",
"Capacity",
"DeviceLocator",
"Manufacturer",
"PartNumber",
"Speed",
]
tag_properties = ["Name","DeviceLocator","Manufacturer","PartNumber"]示例输出
win_wmi_Win32_PhysicalMemory,DeviceLocator=DIMM1,Manufacturer=80AD000080AD,Name=Physical\ Memory,PartNumber=HMA82GU6DJR8N-XN\ \ \ \ ,host=foo Capacity=17179869184i,Speed=3200i 1654269272000000000处理器
此查询提供每个物理处理器的核心数量的度量。由于 WMI 类的 Name 属性默认包含在内,因此度量值还将包含描述每个 CPU 型号的标签值。
[[inputs.win_wmi]]
name_prefix = "win_wmi_"
[[inputs.win_wmi.query]]
namespace = "root\\cimv2"
class_name = "Win32_Processor"
properties = ["Name","NumberOfCores"]
tag_properties = ["Name"]示例输出
win_wmi_Win32_Processor,Name=Intel(R)\ Core(TM)\ i9-10900\ CPU\ @\ 2.80GHz,host=foo NumberOfCores=10i 1654269272000000000计算机系统
此查询提供计算机上套接字处理器数量、每个处理器上的逻辑核心数量以及总物理内存的度量。度量值包含计算机域、制造商和型号的标签值。
[[inputs.win_wmi]]
name_prefix = "win_wmi_"
[[inputs.win_wmi.query]]
namespace = "root\\cimv2"
class_name = "Win32_ComputerSystem"
properties = [
"Name",
"Domain",
"Manufacturer",
"Model",
"NumberOfLogicalProcessors",
"NumberOfProcessors",
"TotalPhysicalMemory"
]
tag_properties = ["Name","Domain","Manufacturer","Model"]示例输出
win_wmi_Win32_ComputerSystem,Domain=company.com,Manufacturer=Lenovo,Model=X1\ Carbon,Name=FOO,host=foo NumberOfLogicalProcessors=20i,NumberOfProcessors=1i,TotalPhysicalMemory=34083926016i 1654269272000000000操作系统
此查询提供分页文件的可用空间、操作系统的可用虚拟内存、计算机上安装的操作系统 SKU 以及 Windows 产品类型的度量。操作系统架构作为标签值包含在内,以描述安装是 32 位还是 64 位。
[[inputs.win_wmi]]
name_prefix = "win_wmi_"
[[inputs.win_wmi.query]]
class_name = "Win32_OperatingSystem"
namespace = "root\\cimv2"
properties = [
"Name",
"Caption",
"FreeSpaceInPagingFiles",
"FreeVirtualMemory",
"OperatingSystemSKU",
"OSArchitecture",
"ProductType"
]
tag_properties = ["Name","Caption","OSArchitecture"]示例输出
win_wmi_Win32_OperatingSystem,Caption=Microsoft\ Windows\ 10\ Enterprise,InstallationType=Client,Name=Microsoft\ Windows\ 10\ Enterprise|C:\WINDOWS|\Device\Harddisk0\Partition3,OSArchitecture=64-bit,host=foo FreeSpaceInPagingFiles=5203244i,FreeVirtualMemory=16194496i,OperatingSystemSKU=4i,ProductType=1i 1654269272000000000故障转移群集
此查询提供一个布尔度量,描述群集的动态仲裁是否启用。度量值的标签值还包括 Windows Server 故障转移群集的名称以及使用的仲裁类型。
[[inputs.win_wmi]]
name_prefix = "win_wmi_"
[[inputs.win_wmi.query]]
namespace = "root\\mscluster"
class_name = "MSCluster_Cluster"
properties = [
"Name",
"QuorumType",
"DynamicQuorumEnabled"
]
tag_properties = ["Name","QuorumType"]示例输出
win_wmi_MSCluster_Cluster,Name=testcluster1,QuorumType=Node\ and\ File\ Share\ Majority,host=testnode1 DynamicQuorumEnabled=1i 1671553260000000000Bitlocker
此查询提供一个列表,其中包含符合 Bitlocker 加密条件的卷及其合规状态。因为 MBAM_Volume 类不包含 Name 属性,所以包含了 ExcludeNameKey 配置。VolumeName 属性包含在度量值中作为标签值。
[[inputs.win_wmi]]
name_prefix = "win_wmi_"
[[inputs.win_wmi.query]]
namespace = "root\\Microsoft\\MBAM"
class_name = "MBAM_Volume"
properties = [
"Compliant",
"VolumeName"
]
tag_properties = ["VolumeName"]示例输出
win_wmi_MBAM_Volume,VolumeName=C:,host=foo Compliant=1i 1654269272000000000SQL Server
此查询提供的度量包含描述 SQL Server 版本和 SKU 的标签。这些属性对于创建 SQL Server 清单仪表板非常有用,该仪表板包括已安装的 SQL Server 的补丁级别和版本。
[[inputs.win_wmi]]
name_prefix = "win_wmi_"
[[inputs.win_wmi.query]]
namespace = "Root\\Microsoft\\SqlServer\\ComputerManagement15"
class_name = "SqlServiceAdvancedProperty"
properties = [
"PropertyName",
"ServiceName",
"PropertyStrValue",
"SqlServiceType"
]
filter = "ServiceName LIKE 'MSSQLSERVER' AND SqlServiceType = 1 AND (PropertyName LIKE 'FILEVERSION' OR PropertyName LIKE 'SKUNAME')"
tag_properties = ["PropertyName","ServiceName","PropertyStrValue"]示例输出
win_wmi_SqlServiceAdvancedProperty,PropertyName=FILEVERSION,PropertyStrValue=2019.150.4178.1,ServiceName=MSSQLSERVER,host=foo,sqlinstance=foo SqlServiceType=1i 1654269272000000000
win_wmi_SqlServiceAdvancedProperty,PropertyName=SKUNAME,PropertyStrValue=Developer\ Edition\ (64-bit),ServiceName=MSSQLSERVER,host=foo,sqlinstance=foo SqlServiceType=1i 1654269272000000000此页面是否有帮助?
感谢您的反馈!
支持和反馈
感谢您成为我们社区的一员!我们欢迎并鼓励您对 Telegraf 和本文档提出反馈和 bug 报告。要获取支持,请使用以下资源
具有年度合同或支持合同的客户可以 联系 InfluxData 支持。