其他分享
首页 > 其他分享> > OpenStack Telemetry系统架构及实践

OpenStack Telemetry系统架构及实践

作者:互联网

1. 概述

早期OpenStack的计量功能由Ceilometer项目负责,后来Ceilometer一分为四,每个项目负责一个方面的工作。不得不说这是OpenStack开发中的一个特色,比如Cinder和Neutron也是从早期的Nova中拆分出来的。

OpenStack Telemetry体系的架构如下:

 

可以看到其由四个组件构成,包括:

四个组件分工明确,各司其职,使得计量系统结构清晰明了。

另外,早期Ceilometer将原始计量数据保存到MongoDB,性能之差可以说几乎不可用。Gnocchi的出现使计量服务不论是在性能还是空间消耗上都有了质的飞跃,功不可没。也因为Gnocchi的先进性,它已经脱离OpenStack成为了一个独立项目,似有追赶其他时间序列数据库的态势。

2. Gnocchi -- 时间序列数据库服务

Gnocchi接收来自Ceilometer的原始计量数据,进行聚合运算后保存到持久化后端。

2.1 三类存储后端

Gnocchi中保存与资源使用量相关的计量数据,为了提高检索效率,额外将计量数据的元数据信息单独存储。另外由于从原始输入数据到最终存储的聚合数据,需要进行大量计算,为了缓冲输入与处理间的速率,引入缓存后端。因此Gnocchi中涉及三种存储后端:

2.2 主要组件

2.3 部署配置

2.3.1 配置Keystone

创建gnocchi用户并添加角色:

# openstack user create --domain default --password-prompt gnocchi
# openstack role add --project service --user gnocchi admin

创建gnocchi服务:

# openstack service create --name gnocchi --description "Metric Service" metric

创建endpoints:

# openstack endpoint create --region RegionOne metric public http://controller:8041
# openstack endpoint create --region RegionOne metric internal http://controller:8041
# openstack endpoint create --region RegionOne metric admin http://controller:8041

2.3.2 配置Ceph

将聚合数据保存到Ceph后端,预先在ceph中分配存储池和权限:

# ceph osd pool create gnocchi 512 512
# ceph auth get-or-create client.gnocchi mon "allow r" osd "allow rwx pool= gnocchi"

把/etc/ceph/ceph.conf和/etc/ceph/ceph.client.gnocchi.keyring拷贝到Gnocchi节点上。

2.3.3 配置MySQL

使用MySQL保存索引数据,预先创建数据库和用户:

# mysql -u root -p
mysql> CREATE DATABASE gnocchi;
mysql> GRANT ALL PRIVILEGES ON gnocchi.* TO 'gnocchi'@'localhost' \
  IDENTIFIED BY 'GNOCCHI_DBPASS';
mysql> GRANT ALL PRIVILEGES ON gnocchi.* TO 'gnocchi'@'%' \
  IDENTIFIED BY 'GNOCCHI_DBPASS';

2.3.4 安装Gnocchi

# yum install centos-release-openstack-rocky
# yum install openstack-gnocchi-api openstack-gnocchi-metricd python-gnocchiclient ceph-common

2.3.5 编辑配置

/etc/gnocchi/gnocchi.conf:服务运行参数。

[DEFAULT]
debug = true
verbose = true
log_dir = /var/log/gnocchi
parallel_operations = 4
coordination_url = redis://controller:6379

[api]
auth_mode = keystone
host = 0.0.0.0
port = 8041
uwsgi_mode = http-socket

[keystone_authtoken]
region_name = RegionOne
www_authenticate_uri = http://controller:5000
auth_url = http://controller:5000/v3
memcached_servers = controller:11211
auth_type = password
project_domain_name = default
user_domain_name = default
project_name = service
username = gnocchi
password = GNOCCHI_PASS
service_token_roles_required = true

[archive_policy]
default_aggregation_methods = mean,min,max,sum,std,count

[indexer]
url = mysql+pymysql://gnocchi:GNOCCHI_DBPASS@controller/gnocchi

[metricd]
workers = 4
metric_processing_delay = 60
greedy = true
metric_reporting_delay = 120
metric_cleanup_delay = 300

