NTNX>日記

個人的な趣味による Nutanix Community Edition 日記。Japanese のみですみません。

Nutanix API v2 で Host stats を取得してみる。(Python での別パターン)

Python を利用して、Nutanix API v2 から AHV の性能情報を取得してみます。
取得する情報は下記と同じものになるはずですが、取得する URI をかえてみました。

今回は、API v2 の GET /hosts/{uuid}/stats ではなく、その前提となる UUID 確認のために取得するであろう GET /hosts から値を抜き出しています。

前回同様、下記のような Prism へのログイン情報のファイルを用意します。

gist.github.com

今回のスクリプトです。

gist.github.com

下記のように実行します。

$ python ./get_ntnx_host_stats.py prism-config.json

実際に実行した様子です。タイムスタンプ、AHV、メトリック、値 の順で CSV 出力しています。

$ python ./get_ntnx_host_stats.py ./prism-config.json
2018-10-30T23:38:53.369319,NTNX-68fda404-A,num_read_io,0
2018-10-30T23:38:53.369319,NTNX-68fda404-A,controller_read_io_bandwidth_kBps,0
2018-10-30T23:38:53.369319,NTNX-68fda404-A,content_cache_hit_ppm,0
2018-10-30T23:38:53.369319,NTNX-68fda404-A,controller_avg_read_io_size_kbytes,0
2018-10-30T23:38:53.369319,NTNX-68fda404-A,content_cache_logical_memory_usage_bytes,642159208
2018-10-30T23:38:53.369319,NTNX-68fda404-A,controller_num_random_io,0
2018-10-30T23:38:53.369319,NTNX-68fda404-A,controller_total_transformed_usage_bytes,-1
2018-10-30T23:38:53.369319,NTNX-68fda404-A,write_io_ppm,0
2018-10-30T23:38:53.369319,NTNX-68fda404-A,hypervisor_num_io,0
2018-10-30T23:38:53.369319,NTNX-68fda404-A,controller_num_read_io,0
2018-10-30T23:38:53.369319,NTNX-68fda404-A,total_io_size_kbytes,0
2018-10-30T23:38:53.369319,NTNX-68fda404-A,total_read_io_size_kbytes,0
2018-10-30T23:38:53.369319,NTNX-68fda404-A,num_write_iops,0
2018-10-30T23:38:53.369319,NTNX-68fda404-A,hypervisor_total_read_io_time_usecs,0
2018-10-30T23:38:53.369319,NTNX-68fda404-A,content_cache_num_lookups,0
2018-10-30T23:38:53.369319,NTNX-68fda404-A,hypervisor_num_read_io,0
2018-10-30T23:38:53.369319,NTNX-68fda404-A,random_io_ppm,-1
2018-10-30T23:38:53.369319,NTNX-68fda404-A,hypervisor_read_io_bandwidth_kBps,0
2018-10-30T23:38:53.369319,NTNX-68fda404-A,controller_num_io,0
2018-10-30T23:38:53.369319,NTNX-68fda404-A,timespan_usecs,20000000
2018-10-30T23:38:53.369319,NTNX-68fda404-A,controller_write_io_ppm,0
2018-10-30T23:38:53.369319,NTNX-68fda404-A,controller_seq_io_ppm,-1
2018-10-30T23:38:53.369319,NTNX-68fda404-A,content_cache_num_dedup_ref_count_pph,100
2018-10-30T23:38:53.369319,NTNX-68fda404-A,hypervisor_avg_read_io_latency_usecs,0
2018-10-30T23:38:53.369319,NTNX-68fda404-A,controller_total_read_io_size_kbytes,0
2018-10-30T23:38:53.369319,NTNX-68fda404-A,hypervisor_num_read_iops,0
2018-10-30T23:38:53.369319,NTNX-68fda404-A,hypervisor_num_transmitted_bytes,0
2018-10-30T23:38:53.369319,NTNX-68fda404-A,avg_read_io_latency_usecs,-1
2018-10-30T23:38:53.369319,NTNX-68fda404-A,read_io_ppm,0
2018-10-30T23:38:53.369319,NTNX-68fda404-A,hypervisor_num_received_bytes,0
2018-10-30T23:38:53.369319,NTNX-68fda404-A,controller_total_io_size_kbytes,0
2018-10-30T23:38:53.369319,NTNX-68fda404-A,hypervisor_avg_write_io_latency_usecs,0
2018-10-30T23:38:53.369319,NTNX-68fda404-A,num_random_io,-1
2018-10-30T23:38:53.369319,NTNX-68fda404-A,content_cache_logical_ssd_usage_bytes,0
2018-10-30T23:38:53.369319,NTNX-68fda404-A,controller_num_read_iops,0
2018-10-30T23:38:53.369319,NTNX-68fda404-A,content_cache_physical_ssd_usage_bytes,0
2018-10-30T23:38:53.369319,NTNX-68fda404-A,hypervisor_total_io_size_kbytes,0
2018-10-30T23:38:53.369319,NTNX-68fda404-A,num_read_iops,0
2018-10-30T23:38:53.369319,NTNX-68fda404-A,controller_num_seq_io,-1
2018-10-30T23:38:53.369319,NTNX-68fda404-A,controller_read_io_ppm,0
2018-10-30T23:38:53.369319,NTNX-68fda404-A,controller_write_io_bandwidth_kBps,0
2018-10-30T23:38:53.369319,NTNX-68fda404-A,hypervisor_timespan_usecs,30436042
2018-10-30T23:38:53.369319,NTNX-68fda404-A,content_cache_physical_memory_usage_bytes,642159208
2018-10-30T23:38:53.369319,NTNX-68fda404-A,num_seq_io,-1
2018-10-30T23:38:53.369319,NTNX-68fda404-A,num_io,0
2018-10-30T23:38:53.369319,NTNX-68fda404-A,seq_io_ppm,-1
2018-10-30T23:38:53.369319,NTNX-68fda404-A,total_transformed_usage_bytes,-1
2018-10-30T23:38:53.369319,NTNX-68fda404-A,hypervisor_write_io_bandwidth_kBps,0
2018-10-30T23:38:53.369319,NTNX-68fda404-A,controller_avg_read_io_latency_usecs,0
2018-10-30T23:38:53.369319,NTNX-68fda404-A,num_write_io,0
2018-10-30T23:38:53.369319,NTNX-68fda404-A,controller_num_write_iops,0
2018-10-30T23:38:53.369319,NTNX-68fda404-A,hypervisor_total_read_io_size_kbytes,0
2018-10-30T23:38:53.369319,NTNX-68fda404-A,hypervisor_total_io_time_usecs,0
2018-10-30T23:38:53.369319,NTNX-68fda404-A,num_iops,0
2018-10-30T23:38:53.369319,NTNX-68fda404-A,controller_avg_write_io_size_kbytes,0
2018-10-30T23:38:53.369319,NTNX-68fda404-A,read_io_bandwidth_kBps,0
2018-10-30T23:38:53.369319,NTNX-68fda404-A,controller_num_iops,0
2018-10-30T23:38:53.369319,NTNX-68fda404-A,hypervisor_io_bandwidth_kBps,0
2018-10-30T23:38:53.369319,NTNX-68fda404-A,hypervisor_avg_io_latency_usecs,0
2018-10-30T23:38:53.369319,NTNX-68fda404-A,io_bandwidth_kBps,0
2018-10-30T23:38:53.369319,NTNX-68fda404-A,controller_io_bandwidth_kBps,0
2018-10-30T23:38:53.369319,NTNX-68fda404-A,controller_avg_io_latency_usecs,0
2018-10-30T23:38:53.369319,NTNX-68fda404-A,write_io_bandwidth_kBps,0
2018-10-30T23:38:53.369319,NTNX-68fda404-A,content_cache_saved_memory_usage_bytes,0
2018-10-30T23:38:53.369319,NTNX-68fda404-A,hypervisor_memory_usage_ppm,767463
2018-10-30T23:38:53.369319,NTNX-68fda404-A,total_read_io_time_usecs,-1
2018-10-30T23:38:53.369319,NTNX-68fda404-A,total_untransformed_usage_bytes,-1
2018-10-30T23:38:53.369319,NTNX-68fda404-A,avg_io_latency_usecs,0
2018-10-30T23:38:53.369319,NTNX-68fda404-A,controller_total_read_io_time_usecs,0
2018-10-30T23:38:53.369319,NTNX-68fda404-A,controller_num_write_io,0
2018-10-30T23:38:53.369319,NTNX-68fda404-A,avg_write_io_latency_usecs,-1
2018-10-30T23:38:53.369319,NTNX-68fda404-A,content_cache_saved_ssd_usage_bytes,0
2018-10-30T23:38:53.369319,NTNX-68fda404-A,hypervisor_num_write_io,0
2018-10-30T23:38:53.369319,NTNX-68fda404-A,controller_timespan_usecs,20000000
2018-10-30T23:38:53.369319,NTNX-68fda404-A,controller_random_io_ppm,-1
2018-10-30T23:38:53.369319,NTNX-68fda404-A,hypervisor_num_write_iops,0
2018-10-30T23:38:53.369319,NTNX-68fda404-A,controller_total_io_time_usecs,0
2018-10-30T23:38:53.369319,NTNX-68fda404-A,hypervisor_cpu_usage_ppm,543724
2018-10-30T23:38:53.369319,NTNX-68fda404-A,total_io_time_usecs,0
2018-10-30T23:38:53.369319,NTNX-68fda404-A,controller_avg_write_io_latency_usecs,0
2018-10-30T23:38:53.369319,NTNX-68fda404-A,hypervisor_num_iops,0

30秒ごとに値が更新されているようなので、下記のように定期実行しつつ、ファイル出力することもできます。

$ while :; do ./get_ntnx_host_stats.py prism-config.json | grep cpu; sleep 30; done >> ファイル名.csv

ちなみに今回の環境は下記です。

  • Nutanix CE: 2018.05.01
  • アクセス元 OS: Oracle Linux 7.5
  • Python 2.7.5(Oracle Linux 7 の Public Yum から yum インストール)

以上。