From cb577b3170e2d6e5c44aa29c37ab5d9751a66636 Mon Sep 17 00:00:00 2001 From: Christian Weiske Date: Fri, 11 Nov 2016 21:13:56 +0100 Subject: [PATCH] improve status page --- data/templates/status.htm | 19 +++++++++++++------ src/phinde/Elasticsearch.php | 10 +++++++--- www/status.php | 17 +++++++++++++++-- 3 files changed, 35 insertions(+), 11 deletions(-) diff --git a/data/templates/status.htm b/data/templates/status.htm index a5699ef..79e875e 100644 --- a/data/templates/status.htm +++ b/data/templates/status.htm @@ -15,26 +15,33 @@ + - + - - + + + + + + + + - + - + - +
Group ItemNumberNumber
Elasticsearch documents{{esDocs}}ElasticsearchDocuments{{esStatus.documents}}
Index size{{esStatus.size_human}}
Gearman Open tasks{{gearStatus.tasks}}{{gearStatus.tasks}}
Tasks being processed{{gearStatus.processing}}{{gearStatus.processing}}
Task workers{{gearStatus.workers}}{{gearStatus.workers}}
diff --git a/src/phinde/Elasticsearch.php b/src/phinde/Elasticsearch.php index 069cf1f..6c90480 100644 --- a/src/phinde/Elasticsearch.php +++ b/src/phinde/Elasticsearch.php @@ -58,14 +58,18 @@ class Elasticsearch $r->send(); } - public function countDocuments() + public function getIndexStatus() { $r = new Elasticsearch_Request( - $this->baseUrl . 'document/_count', + $this->baseUrl . '_stats/docs,store', \HTTP_Request2::METHOD_GET ); $res = $r->send(); - return json_decode($res->getBody())->count; + $data = json_decode($res->getBody()); + return array( + 'documents' => $data->_all->total->docs->count, + 'size' => $data->_all->total->store->size_in_bytes, + ); } public function search($query, $filters, $site, $page, $perPage, $sort) diff --git a/www/status.php b/www/status.php index 3bc52cf..08e2a0d 100644 --- a/www/status.php +++ b/www/status.php @@ -3,15 +3,28 @@ namespace phinde; require 'www-header.php'; $es = new Elasticsearch($GLOBALS['phinde']['elasticsearch']); -$esDocs = $es->countDocuments(); +$esStatus = $es->getIndexStatus(); $queue = new Queue(); $gearStatus = $queue->getServerStatus(); +/** + * @link http://jeffreysambells.com/2012/10/25/human-readable-filesize-php + */ +function human_filesize($bytes, $decimals = 2) +{ + $size = array('B','kiB','MiB','GiB','TiB','PiB','EiB','ZiB','YiB'); + $factor = floor((strlen($bytes) - 1) / 3); + return sprintf("%.{$decimals}f", $bytes / pow(1024, $factor)) + . ' ' . @$size[$factor]; +} + +$esStatus['size_human'] = human_filesize($esStatus['size']); + render( 'status', array( - 'esDocs' => $esDocs, + 'esStatus' => $esStatus, 'gearStatus' => $gearStatus, ) ); -- 2.30.2