Skip to content

Commit f4aa65e

Browse files
committed
Add missed stat details (based on rene-gates <[email protected]> work)
1 parent 3933ee1 commit f4aa65e

File tree

8 files changed

+205
-0
lines changed

8 files changed

+205
-0
lines changed

Diff for: src/Api/Struct/Server/Statistics.php

+24
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,33 @@ class Statistics extends \PleskX\Api\Struct
1111
/** @var Statistics\Version */
1212
public $version;
1313

14+
/** @var Statistics\Other */
15+
public $other;
16+
17+
/** @var Statistics\LoadAverage */
18+
public $loadAverage;
19+
20+
/** @var Statistics\Memory */
21+
public $memory;
22+
23+
/** @var Statistics\Swap */
24+
public $swap;
25+
26+
/** @var Statistics\DiskSpace[] */
27+
public $diskSpace;
28+
1429
public function __construct($apiResponse)
1530
{
1631
$this->objects = new Statistics\Objects($apiResponse->objects);
1732
$this->version = new Statistics\Version($apiResponse->version);
33+
$this->other = new Statistics\Other($apiResponse->other);
34+
$this->loadAverage = new Statistics\LoadAverage($apiResponse->load_avg);
35+
$this->memory = new Statistics\Memory($apiResponse->mem);
36+
$this->swap = new Statistics\Swap($apiResponse->swap);
37+
38+
$this->diskSpace = [];
39+
foreach ($apiResponse->diskspace as $disk) {
40+
$this->diskSpace[(string) $disk->device->name] = new Statistics\DiskSpace($disk->device);
41+
}
1842
}
1943
}

Diff for: src/Api/Struct/Server/Statistics/DiskSpace.php

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
// Copyright 1999-2021. Plesk International GmbH.
3+
4+
namespace PleskX\Api\Struct\Server\Statistics;
5+
6+
class DiskSpace extends \PleskX\Api\Struct
7+
{
8+
/** @var int */
9+
public $total;
10+
11+
/** @var int */
12+
public $used;
13+
14+
/** @var int */
15+
public $free;
16+
17+
public function __construct($apiResponse)
18+
{
19+
$this->_initScalarProperties($apiResponse, [
20+
'total',
21+
'used',
22+
'free',
23+
]);
24+
}
25+
}

Diff for: src/Api/Struct/Server/Statistics/LoadAverage.php

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
// Copyright 1999-2021. Plesk International GmbH.
3+
4+
namespace PleskX\Api\Struct\Server\Statistics;
5+
6+
class LoadAverage extends \PleskX\Api\Struct
7+
{
8+
/** @var float */
9+
public $load1min;
10+
11+
/** @var float */
12+
public $load5min;
13+
14+
/** @var float */
15+
public $load15min;
16+
17+
public function __construct($apiResponse)
18+
{
19+
$this->load1min = $apiResponse->l1 / 100.0;
20+
$this->load5min = $apiResponse->l5 / 100.0;
21+
$this->load15min = $apiResponse->l15 / 100.0;
22+
}
23+
}

Diff for: src/Api/Struct/Server/Statistics/Memory.php

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
// Copyright 1999-2021. Plesk International GmbH.
3+
4+
namespace PleskX\Api\Struct\Server\Statistics;
5+
6+
class Memory extends \PleskX\Api\Struct
7+
{
8+
/** @var int */
9+
public $total;
10+
11+
/** @var int */
12+
public $used;
13+
14+
/** @var int */
15+
public $free;
16+
17+
/** @var int */
18+
public $shared;
19+
20+
/** @var int */
21+
public $buffer;
22+
23+
/** @var int */
24+
public $cached;
25+
26+
public function __construct($apiResponse)
27+
{
28+
$this->_initScalarProperties($apiResponse, [
29+
'total',
30+
'used',
31+
'free',
32+
'shared',
33+
'buffer',
34+
'cached',
35+
]);
36+
}
37+
}

