openstack - 使用 Ceilometer/Aodh 进行自动缩放未能在 openstack rocky 中触发警报
问题描述
这是我参考的文件
1.sample_server.yaml
type: os.nova.server
version: 1.0
properties:
name: cirros_server
flavor: m1.small
image: b86fb462-c5c2-4a08-9fe4-c9f86d05763d
networks:
- network: external-net
2.执行以下命令行
# openstack cluster create --profile pserver --desired-capacity 2 mycluster
# openstack cluster receiver create --type webhook --cluster mycluster --action CLUSTER_SCALE_OUT --params count=2 r_01
# export ALRM_URL01='http://vip:8777/v1/webhooks/aac3433a-40de-4d7d-830c-e0035f2a4d13/trigger?V=1&count=2'
# aodh alarm create --type gnocchi_resources_threshold --aggregation-method mean --name cpu-high --metric cpu_util --threshold 70 --comparison-operator gt --granularity 300 --evaluation-periods 1 --alarm-action $ALRM_URL01 --repeat-actions False --query metadata.user_metadata.cluster_id=$MYCLUSTER_ID --resource-type instance --resource-id f7e0e8a6-51a3-422d-b631-7ddaf65b3dfb
3.登录到每个集群节点并在那里运行一些CPU燃烧工作负载,以提高CPU利用率
我在触发警报请求时将日志输出添加到 /usr/lib/python2.7/site-packages/aodh/notifier/rest.py
class RestAlarmNotifier(notifier.AlarmNotifier):
def notify(self, action, alarm_id, alarm_name, severity, previous,
current, reason, reason_data, headers=None):
body = {'alarm_name': alarm_name, 'alarm_id': alarm_id,
'severity': severity, 'previous': previous,
'current': current, 'reason': reason,
'reason_data': reason_data}
headers['content-type'] = 'application/json'
kwargs = {'data': json.dumps(body),
'headers': headers}
max_retries = self.conf.rest_notifier_max_retries
session = requests.Session()
LOG.info('#########################')
LOG.info(session)
LOG.info(kwargs)
LOG.info(action.geturl())
LOG.info('#########################')
session.mount(action.geturl(),
requests.adapters.HTTPAdapter(max_retries=max_retries))
resp = session.post(action.geturl(), **kwargs)
LOG.info('$$$$$$$$$$$$$$$$$$$$$$$')
LOG.info(resp.content)
LOG.info('$$$$$$$$$$$$$$$$$$$$$$$')
/var/log/aodh/notifier.log 日志中会输出一些错误信息,如下: enter image description here
原因是添加body请求参数引起的错误,直接post请求可以成功,例如使用curl请求不带body参数
curl -g -i -X POST 'http://vip:8777/v1/webhooks/34e91386-7176-4b30-bc17-5c3503712696/trigger?V=1'
Aodh相关版本包如下:</p>
python2-aodhclient-1.1.1-1.el7.noarch
openstack-aodh-api-7.0.0-1.el7.noarch
openstack-aodh-common-7.0.0-1.el7.noarch
openstack-aodh-listener-7.0.0-1.el7.noarch
python-aodh-7.0.0-1.el7.noarch
openstack-aodh-notifier-7.0.0-1.el7.noarch
openstack-aodh-evaluator-7.0.0-1.el7.noarch
openstack-aodh-expirer-7.0.0-1.el7.noarch
谁能指出我正确的方向?谢谢。
解决方案
问题已解决。这是我参考的文件
修改 aodh rest.py(aodh/notifier/rest.py) https://github.com/openstack/aodh/blob/master/aodh/notifier/rest.py#L79 的 headers['content-type'] 下,添加这一行: headers['openstack-api-version'] = 'clustering 1.10'
重启 adh 服务
推荐阅读
- python - 如果没有索引,如何在熊猫中删除有条件的行?
- active-directory - 如何使用 JNDI 检查目录服务器的类型?
- python - 有没有比使用字典更好的方法在 Python 中创建字符串别名?
- python - 现有数据集的 BigQuery API 查询作业返回 404
- javascript - 反应:以前的道具在 componentDidUpdate 中不正确
- kubernetes - 在 Helm File 下使用 Kubernetes Secret
- java - 如何在 imageview 中添加滑动手势?
- json - 我不知道如何使用对象映射器和 Alamofire 解析从 json 调用到我的 tableView 的数据
- security - WebHttpBinding 中的 WCF 数据加密
- reactjs - 简单的 ReactJS 分页