Grafana working templates on Hestia

Hi, just got Grafana web interface working on my Hestia server, so I thought I’d make the templates available.

First install grafana and influxDB according to the many guides around the web. If you want to monitor the local machine you might need to install telegraf or similar data collector and send requests to http://127.0.0.1:8086. If you want to monitor remote machines, you’ll need to open port 8086 TCP.

So the Grafana web interface is running on port 3000. You’ll need to create the two template files and then select them under the domain you want to view grafana under. These assume you’ve got SSL configured, as you probably should.

/usr/local/hestia/data/templates/web/nginx/grafana.tpl

#=======================================================================#
# Grafana Web Domain Template                                           #
#=======================================================================#

# Redirect all traffic to SSL

server {
    listen      %ip%:%proxy_port%;
    server_name %domain_idn% %alias_idn%;

    return 301 https://$host$request_uri;
}

/usr/local/hestia/data/templates/web/nginx/grafana.stpl

#=======================================================================#
# Grafana Web Domain Template                                           #
#=======================================================================#

# this is required to proxy Grafana Live WebSocket connections.
map $http_upgrade $connection_upgrade {
  default upgrade;
  '' close;
}

# Standard Hestia stanza
server {
    listen      %ip%:%proxy_ssl_port% ssl http2;
    server_name %domain_idn% %alias_idn%;
    ssl_certificate      %ssl_pem%;
    ssl_certificate_key  %ssl_key%;
    ssl_stapling on;
    ssl_stapling_verify on;
    error_log  /var/log/%web_system%/domains/%domain%.error.log error;

#  Send all traffic to grafana server
    location / {
        proxy_pass      http://localhost:3000;
    }
    
# Proxy Grafana Live WebSocket connections.
  location /api/live {
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "Upgrade";
    proxy_set_header Host $http_host;
    proxy_pass http://localhost:3000/;
  }

}

Your mileage may vary. This worked for me.