|
27 | 27 | use Phpfastcache\Exceptions\PhpfastcacheLogicException; |
28 | 28 | use Solarium\Client as SolariumClient; |
29 | 29 | use Solarium\Core\Client\Adapter\Curl as SolariumCurlAdapter; |
| 30 | +use Solarium\Core\Client\Endpoint; |
| 31 | +use Solarium\Core\Client\Request; |
30 | 32 | use Solarium\Exception\ExceptionInterface as SolariumExceptionInterface; |
31 | 33 | use Solarium\QueryType\Select\Result\Document as SolariumDocument; |
32 | 34 |
|
@@ -235,11 +237,48 @@ protected function getSolrField(string $pfcField): string |
235 | 237 |
|
236 | 238 | public function getStats(): DriverStatistic |
237 | 239 | { |
| 240 | + /** |
| 241 | + * Solr "phpfastcache" core info |
| 242 | + */ |
| 243 | + $coreAdminQuery = $this->instance->createCoreAdmin(); |
| 244 | + $statusAction = $coreAdminQuery->createStatus(); |
| 245 | + $coreAdminQuery->setAction($statusAction); |
| 246 | + $response = $this->instance->coreAdmin($coreAdminQuery); |
| 247 | + $coreServerInfo = $response->getData()['status'][$this->config->getCoreName()]; |
| 248 | + |
| 249 | + /** |
| 250 | + * Unfortunately Solarium does not offer |
| 251 | + * an API to query the admin info system :( |
| 252 | + */ |
| 253 | + $adminSystemInfoUrl = $this->config->getScheme() |
| 254 | + . '://' |
| 255 | + . $this->config->getHost() |
| 256 | + . ':' |
| 257 | + . $this->config->getPort() |
| 258 | + . rtrim($this->config->getPath(), '/') |
| 259 | + . '/solr/admin/info/system'; |
| 260 | + |
| 261 | + if (($content = \file_get_contents($adminSystemInfoUrl)) !== false) { |
| 262 | + try { |
| 263 | + $serverSystemInfo = \json_decode($content, true, 512, \JSON_THROW_ON_ERROR); |
| 264 | + } catch (\JsonException) { |
| 265 | + $serverSystemInfo = []; |
| 266 | + } |
| 267 | + } |
| 268 | + |
238 | 269 | return (new DriverStatistic()) |
239 | 270 | ->setData(implode(', ', array_keys($this->itemInstances))) |
240 | | - ->setInfo('') |
241 | | - ->setRawData(null) |
242 | | - ->setSize(0); |
| 271 | + ->setInfo(sprintf( |
| 272 | + 'Solarium %s and Solr %s for %s %s. %d document(s) stored in the "%s" core', |
| 273 | + $this->instance::VERSION, |
| 274 | + $serverSystemInfo['lucene']['solr-spec-version'] ?? '[unknown SOLR version]', |
| 275 | + $serverSystemInfo['system']['name'] ?? '[unknown OS]', |
| 276 | + $serverSystemInfo['system']['version'] ?? '[unknown OS version]', |
| 277 | + $coreServerInfo['index']['numDocs'] ?? 0, |
| 278 | + $this->config->getCoreName() |
| 279 | + )) |
| 280 | + ->setRawData($coreServerInfo) |
| 281 | + ->setSize($coreServerInfo['index']['sizeInBytes'] ?? 0); |
243 | 282 | } |
244 | 283 |
|
245 | 284 | public function getConfig(): Config |
|
0 commit comments