Skip to content

Commit eaee917

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

File tree

5 files changed

+150
-0
lines changed

5 files changed

+150
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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 :ref:`OpenMetrics configuration<label_openmetrics_config>`.
12+
13+
.. note:
14+
15+
Please ensure this endpoint is not accessible to everyone as it could lead to some load on your server.
16+
17+
18+
You can view the content of this endpoint with the following command:
19+
20+
::
21+
22+
curl "https://your.domain/metrics"
23+
24+

admin_manual/configuration_server/config_sample_php_parameters.rst

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3290,6 +3290,40 @@ hashingCost
32903290
The hashing cost used by hashes generated by Nextcloud
32913291
Using a higher value requires more time and CPU power to calculate the hashes
32923292

3293+
.. _label_openmetrics_config:
3294+
3295+
OpenMetrics exporter
3296+
--------------------
3297+
3298+
Nextcloud exposes some OpenMetrics metrics on the ``/metrics`` endpoint.
3299+
3300+
openmetrics_allowed_clients
3301+
^^^^^^^^^^^^^^^^^^^^^^^^^^^
3302+
3303+
::
3304+
3305+
'openmetrics_allowed_clients' => [
3306+
'192.168.0.0/16',
3307+
'fe80::/10',
3308+
'10.0.0.1',
3309+
];
3310+
3311+
By default, Nextcloud metrics are only sent to localhost clients.
3312+
This option allows to allow other clients by range or single IP address.
3313+
3314+
openmetrics_skipped_classes
3315+
^^^^^^^^^^^^^^^^^^^^^^^^^^^
3316+
::
3317+
3318+
'openmetrics_skipped_classes' => [
3319+
'OC\OpenMetrics\Exporters\FilesByType',
3320+
'OCA\Files_Sharing\OpenMetrics\SharesCount',
3321+
];
3322+
3323+
Some metrics can be time consumming and not useful for you.
3324+
In this case, you can skip some metrics by using their full classname.
3325+
3326+
32933327
All other configuration options
32943328
-------------------------------
32953329

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

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\MetricTypes;
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(): MetricTypes {
54+
// One MetricTypes::*
55+
return MetricTypes::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)