本主题将讨论在已部署实例上测试和调试 cloud-init 的一般方法。
启动时间分析 - cloud-init 分析
有时,实例的性能不如我们希望的那样,而 cloud-init 封装了一个简单的工具来检查在启动和设置期间哪些操作花费了 cloud-init 的时间最长。
脚本/usr/bin/cloud-init有一个 analyze 子命令analyze 将任何 cloud-init.log 文件解析为格式化和排序的事件。它允许对最昂贵的 cloud-init 操作进行详细分析,以确定 cloud-init 配置和设置中的长杆。这些子命令默认读取 /var/log/cloud-init.log。
analyze show
按阶段解析和组织 cloud-init.log 事件,并将每个子阶段粒度包含在时间增量报告中。
$ cloud-init analyze show -i my-cloud-init.log
-- Boot Record 01 --
The total time elapsed since completing an event is printed after the "@"
character.
The time the event takes is printed after the "+" character.
Starting stage: modules-config
|`->config-emit_upstart ran successfully @05.47600s +00.00100s
|`->config-snap_config ran successfully @05.47700s +00.00100s
|`->config-ssh-import-id ran successfully @05.47800s +00.00200s
|`->config-locale ran successfully @05.48000s +00.00100s
...
analyze dump
将 cloud-init.log 解析为事件记录并返回可用于其他报告需求的字典列表。
$ cloud-init analyze dump -i my-cloud-init.log
[
{
"description": "running config modules",
"event_type": "start",
"name": "modules-config",
"origin": "cloudinit",
"timestamp": 1510807493.0
},...
analyze blame
将 cloud-init.log 解析为事件记录,并根据最高时间成本对其进行排序,以便快速评估可能需要改进的 cloud-init 区域。
$ cloud-init analyze blame -i my-cloud-init.log
-- Boot Record 11 --
00.01300s (modules-final/config-scripts-per-boot)
00.00400s (modules-final/config-final-message)
<