ceilometer 中给 meter 添加一个属性
添加meter属性
meter的volume最终会保存到数据库中,有时候希望meter能够有其他的属性。
例如给meter添加一个other的属性
ceilometer/sample.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19…
class Sample(object):
def init(self, name, type, unit, volume, user_id, project_id,
resource_id, timestamp, resource_metadata, source=None,
other=‘default’):
self.name = name
self.type = type
self.unit = unit
self.volume = volume
self.user_id = user_id
self.project_id = project_id
self.resource_id = resource_id
self.timestamp = timestamp
self.resource_metadata = resource_metadata
self.source = source or cfg.CONF.sample_source
self.id = str(uuid.uuid1())
self.other = other
…
ceilometer/publisher/utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23…
def meter_message_from_counter(sample, secret):
“””Make a metering message ready to be published or stored.
Returns a dictionary containing a metering message
for a notification message and a Sample instance.
“””
msg = {‘source’: sample.source,
‘counter_name’: sample.name,
‘counter_type’: sample.type,
‘counter_unit’: sample.unit,
‘counter_volume’: sample.volume,
‘user_id’: sample.user_id,
‘project_id’: sample.project_id,
‘resource_id’: sample.resource_id,
‘timestamp’: sample.timestamp,
‘resource_metadata’: sample.resource_metadata,
‘message_id’: sample.id,
‘other’: sample.other,
}
msg[‘message_signature’] = compute_signature(msg, secret)
return msg
…
这样收集的meter中就会有一个other的属性
但ceilometer api还会出问题,需要作如下修改
ceilometer/storage/models.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29…
class Sample(base.Model):
“””One collected data point.”””
def init(self,
source,
counter_name, counter_type, counter_unit, counter_volume,
user_id, project_id, resource_id,
timestamp, resource_metadata,
message_id,
message_signature,
recorded_at,
other,
):
…
base.Model.init(self,
source=source,
counter_name=counter_name,
counter_type=counter_type,
counter_unit=counter_unit,
counter_volume=counter_volume,
user_id=user_id,
project_id=project_id,
resource_id=resource_id,
timestamp=timestamp,
resource_metadata=resource_metadata,
message_id=message_id,
message_signature=message_signature,
recorded_at=recorded_at,
other=other)
ceilometer/api/controller/v2.py
1
2
3
4…
class OldSample(_Base):
other = wtype.text
…
若需要定义other的值,举例ceilometer/compute
修改
ceilometer/compute/pollsters/utils.py
1 | … |
ceilometer/compute/pollsters/memory.py
1 | … |