Merge pull request #108142 from Ma27/grafana-img-renderer

grafana-image-renderer: init at 2020-12-01
This commit is contained in:
WilliButz 2021-01-01 19:19:51 +01:00 committed by GitHub
commit 5e9d92c839
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 6855 additions and 0 deletions

View file

@ -540,6 +540,7 @@
./services/monitoring/do-agent.nix
./services/monitoring/fusion-inventory.nix
./services/monitoring/grafana.nix
./services/monitoring/grafana-image-renderer.nix
./services/monitoring/grafana-reporter.nix
./services/monitoring/graphite.nix
./services/monitoring/hdaps.nix

View file

@ -0,0 +1,150 @@
{ lib, pkgs, config, ... }:
with lib;
let
cfg = config.services.grafana-image-renderer;
format = pkgs.formats.json { };
configFile = format.generate "grafana-image-renderer-config.json" cfg.settings;
in {
options.services.grafana-image-renderer = {
enable = mkEnableOption "grafana-image-renderer";
chromium = mkOption {
type = types.package;
description = ''
The chromium to use for image rendering.
'';
};
verbose = mkEnableOption "verbosity for the service";
provisionGrafana = mkEnableOption "Grafana configuration for grafana-image-renderer";
settings = mkOption {
type = types.submodule {
freeformType = format.type;
options = {
service = {
port = mkOption {
type = types.port;
default = 8081;
description = ''
The TCP port to use for the rendering server.
'';
};
logging.level = mkOption {
type = types.enum [ "error" "warning" "info" "debug" ];
default = "info";
description = ''
The log-level of the <filename>grafana-image-renderer.service</filename>-unit.
'';
};
};
rendering = {
width = mkOption {
default = 1000;
type = types.ints.positive;
description = ''
Width of the PNG used to display the alerting graph.
'';
};
height = mkOption {
default = 500;
type = types.ints.positive;
description = ''
Height of the PNG used to display the alerting graph.
'';
};
mode = mkOption {
default = "default";
type = types.enum [ "default" "reusable" "clustered" ];
description = ''
Rendering mode of <package>grafana-image-renderer</package>:
<itemizedlist>
<listitem><para><literal>default:</literal> Creates on browser-instance
per rendering request.</para></listitem>
<listitem><para><literal>reusable:</literal> One browser instance
will be started and reused for each rendering request.</para></listitem>
<listitem><para><literal>clustered:</literal> allows to precisely
configure how many browser-instances are supposed to be used. The values
for that mode can be declared in <literal>rendering.clustering</literal>.
</para></listitem>
</itemizedlist>
'';
};
args = mkOption {
type = types.listOf types.str;
default = [ "--no-sandbox" ];
description = ''
List of CLI flags passed to <package>chromium</package>.
'';
};
};
};
};
default = {};
description = ''
Configuration attributes for <package>grafana-image-renderer</package>.
See <link xlink:href="https://github.com/grafana/grafana-image-renderer/blob/ce1f81438e5f69c7fd7c73ce08bab624c4c92e25/default.json" />
for supported values.
'';
};
};
config = mkIf cfg.enable {
assertions = [
{ assertion = cfg.provisionGrafana -> config.services.grafana.enable;
message = ''
To provision a Grafana instance to use grafana-image-renderer,
`services.grafana.enable` must be set to `true`!
'';
}
];
services.grafana.extraOptions = mkIf cfg.provisionGrafana {
RENDERING_SERVER_URL = "http://localhost:${toString cfg.settings.service.port}/render";
RENDERING_CALLBACK_URL = "http://localhost:${toString config.services.grafana.port}";
};
services.grafana-image-renderer.chromium = mkDefault pkgs.chromium;
services.grafana-image-renderer.settings = {
rendering = mapAttrs (const mkDefault) {
chromeBin = "${cfg.chromium}/bin/chromium";
verboseLogging = cfg.verbose;
timezone = config.time.timeZone;
};
services = {
logging.level = mkIf cfg.verbose (mkDefault "debug");
metrics.enabled = mkDefault false;
};
};
systemd.services.grafana-image-renderer = {
wantedBy = [ "multi-user.target" ];
after = [ "network.target" ];
description = " A Grafana backend plugin that handles rendering of panels & dashboards to PNGs using headless browser (Chromium/Chrome)";
environment = {
PUPPETEER_SKIP_CHROMIUM_DOWNLOAD = "true";
};
serviceConfig = {
DynamicUser = true;
PrivateTmp = true;
ExecStart = "${pkgs.grafana-image-renderer}/bin/grafana-image-renderer server --config=${configFile}";
Restart = "always";
};
};
};
meta.maintainers = with maintainers; [ ma27 ];
}

