mirror of
https://github.com/nextcloud/server.git
synced 2026-05-20 09:12:51 -04:00
Expose a `/metrics` endpoint with some basic metrics Signed-off-by: Benjamin Gaussorgues <benjamin.gaussorgues@nextcloud.com>
62 lines
1.2 KiB
PHP
62 lines
1.2 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
/**
|
|
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
|
|
* SPDX-License-Identifier: AGPL-3.0-or-later
|
|
*/
|
|
|
|
namespace OC\OpenMetrics\Exporters;
|
|
|
|
use Generator;
|
|
use OCP\App\IAppManager;
|
|
use OCP\OpenMetrics\IMetricFamily;
|
|
use OCP\OpenMetrics\Metric;
|
|
use OCP\OpenMetrics\MetricType;
|
|
use Override;
|
|
|
|
/**
|
|
* Export statistics about apps
|
|
*/
|
|
class AppsCount implements IMetricFamily {
|
|
public function __construct(
|
|
private IAppManager $appManager,
|
|
) {
|
|
}
|
|
|
|
#[Override]
|
|
public function name(): string {
|
|
return 'apps_count';
|
|
}
|
|
|
|
#[Override]
|
|
public function type(): MetricType {
|
|
return MetricType::gauge;
|
|
}
|
|
|
|
#[Override]
|
|
public function unit(): string {
|
|
return 'applications';
|
|
}
|
|
|
|
#[Override]
|
|
public function help(): string {
|
|
return 'Number of apps in Nextcloud';
|
|
}
|
|
|
|
#[Override]
|
|
public function metrics(): Generator {
|
|
$installedAppsCount = count($this->appManager->getAppInstalledVersions(false));
|
|
$enabledAppsCount = count($this->appManager->getEnabledApps());
|
|
$disabledAppsCount = $installedAppsCount - $enabledAppsCount;
|
|
yield new Metric(
|
|
$disabledAppsCount,
|
|
['status' => 'disabled'],
|
|
);
|
|
yield new Metric(
|
|
$enabledAppsCount,
|
|
['status' => 'enabled'],
|
|
);
|
|
}
|
|
}
|