OSprofiler 指南¶
OSprofiler 是 oslo 的一个库。它用于性能分析。请参阅 官方文档 以获取更多详细信息。
准备工作¶
OSprofiler 现在支持多种后端,例如 Ceilometer、ElasticSearch、Messaging 和 MongoDB。
注意
1. Ceilometer 仅用于数据收集,而 Messaging 仅用于数据传输。因此,只有在启用 Messaging 时,Ceilometer 才能工作。
2. ElasticSearch 和 MongoDB 支持数据收集和传输。因此,它们可以独立使用。
在本指南中,我们以 MongoDB 为例。
有一些新的配置选项。
enabled
为该节点上的所有服务启用性能分析。默认值为 False(完全禁用性能分析功能)。此功能可能会降低 Zaqar 的性能,因此请在生产环境中将其设置为禁用。
connection_string
用于通知后端连接的字符串。默认值为 messaging://,它将通知程序设置为 oslo_messaging。这里我们将其设置为 “mongodb://:27017”。
hmac_keys
用于加密性能分析上下文数据的密钥。此字符串值应采用以下格式:<key1>[,<key2>,…<keyn>],其中每个 key 都是一个随机字符串。通过 REST API 触发性能分析的用户必须在 REST API 调用的 header 中设置其中一个 key,才能包含该节点的特定项目的性能分析结果。
trace_wsgi_transport、trace_message_store 和 trace_management_store
用户请求流程中的三个层级。设置为 True 以启用每个层级的跟踪。
因此,在本例中,我们应该添加以下配置选项
[profiler]
enabled = True
connection_string = mongodb://localhost:27017
hmac_keys = 123
trace_wsgi_transport = True
trace_message_store = True
trace_management_store = True
注意
如果您想使用 MQ 和 Ceilometer,请将 connection_string 保留为空或指示 MQ 信息。并且请确保在 Ceilometer.conf 中设置了以下配置选项
[DEFAULT]
event_dispatchers = database
[oslo_messaging_notifications]
topics = notifications, profiler
然后重启 Zaqar 服务。
命令行¶
我们现在可以使用 OpenStack Client 来分析用户请求。例如,如果想了解 “queue list” 的性能,可以这样做
1. OpenStack Client 默认支持 OSprofiler。我们只需要在命令中添加 --os-profile {hmac_keys}
openstack queue list --os-profile 123
“123” 这里是我们设置在 Zaqar 配置文件中的值。请求完成后,OpenStack Client 将返回一个 trace ID,例如
Trace ID: 2902c7a3-ee18-4b08-aae7-4e34388f9352
Display trace with command:
osprofiler trace show --html 2902c7a3-ee18-4b08-aae7-4e34388f9352
现在 trace 信息已经存储在 MongoDB 中了。
2. 使用 openstack client 返回信息中的命令。osprofiler 命令默认使用 Ceilometer 进行数据收集,因此我们需要使用 --connection-string 将其更改为 mongoDB
osprofiler trace show --html 2902c7a3-ee18-4b08-aae7-4e34388f9352 --connection-string mongodb://localhost:27017
现在您可以查看 html 格式的分析信息了。
它也支持 json 格式
osprofiler trace show --json 2902c7a3-ee18-4b08-aae7-4e34388f9352 --connection-string mongodb://localhost:27017
当然,它也支持将结果保存到文件
osprofiler trace show --json 2902c7a3-ee18-4b08-aae7-4e34388f9352 --out list_test --connection-string mongodb://localhost:27017
然后您可以打开文件 “list_test” 来获取结果。
注意
如果您使用 MQ 进行数据传输,则可以忽略这里的 “–connection-string” 或将其设置为您的 Ceilometer 端点。