[storage]
#driver = file
driver = ceph
ceph_pool = gnocchi
ceph_username = gnocchi
ceph_keyring = /etc/ceph/ceph.client.gnocchi.keyring
ceph_timeout = 30
ceph_conffile = /etc/ceph/ceph.conf
file_basepath = /var/lib/gnocchi
file_subdir_len = 2

[cors]
allowed_origin = http://controller:3000

其中[cors]/allowed_origin是grafana的地址,前端直接访问gnocchi获取计量数据,需要配置允许跨域访问。

2.3.6 初始化数据库

# gnocchi-upgrade

2.3.7 启动服务

# systemctl enable openstack-gnocchi-api.service openstack-gnocchi-metricd.service
# systemctl start openstack-gnocchi-api.service openstack-gnocchi-metricd.service

2.4 验证使用

查看归档策略:

# openstack metric archive-policy list
+---------------------+-------------+-----------------------------------------------------------------------+---------------------------------+
| name                | back_window | definition                                                            | aggregation_methods             |
+---------------------+-------------+-----------------------------------------------------------------------+---------------------------------+
| bool                |        3600 | - points: 31536000, granularity: 0:00:01, timespan: 365 days, 0:00:00 | last                            |
| high                |           0 | - points: 3600, granularity: 0:00:01, timespan: 1:00:00               | std, count, min, max, sum, mean |
|                     |             | - points: 10080, granularity: 0:01:00, timespan: 7 days, 0:00:00      |                                 |
|                     |             | - points: 8760, granularity: 1:00:00, timespan: 365 days, 0:00:00     |                                 |
| low                 |           0 | - points: 8640, granularity: 0:05:00, timespan: 30 days, 0:00:00      | std, count, min, max, sum, mean |
| medium              |           0 | - points: 10080, granularity: 0:01:00, timespan: 7 days, 0:00:00      | std, count, min, max, sum, mean |
|                     |             | - points: 8760, granularity: 1:00:00, timespan: 365 days, 0:00:00     |                                 |
+---------------------+-------------+-----------------------------------------------------------------------+---------------------------------+

归档策略指定计量数据的聚合计算方式,包括聚合方法(mean、min、max、sum、std、count),和计量数据的统计时间粒度、数据点数。根据时间粒度和统计点数可以确定计量的时间跨度,根据一个数据点的大小在0.05 bytes~8.04 bytes,就可以确定一个metric需要使用的存储空间大小。Gnocchi内置了bool、low、medium、high四种归档策略。

归档策略的作用单位是计量项(metric)。查看归档策略规则:

# openstack metric archive-policy-rule list        
+---------+---------------------+----------------+
| name    | archive_policy_name | metric_pattern |
+---------+---------------------+----------------+
| default | low                 | *              |
+---------+---------------------+----------------+

默认规则将所有metric关联到low策略,metric使用通配符匹配。

查看资源列表:

# openstack metric resource list

资源对于OpenStack各个项目中的逻辑资源,比如实例、端口、镜像、卷等。由于还没有对接Ceilometer,所以列表为空。在Ceilometer章节部分可以看到最终结果。

查看metric列表:

# openstack metric metric list

Metric是资源统计的基本单位,一个资源会有多个metrics,比如实例资源有cpu_util、memory.usage、disk.root.size等。

查看计量数据:

# openstack metric measures show {metric_uuid}

Measures就是Gnocchi中最终保存的计量数据,即每个metric的数据点。

3. Panko -- 事件存储服务

Panko接收来自Ceilometer的事件数据,并提供查询接口。

3.1 主要组件

3.2 部署配置

3.2.1 配置Keystone

创建panko用户并添加角色:

# openstack user create --domain default --password-prompt panko
# openstack role add --project service --user panko admin

创建panko服务:

# openstack service create event --name panko --description "Panko Service"

创建endpoints:

# openstack endpoint create --region RegionOne event admin http://controller:8977
# openstack endpoint create --region RegionOne event public http://controller:8977
# openstack endpoint create --region RegionOne event internal http://controller:8977

3.2.2 配置MongoDB

使用MongoDB保存事件数据,预先创建数据库和用户:

# mongo
> use panko
> db.createUser({user: "panko",
  pwd: "PANKO_DBPASS",
  roles: [ "readWrite", "dbAdmin" ]})'

3.2.3 安装Panko

