[metrics] Fix configuration PID and add file based configuration example (#11280)

Fixes #11279

Signed-off-by: Wouter Born <github@maindrain.net>
This commit is contained in:
Wouter Born 2021-09-22 08:34:09 +02:00 committed by GitHub
parent b2d89d8c7f
commit 36b6b5b8c8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 7 deletions

View File

@ -1,6 +1,6 @@
# Metrics service # Metrics service
The metrics service provides The metrics service provides:
* an additional REST endpoint to retrieve openHAB core metrics from. This can be used as scrape target for pull-based monitoring systems like [Prometheus](https://prometheus.io/). * an additional REST endpoint to retrieve openHAB core metrics from. This can be used as scrape target for pull-based monitoring systems like [Prometheus](https://prometheus.io/).
* optionally configurable services to export openHAB core metrics to push-based monitoring systems like [InfluxDB](https://www.influxdata.com/). * optionally configurable services to export openHAB core metrics to push-based monitoring systems like [InfluxDB](https://www.influxdata.com/).
@ -90,6 +90,23 @@ You can monitor the JMX metrics using a tool like [JConsole](https://docs.oracle
When the JMX exporter is enabled, the metrics will be available under the "metrics" MBean. When the JMX exporter is enabled, the metrics will be available under the "metrics" MBean.
JConsole and VisualVM will only be able to connect using JMX when openHAB is started in debug mode (use `start_debug.sh` or `start_debug.bat`). JConsole and VisualVM will only be able to connect using JMX when openHAB is started in debug mode (use `start_debug.sh` or `start_debug.bat`).
## Configuration file example
The example below shows how to configure the Metrics service using a file.
metrics.cfg:
```java
influxMetricsEnabled=true
influxURL=https://influxdb
influxDB=metrics
influxUsername=openhab
influxPassword=77QjHkoWZEdbvXe9FWsJ
influxUpdateIntervalInSeconds=60
jmxMetricsEnabled=false
```
## Additional metric formats ## Additional metric formats
The metrics service was implemented using [Micrometer](https://micrometer.io), which supports a number of [monitoring systems](https://micrometer.io/docs) The metrics service was implemented using [Micrometer](https://micrometer.io), which supports a number of [monitoring systems](https://micrometer.io/docs)
@ -98,7 +115,8 @@ It should be possible to add any of these, especially the ones using a pull mech
## Grafana ## Grafana
You can now visualize the results in Grafana. Micrometer provides a public [Grafana dashboard here](https://grafana.com/grafana/dashboards/4701). You can now visualize the results in Grafana. Micrometer provides a public [Grafana dashboard here](https://grafana.com/grafana/dashboards/4701).
I adapted it a little bit to include the openHAB metrics. You can download it here [Dashboard](doc/dashboard.json). I adapted it a little bit to include the openHAB metrics.
You can download it here [Dashboard](doc/dashboard.json).
This has been tested with Prometheus - for other monitoring systems adaptions to the dashboard might be necessary. This has been tested with Prometheus - for other monitoring systems adaptions to the dashboard might be necessary.
Here are some screenshots: Here are some screenshots:

View File

@ -56,7 +56,7 @@ import io.swagger.v3.oas.annotations.tags.Tag;
* *
* @author Robert Bach - Initial contribution * @author Robert Bach - Initial contribution
*/ */
@Component(immediate = true, service = MetricsRestController.class) @Component(configurationPid = "org.openhab.metrics", immediate = true, service = MetricsRestController.class)
@JaxrsResource @JaxrsResource
@JaxrsApplicationSelect("(" + JaxrsWhiteboardConstants.JAX_RS_NAME + "=" + RESTConstants.JAX_RS_NAME + ")") @JaxrsApplicationSelect("(" + JaxrsWhiteboardConstants.JAX_RS_NAME + "=" + RESTConstants.JAX_RS_NAME + ")")
@Path(MetricsRestController.PATH_METRICS) @Path(MetricsRestController.PATH_METRICS)