Skip to content

Commit ff67672

Browse files
committed
feat(comments): add basic OpenMetrics exporter
Signed-off-by: Benjamin Gaussorgues <[email protected]>
1 parent ef3ff0a commit ff67672

File tree

4 files changed

+58
-0
lines changed

4 files changed

+58
-0
lines changed

apps/comments/appinfo/info.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@
3838
</providers>
3939
</activity>
4040

41+
<openmetrics>
42+
<exporter>OCA\Comments\OpenMetrics\Comments</exporter>
43+
</openmetrics>
44+
4145
<collaboration>
4246
<plugins>
4347
<plugin type="autocomplete-sort">OCA\Comments\Collaboration\CommentersSorter</plugin>

apps/comments/composer/composer/autoload_classmap.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,6 @@
2222
'OCA\\Comments\\MaxAutoCompleteResultsInitialState' => $baseDir . '/../lib/MaxAutoCompleteResultsInitialState.php',
2323
'OCA\\Comments\\Notification\\Listener' => $baseDir . '/../lib/Notification/Listener.php',
2424
'OCA\\Comments\\Notification\\Notifier' => $baseDir . '/../lib/Notification/Notifier.php',
25+
'OCA\\Comments\\OpenMetrics\\Comments' => $baseDir . '/../lib/OpenMetrics/Comments.php',
2526
'OCA\\Comments\\Search\\CommentsSearchProvider' => $baseDir . '/../lib/Search/CommentsSearchProvider.php',
2627
);

apps/comments/composer/composer/autoload_static.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ class ComposerStaticInitComments
3737
'OCA\\Comments\\MaxAutoCompleteResultsInitialState' => __DIR__ . '/..' . '/../lib/MaxAutoCompleteResultsInitialState.php',
3838
'OCA\\Comments\\Notification\\Listener' => __DIR__ . '/..' . '/../lib/Notification/Listener.php',
3939
'OCA\\Comments\\Notification\\Notifier' => __DIR__ . '/..' . '/../lib/Notification/Notifier.php',
40+
'OCA\\Comments\\OpenMetrics\\Comments' => __DIR__ . '/..' . '/../lib/OpenMetrics/Comments.php',
4041
'OCA\\Comments\\Search\\CommentsSearchProvider' => __DIR__ . '/..' . '/../lib/Search/CommentsSearchProvider.php',
4142
);
4243

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php
2+
3+
/**
4+
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
5+
* SPDX-License-Identifier: AGPL-3.0-or-later
6+
*/
7+
namespace OCA\Comments\OpenMetrics;
8+
9+
use Generator;
10+
use OC\DB\Connection;
11+
use OCP\OpenMetrics\IMetricFamily;
12+
use OCP\OpenMetrics\Metric;
13+
use OCP\OpenMetrics\MetricTypes;
14+
use Override;
15+
16+
class Comments implements IMetricFamily {
17+
public function __construct(
18+
private Connection $connection,
19+
) {
20+
}
21+
22+
#[Override]
23+
public function name(): string {
24+
return 'comments';
25+
}
26+
27+
#[Override]
28+
public function type(): MetricTypes {
29+
return MetricTypes::gauge;
30+
}
31+
32+
#[Override]
33+
public function unit(): string {
34+
return 'comments';
35+
}
36+
37+
#[Override]
38+
public function help(): string {
39+
return 'Comments counts';
40+
}
41+
42+
#[Override]
43+
public function metrics(): Generator {
44+
$qb = $this->connection->getQueryBuilder();
45+
$result = $qb->select($qb->func()->count())
46+
->from('comments')
47+
->where($qb->expr()->eq('verb', $qb->expr()->literal('comment')))
48+
->executeQuery();
49+
50+
yield new Metric($result->fetchOne(), [], time());
51+
}
52+
}

0 commit comments

Comments
 (0)