# yum install openstack-panko-api python2-pankoclient

3.2.4 编辑配置

/etc/panko/panko.conf:服务运行参数。

[DEFAULT]
debug = true
log_dir = /var/log/panko

[database]
connection = mongodb://panko:PANKO_DBPASS@controller:27017/panko

[keystone_authtoken]
region_name = RegionOne
www_authenticate_uri = http://controller:5000
auth_url = http://controller:5000/v3
memcached_servers = controller:11211
auth_type = password
project_domain_name = default
user_domain_name = default
project_name = service
username = panko
password = PANKO_PASS

3.2.5 初始化数据库

# panko-dbsync

3.2.6 建立服务文件

Panko安装包内没有包含服务文件,为了便于管理,手动创建panko-api的服务文件:

# cat /usr/lib/systemd/system/openstack-panko-api.service
[Unit]
Description=OpenStack Event API service
After=syslog.target network.target

[Service]
Type=simple
User=panko
ExecStart=/usr/bin/panko-api --port 8977 -- --logfile /var/log/panko/api.log
Restart=on-failure

[Install]
WantedBy=multi-user.target
# systemctl daemon-reload

3.2.7 启动服务

# systemctl enable openstack-panko-api.service
# systemctl start openstack-panko-api.service

3.3 验证使用

查看事件列表:

# openstack event list

由于还没有对接Ceilometer,所以列表为空。

4. Ceilometer -- 数据采集服务

Ceilometer是OpenStack计量体系中的数据采集组件,主要功能有:

4.1 主要组件

4.2 部署配置

4.2.1 配置Keystone

创建ceilometer用户并添加角色:

# openstack user create --domain default --password-prompt ceilometer
# openstack role add --project service --user ceilometer admin

4.2.2 部署控制节点

1) 安装中心组件

# yum install openstack-ceilometer-notification openstack-ceilometer-central

2) 修改配置

/etc/ceilometer/polling.yaml:配置采集项和采集时间间隔。

/etc/ceilometer/pipeline.yaml:计量数据推送后端,默认是gnocchi://。

/etc/ceilometer/event_pipeline.yaml:事件数据推送后端,默认是gnocchi://,修改为panko://。

/etc/ceilometer/ceilometer.conf:主要配置文件,服务运行参数。

[DEFAULT]
debug = false
auth_strategy = keystone
transport_url = rabbit://openstack:RABBIT_PASS@controller//ceilometer

[service_credentials]
auth_type = password
auth_url = http://controller:5000/v3
project_domain_id = default
user_domain_id = default
project_name = service
username = ceilometer
password = CEILOMETER_PASS
interface = internalURL
region_name = RegionOne

[notification]
store_events = true
messaging_urls = rabbit://openstack:RABBIT_PASS@controller//glance
messaging_urls = rabbit://openstack:RABBIT_PASS@controller//cinder
messaging_urls = rabbit://openstack:RABBIT_PASS@controller//ceilometer
messaging_urls = rabbit://openstack:RABBIT_PASS@controller//nova
messaging_urls = rabbit://openstack:RABBIT_PASS@controller//neutron

3) 初始化数据库

在Gnocchi上创建资源,要求Gnocchi已运行并在Keystone配置了endpoint。

# ceilometer-upgrade

4) 启动服务

# systemctl enable openstack-ceilometer-notification.service openstack-ceilometer-central.service
# systemctl start openstack-ceilometer-notification.service openstack-ceilometer-central.service

4.2.3 部署计算节点

1) 安装计算节点组件

# yum install openstack-ceilometer-compute

2) 修改配置

/etc/ceilometer/polling.yaml:配置采集项和采集时间间隔。

/etc/ceilometer/ceilometer.conf:主要配置文件,服务运行参数。

[DEFAULT]
auth_strategy = keystone
transport_url = rabbit://openstack:RABBIT_PASS@controller//ceilometer

[service_credentials]
auth_type = password
auth_url = http://controller:5000/v3
project_domain_id = default
user_domain_id = default
project_name = service
username = ceilometer
password = CEILOMETER_PASS
interface = internalURL
region_name = RegionOne

3) 修改nova配置

/etc/nova/nova.conf中一下计量相关配置:

[DEFAULT]
instance_usage_audit = true
instance_usage_audit_period = hour

[notifications]
notify_on_state_change = vm_and_task_state
notification_format = unversioned

[oslo_messaging_notifications]
driver = messagingv2

其中要注意notification_format = unversioned,因为目前ceilometer只支持解析unversioned格式的计量消息,所以必须这样配置。

4) 启动服务

# systemctl enable openstack-ceilometer-compute.service
# systemctl start openstack-ceilometer-compute.service
# systemctl restart openstack-nova-compute.service

4.3 验证使用

配置了Ceilometer将计量数据存储到Gnocchi,事件数据存储到Panko,Ceilometer启动后,可以看到相关数据。

查看metric列表:

# openstack metric metric list --limit 10
+--------------------------------------+---------------------+---------------------------------+-----------+--------------------------------------+
| id                                   | archive_policy/name | name                            | unit      | resource_id                          |
+--------------------------------------+---------------------+---------------------------------+-----------+--------------------------------------+
| 0144c51d-9be7-42ea-975f-618b3744dc22 | ceilometer-low-rate | disk.device.write.bytes         | B         | 95f7fed3-6b7b-5f73-bfb7-a0cbf943b0f3 |
| 0189e22c-3e1f-4b8b-b5f1-b73bc13b7084 | ceilometer-low      | image.size                      | B         | dd962583-85f6-485f-98cd-b3a790ce3f8e |
| 01a33a01-18b4-4491-afac-1b2d745d3d36 | ceilometer-low      | volume.size                     | GB        | dcfdabba-f142-4c97-976f-f75d55c0953a |
| 01c64435-e1d8-47d2-8b2c-8745b2ab5ca7 | ceilometer-low      | disk.device.write.bytes.rate    | B/s       | cddaa528-bc6d-53e9-b205-d24194cc28bd |
| 02100b0a-592a-4919-a479-8ab68f64feb9 | ceilometer-low      | disk.root.size                  | GB        | 3c9c995a-3077-4b1a-85bc-46dc6b04b320 |
| 030e15f1-1c94-4288-999d-925bc68a3770 | ceilometer-low-rate | cpu                             | ns        | f89792f8-6801-4628-bfd3-39ea2e1d882b |
| 0313e6c6-86fd-4140-9276-8ba5b32576c3 | ceilometer-low      | disk.device.write.requests.rate | request/s | 841054da-180e-5f53-86a2-27faf09dbdd6 |
| 0366ac70-74b8-4571-b2f8-9552d86b7c2d | ceilometer-low      | volume.size                     | GB        | a5952eda-8531-4ccd-8c05-9a473b2e0aa5 |
| 040b9167-9e69-4da2-8313-d27fb713d2c5 | ceilometer-low-rate | disk.device.write.requests      | request   | 76a2dbef-8423-583a-9826-ecb1e222a824 |
| 045655d9-d274-4f61-b4d7-3019732e329d | ceilometer-low      | network.incoming.bytes.rate     | B/s       | d45dcf5a-2774-5b57-9a76-433cbd419fee |
+--------------------------------------+---------------------+---------------------------------+-----------+--------------------------------------+

查看计量数据:

# openstack metric measures show 01c64435-e1d8-47d2-8b2c-8745b2ab5ca7 --start 2019-08-23T14:40:00
+---------------------------+-------------+---------------+
| timestamp                 | granularity |         value |
+---------------------------+-------------+---------------+
| 2019-08-23T14:40:00+08:00 |       300.0 | 6362.93010769 |
| 2019-08-23T14:45:00+08:00 |       300.0 | 7153.82744187 |
+---------------------------+-------------+---------------+

查看事件列表:

# openstack event list --limit 1
+------------------------+----------------------------+--------------------------------------+-------------+------------------------------------------+-------------+
| event_type             | generated                  | message_id                           | traits:name | traits:value                             | traits:type |
+------------------------+----------------------------+--------------------------------------+-------------+------------------------------------------+-------------+
| compute.metrics.update | 2019-06-25T09:37:19.990000 | 5cde7191-a485-40ff-ab1d-8609c928bfa6 | service     | compute.rocky-cmpt-01                    | string      |
|                        |                            |                                      | request_id  | req-d41eb174-2b06-45df-9cff-c08755878c01 | string      |
+------------------------+----------------------------+--------------------------------------+-------------+------------------------------------------+-------------+

