Skip to content

Commit a4ffa6d

Browse files
committed
feat: add documentation for OpenMetrics
Signed-off-by: Benjamin Gaussorgues <[email protected]>
1 parent 2137474 commit a4ffa6d

File tree

5 files changed

+143
-0
lines changed

5 files changed

+143
-0
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
==========
2+
Monitoring
3+
==========
4+
5+
OpenMetrics
6+
-----------
7+
8+
.. versionadded:: 33
9+
10+
Nextcloud exposes a ``/metrics`` endpoint. By default, it responds only on localhost.
11+
You can change this behaviour with ``openmetrics_allowed_clients``
12+
13+
::
14+
15+
'openmetrics_allowed_clients' => [
16+
'192.168.0.0/16',
17+
],
18+
19+
20+
.. warning::
21+
22+
Ensure this endpoint is not accessible to everyone as it could lead to some load on your server.
23+
24+
25+
You can view the content of this endpoint with the following command:
26+
27+
::
28+
29+
curl "https://your.domain/metrics"
30+
31+
32+
If for some reason you want to disable some metrics (eg. if they take too long to generate), you can disable them by adding their class name into ``openmetrics_skipped_classes``
33+
34+
::
35+
36+
'openmetrics_skipped_classes' => [
37+
'OC\OpenMetrics\Exporters\FilesByType',
38+
],
39+
40+
41+
.. seealso::
42+
43+
Check :doc:`../configuration_server/config_sample_php_parameters` for more information

admin_manual/contents.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ Table of contents
6565
.. toctree::
6666
:caption: Maintenance
6767

68+
configuration_monitoring/index
6869
maintenance/index
6970
issues/index
7071

admin_manual/release_notes/upgrade_to_33.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,14 @@ Snowflake IDs
2525
This version of Nextcloud ships with `Snowflake IDs <https://en.wikipedia.org/wiki/Snowflake_ID>`_. Those IDs include the creation time of object, a sequence ID and a server ID.
2626
The server ID should now be configured in your config.php file or using environment variables. See :doc:`../configuration_server/config_sample_php_parameters` for more information.
2727

28+
OpenMetrics endpoint
29+
--------------------
30+
31+
Nextcloud 33 introduces a ``/metrics`` endpoint that can be integrated into every OpenMetrics (Prometheus) system.
32+
For security, it only answers on localhost by default.
33+
34+
See :doc:`../configuration_monitoring/index` for more information about it.
35+
2836

2937
Default user agent for outgoing requests changed
3038
------------------------------------------------

developer_manual/digging_deeper/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ Digging deeper
2424
notifications
2525
oidc
2626
out_of_office
27+
openmetrics
2728
performance
2829
phonenumberutil
2930
psr
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
=====================
2+
Open Metrics exporter
3+
=====================
4+
5+
.. versionadded:: 33.0
6+
7+
Nextcloud allows to export metrics using `OpenMetrics <https://openmetrics.io/>`_ format.
8+
9+
The data is available on the ``/metrics`` endpoint and can then be imported into any OpenMetrics (formerly Prometheus) enabled tool.
10+
11+
12+
Register a new exporter
13+
-----------------------
14+
15+
Each exporter must be registered inside **<myapp>/appinfo/info.xml**:
16+
17+
.. code-block:: xml
18+
19+
<openmetrics>
20+
<exporter>OCA\MyApp\OpenMetrics\CustomExporter</exporter>
21+
<exporter>OCA\MyApp\OpenMetrics\AnotherExporter</exporter>
22+
</openmetrics>
23+
24+
25+
Implement a new exporter
26+
------------------------
27+
28+
Then you need to implement it:
29+
30+
.. code-block:: php
31+
32+
<?php
33+
34+
declare(strict_types=1)
35+
36+
namespace OCA\MyApp\OpenMetrics;
37+
38+
use OCP\OpenMetrics\IMetricFamily;
39+
use OCP\OpenMetrics\MetricType;
40+
41+
class CustomExporter implements IMetricFamily {
42+
public function __construct(
43+
// Add you dependencies here
44+
) {
45+
}
46+
47+
#[Override]
48+
public function name(): string {
49+
return 'myapp_metric';
50+
}
51+
52+
#[Override]
53+
public function type(): MetricType {
54+
// One MetricType::*
55+
return MetricType::gauge;
56+
}
57+
58+
#[Override]
59+
public function unit(): string {
60+
return 'units';
61+
}
62+
63+
#[Override]
64+
public function help(): string {
65+
return 'Description of metric';
66+
}
67+
68+
#[Override]
69+
public function metrics(): Generator {
70+
yield new Metric(
71+
42,
72+
['label' => 'one value'],
73+
);
74+
yield new Metric(
75+
1337,
76+
['label' => 'another value'],
77+
);
78+
}
79+
}
80+
81+
This exporter will add something like this on the ``/metrics`` endpoint:
82+
83+
.. code-block::
84+
85+
# TYPE nextcloud_myapp_metric gauge
86+
# UNIT nextcloud_myapp_metric units
87+
# HELP nextcloud_myapp_metric Description of metric
88+
nextcloud_myapp_metric{label="one value"} 42
89+
nextcloud_myapp_metric{backend="another value"} 1337
90+

0 commit comments

Comments
 (0)