改进 snmp 硬件检查器¶
https://blueprints.launchpad.net/ceilometer/+spec/snmp-improvement
我们可以对现有的硬件 snmp 检查器进行一些改进,以达到以下目标
在添加新的硬件指标时,尽量减少 snmp 检查器的编码工作量
减少检查器和远程 snmpd 代理之间的网络流量
问题描述¶
目前,要添加新的硬件指标,开发人员需要执行以下操作
在 ceilometer.hardware.inspector.base.Inspector 类中添加新的 inspect 方法。
添加上述新 inspect 方法的新返回数据类型定义。
在 snmp 检查器中实现新的 inspect 方法。
添加新的硬件 pollsters 并将其在 setup.cfg 中注册。
考虑到可以通过 snmp 获取的大量指标,这可能会导致大量的编码工作。
此外,由于大多数现有的 snmpd 代理都支持版本 2c,我们应该利用版本 2c 中引入的 snmp GetBulkRequest 来最大限度地减少 snmp 检查器和 snmpd 代理之间的网络流量。如果 snmpd 代理不支持版本 2c 及以上版本,我们应该回退到 GetNextRequest。
提议的变更¶
因为每个硬件指标都可以映射到一个或多个 snmp OID。使用这些 OID,snmp 检查器可以获取样本值以及样本的元数据。
因此,我们提出以下更改
在 ceilometer.hardware.inspector.base.Inspector 中
我们将用通用的 inspect 方法替换当前的 inspect_xxx() 方法
def inspect_generic(self, host, identifier, cache):
""" return an iterator of (value, metadata, extra)
param host: the target host
param identifier: the identifier of the metric
param cache: cache passed from the pollster
return value: sample value
return metadata: dict to construct sample's metadata
return extra: dict of extra information to help pollster
to construct the sample
"""
在 ceilometer.hardware.inspector.snmp 中
我们定义一个如下所示的映射字典
MAPPING = {
identifier: {
'matching_type': EXACT or PREFIX,
'metric_oid': oid of the sample value,
'metadata': {
metadata_name1: [oid1, value_converter],
metadata_name2: [oid2, value_converter],
},
'post_op': special func to modify the return data,
},
}
传递到 inspect_generic() 方法的 identifier 参数充当上述映射的关键键。
snmp 检查器中的 inspect_generic() 方法将执行以下操作
1. map = MAPPING[identifier]
value = None
metadata = {}
extra = {}
2. Collect all the oids in the map, including the metric_oid as
map['metric_oid'] and oids in metadata map['metadata'].
3. Send out GetRequest or GetBulkRequest(based on the matching_type
respectively) to get those oid values which are not in the cache,
and save the response as key-value pairs like oid:value in the cache.
4. Based on the matching_type, construct value and metadata using the
oid:value key-value pairs in the cache. The metadata is constructed
as a dictionary like:
{
metadata_name1: value_converter(select_data(cache, oid1, index)),
metadata_name2: value_converter(select_data(cache, oid2, index)),
}
5. call post_op(host, map, value, metadata, extra)
The post_op is assumed to be implemented by new metric developer. It
could be used to add additional special metadata(e.g. ip address), or
it could be used to add information into extra dict to be returned
to construct the pollster how to build final sample, e.g.
extra.update('project_id': xy, 'user_id': zw)
基于不同的 matching_type,在上述第 5 步中构造返回的 (value, metadata) 的方式略有不同
如果 matching_type 是 EXACT,我们使用 oid 作为缓存中的精确键来查找相应的值,即 cache[oid]。
如果 matching_type 是 PREFIX,缓存中所有以 oid 作为前缀的键都匹配,并且键的剩余部分将像索引一样处理。可以使用索引来查找相应的元数据值。例如,假设我们有以下映射
MAPPING = {
'disk.size.total': {
'matching_type': PREFIX,
'metric_oid': "1.3.6.1.4.1.2021.9.1.6",
'metadata': {
'device': ["1.3.6.1.4.1.2021.9.1.3", str],
'path': ["1.3.6.1.4.1.2021.9.1.2", str],
},
'post_op': None,
},
And in the cache, we have something like the following:
{
'1.3.6.1.4.1.2021.9.1.6.1': 19222656,
'1.3.6.1.4.1.2021.9.1.3.1': "/dev/sda2",
'1.3.6.1.4.1.2021.9.1.2.1': "/"
'1.3.6.1.4.1.2021.9.1.6.2': 808112,
'1.3.6.1.4.1.2021.9.1.3.2': "tmpfs",
'1.3.6.1.4.1.2021.9.1.2.2': "/run",
}
So here we'll return 2 instances of (value, metadata, extra):
(19222656, {'device': "/dev/sda2", 'path': "/"}, None)
(808112, {'device': "tmpfs", 'path': "/run"}, None)
在 ceilometer.hardware.pollsters 中
我们需要相应地更改为新的通用检查器接口。
替代方案¶
无
数据模型影响¶
无
REST API 影响¶
无
安全影响¶
无
Pipeline 影响¶
无
其他最终用户影响¶
无
性能/可扩展性影响¶
现有模型是首先使用 GetNextRequest 获取索引,然后使用该索引使用 GetRequest 获取多个 OID。我们将其替换为 GetBulkRequest。这可以显著减少 snmp 检查器和 snmpd 代理之间交换的 snmp 数据包数量。从而我们可以提高性能。
其他部署影响¶
为了使 snmp 检查器正常工作,机器上需要运行一个 snmp 代理 ‘snmpd’,监听 snmp 检查器和 ceilometer 代理可访问的网络接口。但是,这不是一个新的部署要求,因为我们已经需要部署一个 snmpd 代理。
开发者影响¶
ceilometer.hardware.inspector.base.Inspector 中的接口更改可能需要更改其他硬件检查器实现。但现在已知的唯一实现是 snmp 检查器,因此不应产生其他重大影响。
实现¶
负责人¶
- 主要负责人
<lianhao-lu>
- 其他贡献者
<None>
- 持续维护者
<lianhao-lu>
工作项¶
添加新的 inspect_generic 接口和 snmp 实现
将 pollster 更改为新接口并删除旧的检查器接口
未来生命周期¶
无
依赖项¶
测试¶
无
文档影响¶
无
参考资料¶
Juno summit 会议记录
https://etherpad.openstack.org/p/ceilometer-snmp-inspector
pysnmp 库