Run Grafana on Heroku
Heroku-Grafana provides an automatic deployment script which will perform all of the following steps for you.
Should you wish to use this script, simply invoke it as follows:
./deploy.sh <app name>
Otherwise, please follow these steps to manually deploy Heroku-Grafana.
- Install the Heroku Toolbelt
- Fork and clone this repo
- Create the app, e.g.
heroku create
- Set the buildpack to the Null buildpack:
heroku buildpacks:add http://github.com/ryandotsmith/null-buildpack.git
Heroku dynos use an ephemeral filesystem, and as such will not persist changes between deployments. Specifically for Grafana, this means the database engine cannot be sqlite, but instead a Heroku database add-on. Here we are using the Postgres:
- Add on a database:
heroku addons:create heroku-postgresql:hobby-dev
- View the full Postgres connection URL:
heroku config:get DATABASE_URL
- Create Grafana environment variables based on Postgres URL:
# Postgres URL format:
# postgres://<username>:<password>@<host>/<dbname>
heroku config:set GF_DATABASE_TYPE=postgres
heroku config:set GF_DATABASE_HOST=<host>
heroku config:set GF_DATABASE_NAME=<dbname>
heroku config:set GF_DATABASE_USER=<username>
heroku config:set GF_DATABASE_PASSWORD=<password>
heroku config:set GF_DATABASE_SSL_MODE=require
Grafana also needs some configuration to use Postgres as the session provider.
First, you'll need to connect to your Postgres DB to create the session table:
# only swap out for values where <> is below
heroku pg:psql --app <app-name> DATABASE_URL
\connect <dbname>
CREATE TABLE session (key CHAR(16) NOT NULL, data bytea, expiry INT NOT NULL, PRIMARY KEY (key));
# use \dt to ensure the session table exists
\dt
Now configure Grafana to use Postgres as the session store.
heroku config:set GF_SESSION_PROVIDER=postgres
heroku config:set GF_SESSION_PROVIDER_CONFIG="$(heroku pg:credentials:url DATABASE | grep dbname | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')"
If you're running Heroku on Windows, set GF_SESSION_PROVIDER_CONFIG (space-delimited) based on the output of:
heroku pg:credentials:url DATABASE
- Deploy:
git push heroku master
- View the running app:
heroku open
Most changes can be made to Grafana through the use of environment variables. It is recommended to change the Grafana security at set-up time:
heroku config:set GF_SECURITY_ADMIN_USER=<admin user>
heroku config:set GF_SECURITY_ADMIN_PASSWORD=<admin password>
heroku config:set GF_SECURITY_SECRET_KEY=<secret key>
The binary for the Grafana server has been built specifically for the platform running on Heroku, which is 64-bit Linux. If you are running another OS, you will not be able to run this locally as-is.
# Launch the grafana server locally
heroku local web