5. 告警服务Aodh

Aodh根据Gnocchi和Panko中存储的计量和事件数据,提供告警通知功能。

5.1 主要组件

5.2 部署配置

5.2.1 配置Keystone

创建aodh用户并添加角色:

# openstack user create --domain default --password-prompt aodh
# openstack role add --project service --user aodh admin

创建aodh服务:

# openstack service create --name aodh --description "Telemetry Alarm" alarming

创建endpoints:

# openstack endpoint create --region RegionOne alarming public http://controller:8042
# openstack endpoint create --region RegionOne alarming internal http://controller:8042
# openstack endpoint create --region RegionOne alarming admin http://controller:8042

5.2.2 配置MySQL

使用MySQL保存索引数据,预先创建数据库和用户:

# mysql -u root -p
mysql> CREATE DATABASE aodh;
mysql> GRANT ALL PRIVILEGES ON aodh.* TO 'aodh'@'localhost' \
  IDENTIFIED BY 'AODH_DBPASS';
mysql> GRANT ALL PRIVILEGES ON aodh.* TO 'aodh'@'%' \
  IDENTIFIED BY 'AODH_DBPASS';

5.2.3 安装Aodh

# yum install openstack-aodh-api   openstack-aodh-evaluator openstack-aodh-notifier   openstack-aodh-listener openstack-aodh-expirer   python-aodhclient

5.2.4 编辑配置

/etc/aodh/aodh.conf:服务运行参数。

[DEFAULT]
auth_strategy = keystone
transport_url = rabbit://openstack:RABBIT_PASS@controller//aodh

[database]
connection = mysql+pymysql://aodh:AODH_DBPASS@controller/aodh

[keystone_authtoken]
www_authenticate_uri = http://controller:5000
auth_url = http://controller:5000
memcached_servers = controller:11211
auth_type = password
project_domain_id = default
user_domain_id = default
project_name = service
username = aodh
password = AODH_PASS

[service_credentials]
auth_type = password
auth_url = http://controller:5000/v3
project_domain_id = default
user_domain_id = default
project_name = service
username = aodh
password = AODH_PASS
interface = internalURL
region_name = RegionOne

5.2.5 初始化数据库

# aodh-dbsync

5.2.6 修改服务文件

Aodh服务默认监听8000端口,但帮助文档中描述的是8042端口。从Gnocchi监听8041端口来看,Aodh监听8042比较有延续性。修改aodh的服务文件,在启动命令中添加--port 8042参数:

# cat /usr/lib/systemd/system/openstack-aodh-api.service
[Unit]
Description=OpenStack Alarm API service
After=syslog.target network.target

[Service]
Type=simple
User=aodh
ExecStart=/usr/bin/aodh-api --port 8042 -- --logfile /var/log/aodh/api.log
Restart=on-failure

[Install]
WantedBy=multi-user.target
# systemctl daemon-reload

5.2.7. 启动服务

# systemctl enable openstack-aodh-api.service   openstack-aodh-evaluator.service  openstack-aodh-notifier.service   openstack-aodh-listener.service
# systemctl start openstack-aodh-api.service   openstack-aodh-evaluator.service  openstack-aodh-notifier.service   openstack-aodh-listener.service

5.3 验证使用

创建alarm:

# openstack alarm create --name cpu_high \
--type gnocchi_resources_threshold \
--description 'Instance Running HOT' \
--metric cpu_util --threshold 65 \
--comparison-operator ge \
--aggregation-method mean \
--granularity 300 --resource-id 5204dcff-c148-406c-a8ce-dcae8f128e50 \
--resource-type instance --alarm-action 'log://' --ok-action 'log://'

这里设置触发器状态变为alarm和ok时都执行log动作,即记录到aodh-notifier日志中。可以将log://替换为外部告警接口,触发邮件、短信等通知,或者heat、senlin的扩容接口,实现服务自动扩容。

至此OpenStack计量体系的四个组件就部署完成了。

 

标签:ceilometer,架构,service,aodh,Telemetry,controller,openstack,OpenStack,gnocchi
来源: https://www.cnblogs.com/ltxdzh/p/11400309.html