Debian Codegraph @

README.md

raw symbols SCIP
1 # nextcloud-exporter
2
3 A [prometheus](https://prometheus.io) exporter for getting some metrics of a [Nextcloud](https://nextcloud.com/) server instance.
4
5 ## Installation
6
7 ### Docker Image
8
9 The preferred way to use `nextcloud-exporter` is by running the provided Docker image. It is currently provided on Docker Hub and GitHub Container Registry:
10
11 - [`ghcr.io/xperimental/nextcloud-exporter`](https://github.com/xperimental/nextcloud-exporter/pkgs/container/nextcloud-exporter)
12 - [`xperimental/nextcloud-exporter`](https://hub.docker.com/r/xperimental/nextcloud-exporter/)
13
14 The following tags are available:
15
16 - `x.y.z` pointing to the release with that version
17 - `latest` pointing to the most recent released version
18 - `master` pointing to the latest build from the default branch
19
20 ### Pre-built binaries
21
22 The [releases](https://github.com/xperimental/nextcloud-exporter/releases) page contains pre-built binaries for AMD64 and ARM64 linux.
23
24 ### Build from Source
25
26 If you have a recent Go installation (see `go.mod` for the minimum version), Git and GNU Make, the following commands will check out the repository and compile the binary from source:
27
28 ```bash
29 git clone https://github.com/xperimental/nextcloud-exporter.git
30 cd nextcloud-exporter
31 make
32 ```
33
34 After this there should be a `nextcloud-exporter` binary in your current directory.
35
36 ## Client credentials
37
38 The exporter supports two different approaches for authenticating with the Nextcloud server:
39
40 - Token authentication (needs Nextcloud 22 or newer)
41 - Username and password
42
43 If you have Nextcloud 22 then using the token authentication is recommended, because it does not need a normal user account with admin privileges.
44
45 If both a token and username/password are specified in the configuration, the token will take precedence.
46
47 ### Token authentication
48
49 Nextcloud 22 and newer versions support "token authentication" for the serverinfo. That way, accessing this information does not need a normal user account with admin privileges. You can set the token to anything you like, but the recommendation is to set it to a long random number:
50
51 ```bash
52 # Generate random value (for example using openssl)
53 TOKEN=$(openssl rand -hex 32)
54 # Set token (using the occ console application)
55 occ config:app:set serverinfo token --value "$TOKEN"
56 ```
57
58 You can then use this generated token in the exported configuration instead of username and password.
59
60 ### Username and password authentication
61
62 To access the serverinfo API you will need the credentials of an admin user. It is recommended to create a separate user for that purpose. It's also possible for the exporter to generate an "app password", so that the real user password is never saved to the configuration. This also makes the exporter show up in the security panel of the user as a connected application.
63
64 To let the nextcloud-exporter create an app password, start it with the `--login` parameter:
65
66 ```bash
67 nextcloud-exporter --login --server https://nextcloud.example.com
68 ```
69
70 The exporter will generate a login URL that you need to open in your browser. Be sure to login with the correct user if you created a special user for the exporter as the app password will be bound to the logged-in user. Once the access has been granted using the browser the exporter will output the username and password that need to be entered into the configuration.
71
72 When the login process is done, it is possible to disable filesystem access for the generated token in the user's settings:
73
74 ![Allow filesystem access checkbox](contrib/allow-filesystem.png)
75
76 ---
77
78 The interactive login can also be done using a Docker container:
79
80 ```bash
81 docker run --rm -it ghcr.io/xperimental/nextcloud-exporter --login --server https://nextcloud.example.com
82 ```
83
84 The login flow needs at least Nextcloud 16 to work.
85
86 ## Usage
87
88 ```plain
89 $ nextcloud-exporter --help
90 Usage of nextcloud-exporter:
91 -a, --addr string Address to listen on for connections. (default ":9205")
92 --auth-token string Authentication token. Can replace username and password when using Nextcloud 22 or newer.
93 -c, --config-file string Path to YAML configuration file.
94 --enable-info-apps Enable gathering of apps-related metrics.
95 --enable-info-update Enable gathering of system update-related metrics.
96 --login Use interactive login to create app password.
97 -p, --password string Password for connecting to Nextcloud.
98 -s, --server string URL to Nextcloud server.
99 -t, --timeout duration Timeout for getting server info document. (default 5s)
100 --tls-skip-verify Skip certificate verification of Nextcloud server.
101 -u, --username string Username for connecting to Nextcloud.
102 -V, --version Show version information and exit.
103 ```
104
105 After starting the server will offer the metrics on the `/metrics` endpoint, which can be used as a target for prometheus.
106
107 ### Example Dashboard
108
109 The repository contains an [example Grafana dashboard](contrib/grafana-dashboard.json) that can be imported into Grafana. The dashboard is also available as ID `20716` from the [Grafana Dashboard Exchange](https://grafana.com/grafana/dashboards/20716-nextcloud/).
110
111 ### Configuration methods
112
113 There are three methods of configuring the nextcloud-exporter (higher methods take precedence over lower ones):
114
115 - Environment variables
116 - Configuration file
117 - Command-line parameters
118
119 #### Environment variables
120
121 All settings can also be specified through environment variables:
122
123 | Environment variable | Flag equivalent |
124 |----------------------------:|:---------------------|
125 | `NEXTCLOUD_SERVER` | --server |
126 | `NEXTCLOUD_USERNAME` | --username |
127 | `NEXTCLOUD_PASSWORD` | --password |
128 | `NEXTCLOUD_AUTH_TOKEN` | --auth-token |
129 | `NEXTCLOUD_LISTEN_ADDRESS` | --addr |
130 | `NEXTCLOUD_TIMEOUT` | --timeout |
131 | `NEXTCLOUD_TLS_SKIP_VERIFY` | --tls-skip-verify |
132 | `NEXTCLOUD_INFO_APPS` | --enable-info-apps |
133 | `NEXTCLOUD_INFO_UPDATE` | --enable-info-update |
134
135 #### Configuration file
136
137 The `--config-file` option can be used to read the configuration options from a YAML file:
138
139 ```yaml
140 # required
141 server: "https://example.com"
142 # required for token authentication
143 authToken: "example-token"
144 # required for username/password authentication
145 username: "example"
146 password: "example"
147 # optional
148 listenAddress: ":9205"
149 timeout: "5s"
150 tlsSkipVerify: false
151 info:
152 apps: false
153 update: false
154 ```
155
156 ### Loading Credentials from Files
157
158 Both the authentication token and the password can optionally be read from a separate file instead of directly from the input methods above.
159
160 This can be achieved by setting the value to the path of the file prefixed with an "@", for example:
161
162 ```bash
163 # Authentication token
164 nextcloud-exporter -c config-without-token.yml --auth-token @/path/to/tokenfile
165 # Password
166 nextcloud-exporter -c config-without-password.yml -p @/path/to/passwordfile
167 ```
168
169 This also works when the password or token is set using one of the other configuration modes (configuration file or environment variables).
170
171 ## Other information
172
173 ### Info URL
174
175 The exporter reads the metrics from the Nextcloud server using its "serverinfo" API. You can find the URL of this API in the administrator settings in the "Monitoring" section. It should look something like this:
176
177 ```plain
178 https://example.com/ocs/v2.php/apps/serverinfo/api/v1/info
179 ```
180
181 The path will be automatically added to the server URL you provide, so in the above example setting `--server https://example.com` would be sufficient.
182
183 If you open this URL in a browser you should see an XML structure with the information that will be used by the exporter.
184
185 ### Scrape configuration
186
187 The exporter will query the nextcloud server every time it is scraped by prometheus. If you want to reduce load on the nextcloud server you need to change the scrape interval accordingly:
188
189 ```yml
190 scrape_configs:
191 - job_name: 'nextcloud'
192 scrape_interval: 90s
193 static_configs:
194 - targets: ['localhost:9205']
195 ```
196
197 ### Exported metrics
198
199 These metrics are exported by `nextcloud-exporter`:
200
201 | name | description |
202 |----------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
203 | nextcloud_active_users_daily_total | Number of active users in the last 24 hours |
204 | nextcloud_active_users_hourly_total | Number of active users in the last hour |
205 | nextcloud_active_users_total | Number of active users for the last five minutes |
206 | nextcloud_apps_installed_total | Number of currently installed apps |
207 | nextcloud_apps_updates_available_total | Number of apps that have available updates |
208 | nextcloud_database_info | Contains meta information about the database as labels. Value is always 1. |
209 | nextcloud_database_size_bytes | Size of database in bytes as reported from engine |
210 | nextcloud_exporter_info | Contains meta information of the exporter. Value is always 1. |
211 | nextcloud_files_total | Number of files served by the instance |
212 | nextcloud_free_space_bytes | Free disk space in data directory in bytes |
213 | nextcloud_php_info | Contains meta information about PHP as labels. Value is always 1. |
214 | nextcloud_php_memory_limit_bytes | Configured PHP memory limit in bytes |
215 | nextcloud_php_upload_max_size_bytes | Configured maximum upload size in bytes |
216 | nextcloud_scrape_errors_total | Counts the number of scrape errors by this collector |
217 | nextcloud_shares_federated_total | Number of federated shares by direction `sent` / `received` |
218 | nextcloud_shares_total | Number of shares by type: <br> `authlink`: shared password protected links <br> `group`: shared groups <br>`link`: all shared links <br> `user`: shared users <br> `mail`: shared by mail <br> `room`: shared with room |
219 | nextcloud_system_info | Contains meta information about Nextcloud as labels. Value is always 1. |
220 | nextcloud_system_update_available | Contains information whether a system update is available: <br>`0`: no update available<br>`1`: nextcloud update available<br>In case of 1=yes, `available_version` label contains the new version. This metric is only available if activated. |
221 | nextcloud_up | Indicates if the metrics could be scraped by the exporter: <br>`1`: successful<br>`0`: unsuccessful (server down, server/endpoint not reachable, invalid credentials, ...) |
222 | nextcloud_users_total | Number of users of the instance |