View file

@ -0,0 +1,67 @@
{ lib, mkYarnPackage, fetchFromGitHub, nodejs, runtimeShell }:
# Notes for the upgrade:
# * Download the tarball of the new version to use.
# * Remove the `resolutions`-section from upstream `package.json`
# as this breaks with `yarn2nix`.
# * Regenerate `yarn.lock` and `yarn2nix`.
# * Replace new `package.json`, `yarn.nix`, `yarn.lock` here.
# * Update `version`+`hash` and rebuild.
mkYarnPackage rec {
name = "grafana-image-renderer-unstable";
version = "2020-12-01";
src = fetchFromGitHub {
owner = "grafana";
repo = "grafana-image-renderer";
rev = "ce1f81438e5f69c7fd7c73ce08bab624c4c92e25";
sha256 = "sha256-1Ke1KLLNZ1dkLH0BWB60r2c45RBbndd0eepjc0nlHVk=";
};
buildPhase = ''
runHook preBuild
pushd deps/renderer
npm run build
popd
runHook postBuild
'';
dontInstall = true;
packageJSON = ./package.json;
yarnNix = ./yarn.nix;
yarnLock = ./yarn.lock;
distPhase = ''
runHook preDist
shopt -s extglob
pushd deps/renderer
install_path="$out/libexec/grafana-image-renderer"
mkdir -p $install_path
cp -R ../../node_modules $install_path
cp -R ./!(node_modules) $install_path
popd
mkdir -p $out/bin
cat >$out/bin/grafana-image-renderer <<EOF
#! ${runtimeShell}
${nodejs}/bin/node $install_path/build/app.js \$@
EOF
chmod +x $out/bin/grafana-image-renderer
runHook postDist
'';
meta = with lib; {
homepage = "https://github.com/grafana/grafana-image-renderer";
description = "A Grafana backend plugin that handles rendering of panels & dashboards to PNGs using headless browser (Chromium/Chrome)";
license = licenses.asl20;
maintainers = with maintainers; [ ma27 ];
platforms = platforms.linux;
};
}

View file

@ -0,0 +1,69 @@
{
"name": "renderer",
"version": "1.0.0",
"author": "Grafana Labs",
"license": "Apache-2.0",
"repository": {
"type": "git",
"url": "http://github.com/grafana/grafana-image-renderer.git"
},
"scripts": {
"tslint": "tslint -c tslint.json --project tsconfig.json",
"typecheck": "tsc --noEmit",
"prettier:check": "prettier --list-different \"**/*.ts\"",
"prettier:write": "prettier --list-different \"**/*.ts\" --write",
"precommit": "npm run tslint & npm run typecheck",
"watch": "tsc-watch --onSuccess \"node build/app.js server --config=dev.json\"",
"build": "tsc",
"start": "node build/app.js --config=dev.json"
},
"dependencies": {
"@grpc/grpc-js": "^1.0",
"@grpc/proto-loader": "^0.5.4",
"@hapi/boom": "^9.1.0",
"express": "^4.16.3",
"express-prom-bundle": "^5.1.5",
"google-protobuf": "3.5.0",
"lodash": "^4.17.19",
"minimist": "^1.2.0",
"morgan": "^1.9.0",
"mz": "^2.7.0",
"prom-client": "^11.5.3",
"puppeteer": "^2.0.0",
"puppeteer-cluster": "^0.18.0",
"unique-filename": "^1.1.0",
"winston": "^3.2.1"
},
"devDependencies": {
"@types/express": "^4.11.1",
"@types/node": "^10.0.9",
"husky": "^3.1.0",
"lint-staged": "^9.5.0",
"pkg": "4.4.8",
"prettier": "^1.19.1",
"tsc-watch": "^4.2.3",
"tslint": "^6.1.1",
"typescript": "^3.8.3"
},
"husky": {
"hooks": {
"pre-commit": "lint-staged && npm run precommit"
}
},
"lint-staged": {
"*.ts": [
"prettier --write",
"git add"
]
},
"pkg": {
"assets": "proto/*"
},
"bin": "build/app.js",
"engines": {
"node": ">=12 <13"
},
"volta": {
"node": "12.19.0"
}
}

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -17213,6 +17213,8 @@ in
grafana_reporter = callPackage ../servers/monitoring/grafana-reporter { };
grafana-image-renderer = callPackage ../servers/monitoring/grafana-image-renderer { };
gerbera = callPackage ../servers/gerbera {};
gobetween = callPackage ../servers/gobetween { };