RESTを使ってVMの状況を取得しよう
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
この記事は、Nutanix Advent Calendar 2015/12/07の記事です。 | |
http://www.adventar.org/calendars/1124 | |
Nutanix AHVでは、 | |
REST APIを使ってVMの状況を取得したりすることができます。 | |
詳しいREST APIの一覧は別記事に譲るとして、 | |
今回はその一例として、VMの一覧とそのステータスを取得してみましょう。 | |
普通のRESTと同等に使えますが、一つ注意する点があります。 | |
この手の組込機器(スイッチなど)でSSLを使っているものによるある制約として、 | |
SSL証明書がオレオレである点があります。 | |
wgetでは”--no-check-certificate”を、 | |
curlでは”--insecure”をつける必要があります。 | |
perl LWPの場合は、ssl_opts(verify_hostanme=>0)とします。 | |
では実際にやってみましょう。 | |
#!/usr/bin/perl | |
use strict; | |
use warnings; | |
use JSON; | |
use REST::Client; | |
use Data::Dumper; | |
use MIME::Base64; | |
my $user='hoge'; | |
my $passwd='fuga'; | |
my $client=REST::Client->new(); | |
$client->getUseragent()->ssl_opts(verify_hostname=>0); | |
my $headers={Authorization => 'Basic ' . encode_base64($user . ':' . $passwd)}; | |
$client->setHost('https://172.16.64.11:9440'); | |
$client->GET( | |
'/PrismGateway/services/rest/v1/vms', | |
$headers | |
); | |
print Dumper from_json($client->responseContent()); | |
するとこんな感じの出力が得られます。 | |
$VAR1 = { | |
'metadata' => { | |
'count' => 193, | |
'page' => 1, | |
'grandTotalEntities' => 193, | |
'endIndex' => 193, | |
'sortCriteria' => '', | |
'filterCriteria' => '', | |
'startIndex' => 1, | |
'totalEntities' => 193 | |
}, | |
'entities' => [ | |
{ | |
'containerIds' => [ | |
'0004e095-960e-f29d-0000-000000012345::3195' | |
], | |
'guestOperatingSystem' => undef, | |
'usageStats' => {}, | |
'clusterUuid' => '0004e095-960e-f29d-0000-000000012345', | |
'hypervisorType' => 'kKvm', | |
'vdiskNames' => [ | |
'0004e095-960e-f29d-0000-00000012345::NFS:916763' | |
], | |
'cpuReservedInHz' => undef, | |
'vdiskFilePaths' => [ | |
'/default/.acropolis/vmdisk/6f884ad6-a924-42be-841f-2db266abe240' | |
], | |
'diskCapacityInBytes' => '16106127360', | |
'numVCpus' => 2, | |
'vmId' => '0004e095-960e-f29d-0000-00000012345::01cd17b6-f6c6-4d84-bb7f-89cf83613c01', | |
'powerState' => 'on', | |
'runningOnNdfs' => $VAR1->{'entities'}[0]{'runningOnNdfs'}, | |
'controllerVm' => $VAR1->{'entities'}[0]{'controllerVm'}, | |
'virtualNicIds' => [], | |
'memoryReservedCapacityInBytes' => 8589934592, | |
'displayable' => $VAR1->{'entities'}[0]{'runningOnNdfs'}, | |
'vmName' => 'piyo007', | |
'acropolisVm' => $VAR1->{'entities'}[0]{'runningOnNdfs'}, | |
'stats' => { | |
'num_read_iops' => '-1', | |
'controller_num_iops' => '0', | |
'total_transformed_usage_bytes' => '-1', | |
'avg_io_latency_usecs' => '-1', | |
'controller_num_write_iops' => '0', | |
'hypervisor_cpu_usage_ppm' => '16179', | |
'hypervisor_num_write_io' => '0', | |
'io_bandwidth_kBps' => '-1', | |
'controller_io_bandwidth_kBps' => '0', | |
'hypervisor_num_read_io' => '0', | |
'hypervisor_read_io_bandwidth_kBps' => '0', | |
'hypervisor.cpu_ready_time_ppm' => '-1', | |
'hypervisor_num_received_bytes' => '808', | |
'controller_num_read_iops' => '0', | |
'controller_read_io_bandwidth_kBps' => '0', | |
'read_io_bandwidth_kBps' => '-1', | |
'seq_io_ppm' => '-1', | |
'controller_avg_write_io_latency_usecs' => '0', | |
'num_write_iops' => '-1', | |
'write_io_bandwidth_kBps' => '-1', | |
'read_io_ppm' => '-1', | |
'hypervisor_num_read_iops' => '0', | |
'avg_read_io_latency_usecs' => '-1', | |
'controller_random_io_ppm' => '-1', | |
'avg_write_io_latency_usecs' => '-1', | |
'hypervisor_avg_read_io_latency_usecs' => '0', | |
'num_iops' => '-1', | |
'total_untransformed_usage_bytes' => '-1', | |
'hypervisor_avg_io_latency_usecs' => '0', | |
'controller_avg_read_io_latency_usecs' => '0', | |
'controller_avg_read_io_size_kbytes' => '0', | |
'controller_write_io_bandwidth_kBps' => '0', | |
'controller_user_bytes' => '8167886848', | |
'hypervisor_num_iops' => '0', | |
'write_io_ppm' => '-1', | |
'controller_avg_write_io_size_kbytes' => '0', | |
'hypervisor_memory_usage_ppm' => '1000000', | |
'hypervisor_io_bandwidth_kBps' => '0', | |
'hypervisor_write_io_bandwidth_kBps' => '0', | |
'random_io_ppm' => '-1', | |
'hypervisor_num_write_iops' => '0', | |
'controller_avg_io_latency_usecs' => '0', | |
'hypervisor_memory_assigned_bytes' => '-1', | |
'hypervisor_num_transmitted_bytes' => '540', | |
'hypervisor_avg_write_io_latency_usecs' => '0' | |
}, | |
'memoryCapacityInBytes' => 8589934592, | |
'numNetworkAdapters' => 1, | |
'hostName' => 'NTNX-13am3k012345-1', | |
'consistencyGroupName' => undef, | |
'protectionDomainName' => undef, | |
'hostId' => '0004e095-960e-f29d-0000-000000012345::14', | |
'nutanixVirtualDiskIds' => [ | |
'0004e095-960e-f29d-0000-00000012345::6f884ad6-a924-42be-841f-2db266abe240' | |
], | |
'ipAddresses' => [ | |
'172.16.1.2' | |
], | |
'nutanixVirtualDisks' => [ | |
'/default/.acropolis/vmdisk/6f884ad6-a924-42be-841f-2db266abe240' | |
] | |
}, | |
... | |
沢山の情報が表示されますが、 | |
リストの中でPrismからも表示される情報は以下のエントリーになります。 | |
'vmName' => 'piyo007', #VMの名前 | |
'powerState' => 'on', #VMの電源の状態 | |
'stats' => { 'hypervisor_cpu_usage_ppm' => '16179',} | |
#CPUの負荷 | |
'hostName' => 'NTNX-13am3k012345-1', | |
#動いてるHVの場所 | |
'ipAddresses' => [ '172.16.1.2' ], | |
#使っているIPアドレス | |
他にも興味深い情報が沢山含まれますので、 | |
これを使ってVMの状態監視をすることも出来ます。 | |
CPUの負荷も分かりますから、 | |
100%の利用率が続くのはおかしい! | |
などの検出もできますね。 | |
では楽しいNutanix AHVライフを! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment