mirror of
https://github.com/nextcloud/server.git
synced 2026-02-03 20:41:22 -05:00
feat(comments): add basic OpenMetrics exporter
Signed-off-by: Benjamin Gaussorgues <benjamin.gaussorgues@nextcloud.com>
This commit is contained in:
parent
c57c4843e8
commit
47de164946
4 changed files with 58 additions and 0 deletions
|
|
@ -38,6 +38,10 @@
|
|||
</providers>
|
||||
</activity>
|
||||
|
||||
<openmetrics>
|
||||
<exporter>OCA\Comments\OpenMetrics\CommentsCountMetric</exporter>
|
||||
</openmetrics>
|
||||
|
||||
<collaboration>
|
||||
<plugins>
|
||||
<plugin type="autocomplete-sort">OCA\Comments\Collaboration\CommentersSorter</plugin>
|
||||
|
|
|
|||
|
|
@ -22,5 +22,6 @@ return array(
|
|||
'OCA\\Comments\\MaxAutoCompleteResultsInitialState' => $baseDir . '/../lib/MaxAutoCompleteResultsInitialState.php',
|
||||
'OCA\\Comments\\Notification\\Listener' => $baseDir . '/../lib/Notification/Listener.php',
|
||||
'OCA\\Comments\\Notification\\Notifier' => $baseDir . '/../lib/Notification/Notifier.php',
|
||||
'OCA\\Comments\\OpenMetrics\\CommentsCountMetric' => $baseDir . '/../lib/OpenMetrics/CommentsCountMetric.php',
|
||||
'OCA\\Comments\\Search\\CommentsSearchProvider' => $baseDir . '/../lib/Search/CommentsSearchProvider.php',
|
||||
);
|
||||
|
|
|
|||
|
|
@ -37,6 +37,7 @@ class ComposerStaticInitComments
|
|||
'OCA\\Comments\\MaxAutoCompleteResultsInitialState' => __DIR__ . '/..' . '/../lib/MaxAutoCompleteResultsInitialState.php',
|
||||
'OCA\\Comments\\Notification\\Listener' => __DIR__ . '/..' . '/../lib/Notification/Listener.php',
|
||||
'OCA\\Comments\\Notification\\Notifier' => __DIR__ . '/..' . '/../lib/Notification/Notifier.php',
|
||||
'OCA\\Comments\\OpenMetrics\\CommentsCountMetric' => __DIR__ . '/..' . '/../lib/OpenMetrics/CommentsCountMetric.php',
|
||||
'OCA\\Comments\\Search\\CommentsSearchProvider' => __DIR__ . '/..' . '/../lib/Search/CommentsSearchProvider.php',
|
||||
);
|
||||
|
||||
|
|
|
|||
52
apps/comments/lib/OpenMetrics/CommentsCountMetric.php
Normal file
52
apps/comments/lib/OpenMetrics/CommentsCountMetric.php
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*/
|
||||
namespace OCA\Comments\OpenMetrics;
|
||||
|
||||
use Generator;
|
||||
use OC\DB\Connection;
|
||||
use OCP\OpenMetrics\IMetricFamily;
|
||||
use OCP\OpenMetrics\Metric;
|
||||
use OCP\OpenMetrics\MetricType;
|
||||
use Override;
|
||||
|
||||
class CommentsCountMetric implements IMetricFamily {
|
||||
public function __construct(
|
||||
private Connection $connection,
|
||||
) {
|
||||
}
|
||||
|
||||
#[Override]
|
||||
public function name(): string {
|
||||
return 'comments';
|
||||
}
|
||||
|
||||
#[Override]
|
||||
public function type(): MetricType {
|
||||
return MetricType::gauge;
|
||||
}
|
||||
|
||||
#[Override]
|
||||
public function unit(): string {
|
||||
return 'comments';
|
||||
}
|
||||
|
||||
#[Override]
|
||||
public function help(): string {
|
||||
return 'Number of comments';
|
||||
}
|
||||
|
||||
#[Override]
|
||||
public function metrics(): Generator {
|
||||
$qb = $this->connection->getQueryBuilder();
|
||||
$result = $qb->select($qb->func()->count())
|
||||
->from('comments')
|
||||
->where($qb->expr()->eq('verb', $qb->expr()->literal('comment')))
|
||||
->executeQuery();
|
||||
|
||||
yield new Metric($result->fetchOne(), [], time());
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue