Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions lib/OpenCloud/Compute/Resource/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -775,4 +775,25 @@ public function resume()

return $this->action($object);
}

/**
* Get server diagnostics
*
* Gets basic usage data for a specified server.
*
* @api
* @return object
*/
public function diagnostics()
{
// The diagnostics is only available when the os-server-diagnostics extension is installed.
$this->checkExtension('os-server-diagnostics');

$url = $this->getUrl('diagnostics');

$response = $this->getClient()->get($url)->send();
$body = Formatter::decode($response);

return $body ?: (object) array();
}
}
10 changes: 10 additions & 0 deletions tests/OpenCloud/Tests/Compute/Resource/ServerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -376,4 +376,14 @@ public function test_Create_With_Bootable_Volume_Delete_On_Termination()
$this->assertEquals(0, $obj->boot_index);
$this->assertEquals(true, $obj->delete_on_termination);
}

public function test_Diagnostics()
{
$this->addMockSubscriber($this->getTestFilePath('Diagnostics'));
$diagnostics = $this->server->diagnostics();
$this->assertInternalType('object', $diagnostics);
$this->assertEquals(524288, $diagnostics->memory);
$this->assertEquals(-1, $diagnostics->vda_errors);
$this->assertEquals(662, $diagnostics->vnet1_tx_packets);
}
}
24 changes: 24 additions & 0 deletions tests/OpenCloud/Tests/Compute/_response/Diagnostics.resp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
HTTP/1.1 200 OK
Date: Fri, 15 Nov 2013 14:12:58 GMT
Content-Length: 1364
Content-Type: application/json
X-Compute-Request-Id: req-164dc435-90c2-48ce-9d69-96f170c518c8
Server: Jetty(8.0.y.z-SNAPSHOT)

{
"cpu0_time": 17300000000,
"memory": 524288,
"vda_errors": -1,
"vda_read": 262144,
"vda_read_req": 112,
"vda_write": 5778432,
"vda_write_req": 488,
"vnet1_rx": 2070139,
"vnet1_rx_drop": 0,
"vnet1_rx_errors": 0,
"vnet1_rx_packets": 26701,
"vnet1_tx": 140208,
"vnet1_tx_drop": 0,
"vnet1_tx_errors": 0,
"vnet1_tx_packets": 662
}
8 changes: 8 additions & 0 deletions tests/OpenCloud/Tests/Compute/_response/Extensions.resp
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,14 @@ Server: Jetty(8.0.y.z-SNAPSHOT)
"alias": "os-keypairs",
"description": "Keypair Support."
},
{
"updated": "2011-12-21T00:00:00+00:00",
"name": "ServerDiagnostics",
"links": [],
"namespace": "http://docs.openstack.org/compute/ext/server-diagnostics/api/v1.1",
"alias": "os-server-diagnostics",
"description": "Allow Admins to view server diagnostics through server action."
},
{
"updated": "2012-03-07T14:46:43Z",
"name": "OSNetworksV2",
Expand Down