Diff for: src/Api/Struct/Server/Statistics/Objects.php

+36
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,47 @@ class Objects extends \PleskX\Api\Struct
1111
/** @var int */
1212
public $domains;
1313

14+
/** @var int */
15+
public $databases;
16+
17+
/** @var int */
18+
public $activeDomains;
19+
20+
/** @var int */
21+
public $mailBoxes;
22+
23+
/** @var int */
24+
public $mailRedirects;
25+
26+
/** @var int */
27+
public $mailGroups;
28+
29+
/** @var int */
30+
public $mailResponders;
31+
32+
/** @var int */
33+
public $databaseUsers;
34+
35+
/** @var int */
36+
public $problemClients;
37+
38+
/** @var int */
39+
public $problemDomains;
40+
1441
public function __construct($apiResponse)
1542
{
1643
$this->_initScalarProperties($apiResponse, [
1744
'clients',
1845
'domains',
46+
'databases',
47+
['active_domains' => 'activeDomains'],
48+
['mail_boxes' => 'mailBoxes'],
49+
['mail_redirects' => 'mailRedirects'],
50+
['mail_groups' => 'mailGroups'],
51+
['mail_responders' => 'mailResponders'],
52+
['database_users' => 'databaseUsers'],
53+
['problem_clients' => 'problemClients'],
54+
['problem_domains' => 'problemDomains'],
1955
]);
2056
}
2157
}

Diff for: src/Api/Struct/Server/Statistics/Other.php

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
// Copyright 1999-2021. Plesk International GmbH.
3+
4+
namespace PleskX\Api\Struct\Server\Statistics;
5+
6+
class Other extends \PleskX\Api\Struct
7+
{
8+
/** @var string */
9+
public $cpu;
10+
11+
/** @var int */
12+
public $uptime;
13+
14+
/** @var bool */
15+
public $insideVz;
16+
17+
public function __construct($apiResponse)
18+
{
19+
$this->_initScalarProperties($apiResponse, [
20+
'cpu',
21+
'uptime',
22+
['inside_vz' => 'insideVz'],
23+
]);
24+
}
25+
}

Diff for: src/Api/Struct/Server/Statistics/Swap.php

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
// Copyright 1999-2021. Plesk International GmbH.
3+
4+
namespace PleskX\Api\Struct\Server\Statistics;
5+
6+
class Swap extends \PleskX\Api\Struct
7+
{
8+
/** @var int */
9+
public $total;
10+
11+
/** @var int */
12+
public $used;
13+
14+
/** @var int */
15+
public $free;
16+
17+
public function __construct($apiResponse)
18+
{
19+
$this->_initScalarProperties($apiResponse, [
20+
'total',
21+
'used',
22+
'free',
23+
]);
24+
}
25+
}

Diff for: tests/ServerTest.php

+10
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,19 @@ public function testGetStatistics()
9292
{
9393
$stats = static::$_client->server()->getStatistics();
9494
$this->assertIsNumeric($stats->objects->clients);
95+
$this->assertIsNumeric($stats->objects->domains);
96+
$this->assertIsNumeric($stats->objects->databases);
9597
$this->assertEquals('psa', $stats->version->internalName);
9698
$this->assertNotEmpty($stats->version->osName);
9799
$this->assertNotEmpty($stats->version->osVersion);
100+
$this->assertGreaterThan(0, $stats->other->uptime);
101+
$this->assertGreaterThan(0, strlen($stats->other->cpu));
102+
$this->assertIsFloat($stats->loadAverage->load1min);
103+
$this->assertGreaterThan(0, $stats->memory->total);
104+
$this->assertGreaterThan($stats->memory->free, $stats->memory->total);
105+
$this->assertIsNumeric($stats->swap->total);
106+
$this->assertIsArray($stats->diskSpace);
107+
$this->assertGreaterThan(0, array_pop($stats->diskSpace)->total);
98108
}
99109

100110
public function testGetSiteIsolationConfig()

0 commit comments

Comments
 (0)