Grafana: Difference between revisions

From NixOS Wiki
imported>PaulGrandperrin
m fix proxyPath url, a slash was missing at the end causing redirection loop
imported>ShortCord
m Config structure update for Grafana
Line 8: Line 8:


<syntaxhighlight lang=nix>
<syntaxhighlight lang=nix>
services.grafana = {
services.grafana =
      enable = true;
  enable = true;
       # Listening address and TCP port
  settings = {
       addr = "127.0.0.1";
    server = {
       port = 3000;
       # Listening Address
       # Grafana needs to know on which domain and URL it's running:
       http_addr = "127.0.0.1";
       # and Port
      http_port = 3000;
       # Grafana needs to know on which domain and URL it's running
       domain = "your.domain";
       domain = "your.domain";
       rootUrl = "https://your.domain/grafana/"; # Not needed if it is `https://your.domain/`
       root_url = "https://your.domain/grafana/"; # Not needed if it is `https://your.domain/`
    };
  };
};
};
</syntaxhighlight>
</syntaxhighlight>
Line 21: Line 26:
This will make Grafana available only at localhost. On a server, it might be used through SSH tunnel or made publicly available using nginx with TLS. For example the follwing [[Nginx]] configuration can be used:
This will make Grafana available only at localhost. On a server, it might be used through SSH tunnel or made publicly available using nginx with TLS. For example the follwing [[Nginx]] configuration can be used:
<syntaxhighlight lang=nix>
<syntaxhighlight lang=nix>
  services.nginx.virtualHosts."your.domain" = {
services.nginx.virtualHosts."your.domain" = {
    addSSL = true;
  addSSL = true;
    enableACME = true;
  enableACME = true;
    locations."/grafana/" = {
  locations."/grafana/" = {
        proxyPass = "http://127.0.0.1:${toString config.services.grafana.port}/";
      proxyPass = "http://${toString config.services.grafana.settings.server.http_addr}:${toString config.services.grafana.settings.server.http_port}/";
        proxyWebsockets = true;
      proxyWebsockets = true;
    };
   };
   };
};
</syntaxhighlight>
</syntaxhighlight>



Revision as of 07:42, 13 May 2023

Grafana is an open-source, general purpose dashboarding tool, which runs as a web application. It can be used to create a variety of time-series graphs and also for displaying logs. It supports Prometheus, graphite, InfluxDB, opentsdb, Grafana Loki, PostgreSQL and many other data sources.

See Grafana options

Installation

Grafana is available as NixOS module, it can be enabled using the following config:

services.grafana =
  enable = true;
  settings = {
    server = {
      # Listening Address
      http_addr = "127.0.0.1";
      # and Port
      http_port = 3000;
      # Grafana needs to know on which domain and URL it's running
      domain = "your.domain";
      root_url = "https://your.domain/grafana/"; # Not needed if it is `https://your.domain/`
    };
  };
};

This will make Grafana available only at localhost. On a server, it might be used through SSH tunnel or made publicly available using nginx with TLS. For example the follwing Nginx configuration can be used:

services.nginx.virtualHosts."your.domain" = {
  addSSL = true;
  enableACME = true;
  locations."/grafana/" = {
      proxyPass = "http://${toString config.services.grafana.settings.server.http_addr}:${toString config.services.grafana.settings.server.http_port}/";
      proxyWebsockets = true;
  };
};

Usage

Log into the Grafana web application (using default user: admin, password: admin). Everything else (data sources, users, dashboards, ...) is configured in the Web UI. Refer to the official documentation on how to do it:

External Links