From 5b002c55ec294995460b6ea3ed37b3bfd45fb23d Mon Sep 17 00:00:00 2001 From: Marcus Efraimsson Date: Thu, 7 May 2020 15:29:11 +0200 Subject: [PATCH] Docs: Updates (#136) --- devenv/docker/custom-config/config.json | 45 +++++++++++++++++++ .../docker/custom-config/docker-compose.yaml | 17 +++++++ devenv/docker/simple/docker-compose.yaml | 6 ++- docs/remote_rendering_using_docker.md | 36 +++++++++++++-- 4 files changed, 99 insertions(+), 5 deletions(-) create mode 100644 devenv/docker/custom-config/config.json create mode 100644 devenv/docker/custom-config/docker-compose.yaml diff --git a/devenv/docker/custom-config/config.json b/devenv/docker/custom-config/config.json new file mode 100644 index 00000000..ac5994ba --- /dev/null +++ b/devenv/docker/custom-config/config.json @@ -0,0 +1,45 @@ +{ + "service": { + "host": null, + "port": 8081, + + "metrics": { + "enabled": true, + "collectDefaultMetrics": true, + "requestDurationBuckets": [1, 5, 7, 9, 11, 13, 15, 20, 30] + }, + + "logging": { + "level": "debug", + "console": { + "json": true, + "colorize": false + } + } + }, + "rendering": { + "chromeBin": null, + "args": [ + "--no-sandbox" + ], + "ignoresHttpsErrors": false, + + "timezone": null, + "acceptLanguage": null, + "width": 1000, + "height": 500, + "deviceScaleFactor": 1, + "maxWidth": 3080, + "maxHeight": 3000, + "maxDeviceScaleFactor": 3, + + "mode": "clustered", + "clustering": { + "mode": "context", + "maxConcurrency": 5 + }, + + "verboseLogging": false, + "dumpio": false + } +} \ No newline at end of file diff --git a/devenv/docker/custom-config/docker-compose.yaml b/devenv/docker/custom-config/docker-compose.yaml new file mode 100644 index 00000000..c71e9b2d --- /dev/null +++ b/devenv/docker/custom-config/docker-compose.yaml @@ -0,0 +1,17 @@ +version: '2' + +services: + grafana: + image: grafana/grafana:latest + ports: + - 3000 + environment: + GF_RENDERING_SERVER_URL: http://renderer:8081/render + GF_RENDERING_CALLBACK_URL: http://grafana:3000/ + GF_LOG_FILTERS: rendering:debug + renderer: + image: grafana/grafana-image-renderer:latest + ports: + - 8081 + volumes: + - ./config.json:/usr/src/app/config.json diff --git a/devenv/docker/simple/docker-compose.yaml b/devenv/docker/simple/docker-compose.yaml index 1f3ea19f..b7c4fe1e 100644 --- a/devenv/docker/simple/docker-compose.yaml +++ b/devenv/docker/simple/docker-compose.yaml @@ -2,9 +2,9 @@ version: '2' services: grafana: - image: grafana/grafana:master + image: grafana/grafana:latest ports: - - "3000:3000" + - 3000 environment: GF_RENDERING_SERVER_URL: http://renderer:8081/render GF_RENDERING_CALLBACK_URL: http://grafana:3000/ @@ -13,3 +13,5 @@ services: image: grafana/grafana-image-renderer:latest ports: - 8081 + environment: + ENABLE_METRICS: 'true' diff --git a/docs/remote_rendering_using_docker.md b/docs/remote_rendering_using_docker.md index 0e010fc4..2cb694dd 100644 --- a/docs/remote_rendering_using_docker.md +++ b/docs/remote_rendering_using_docker.md @@ -84,6 +84,28 @@ Additional arguments to pass to the headless browser instance. Default is `--no- RENDERING_ARGS=--no-sandbox,--disable-setuid-sandbox,--disable-dev-shm-usage,--disable-accelerated-2d-canvas,--disable-gpu,--window-size=1280x758 ``` +**Change how browser instances are created:** + +You can instruct how headless browser instances are created by configuring a rendering mode (`RENDERING_MODE`). Default is `default` and will create a new browser instance on each request. Other supported values are `clustered` and `reusable`. + +```bash +RENDERING_MODE=default +``` + +When using `clustered` you can configure a clustering mode to define how many browser instances or incognito pages that can execute concurrently. Default is `browser` and will ensure a maximum amount of browser instances can execute concurrently. Mode `context` will ensure a maximum amount of incognito pages can execute concurrently. You can also configure the maximum concurrency allowed which per default is `5`. + +```bash +RENDERING_MODE=clustered +RENDERING_CLUSTERING_MODE=default +RENDERING_CLUSTERING_MAX_CONCURRENCY=5 +``` + +When using the rendering mode `reusable` one browser instance will be created and reused. A new incognito page will be opened on each request for. This mode is a bit experimental since if the browser instance crashes it will not automatically be restarted. + +```bash +RENDERING_MODE=reusable +``` + ## Configuration file You can override certain settings by using a configuration file, see [default.json](https://github.com/grafana/grafana-image-renderer/tree/master/default.json) for defaults. Note that any configured environment variable takes precedence over configuration file settings. @@ -94,6 +116,8 @@ You can volume mount your custom configuration file when starting the docker con docker run -d --name=renderer --network=host -v /some/path/config.json:/usr/src/app/config.json grafana/grafana-image-renderer:latest ``` +You can see a docker-compose example using a custom configuration file [here/](https://github.com/grafana/grafana-image-renderer/tree/master/devenv/docker/custom-config). + ## Docker Compose example The following docker-compose example can also be found in [docker/](https://github.com/grafana/grafana-image-renderer/tree/master/devenv/docker/simple). @@ -103,9 +127,9 @@ version: '2' services: grafana: - image: grafana/grafana:master + image: grafana/grafana:latest ports: - - "3000:3000" + - 3000 environment: GF_RENDERING_SERVER_URL: http://renderer:8081/render GF_RENDERING_CALLBACK_URL: http://grafana:3000/ @@ -114,6 +138,8 @@ services: image: grafana/grafana-image-renderer:latest ports: - 8081 + environment: + ENABLE_METRICS: 'true' ``` 1. Start containers: @@ -124,7 +150,11 @@ services: 3. Create a dashboard, add a panel and save the dashboard. 4. Panel context menu -> Share -> Direct link rendered image -## Prometheus metrics endpoint output example +## Enable Prometheus metrics endpoint + +The service can be configured to expose a Prometheus metrics endpoint. There's [dashboard](https://grafana.com/grafana/dashboards/12203) published that explains the details of how to configure and monitor the rendering service using Prometheus as a data source. + +**Metrics endpoint output example:** ``` # HELP process_cpu_user_seconds_total Total user CPU time spent in seconds.