From 01c3320ea5c52ebbcfc766122c189b09a17fdfb7 Mon Sep 17 00:00:00 2001 From: olomana Date: Fri, 10 Feb 2023 22:16:06 +0000 Subject: [PATCH] Add grafana --- README.md | 2 ++ grafana/.gitignore | 2 ++ grafana/README.md | 31 +++++++++++++++++ grafana/docker-compose.yml | 70 ++++++++++++++++++++++++++++++++++++++ grafana/grafana.ini | 62 +++++++++++++++++++++++++++++++++ grafana/prometheus.yml | 21 ++++++++++++ 6 files changed, 188 insertions(+) create mode 100644 grafana/.gitignore create mode 100644 grafana/README.md create mode 100644 grafana/docker-compose.yml create mode 100755 grafana/grafana.ini create mode 100644 grafana/prometheus.yml diff --git a/README.md b/README.md index 1f42b13..1b0e0e6 100644 --- a/README.md +++ b/README.md @@ -85,6 +85,8 @@ Traefik is the networking stack that I'm using for Olomana. The goal here is to 5. (Additional) Configure the admin console and generate passwords for the admin user. +**Note that often I had to restart traefik after bringing up other services.** + ### Docker Admin Console (Portainer) 1. Start portainer using the docker-compose file: `docker-compose up -d`. diff --git a/grafana/.gitignore b/grafana/.gitignore new file mode 100644 index 0000000..a4cd3b8 --- /dev/null +++ b/grafana/.gitignore @@ -0,0 +1,2 @@ +olomana.ini + diff --git a/grafana/README.md b/grafana/README.md new file mode 100644 index 0000000..59eaa5d --- /dev/null +++ b/grafana/README.md @@ -0,0 +1,31 @@ +# Whitney Grafana + +Resource: https://grafana.com/docs/grafana/latest/setup-grafana/installation/docker/ + +Note: Create a `grafana` user and add its UID to the docker-compose file so that created files will be given the correct ownership for later. Then, when running the container for the first time, use sudo so we can create the folder hierarchy for grafana. + +Grafana instance that produces system metrics. Creates a Node-Exporter container that reads system metrics. A bridge network is created to allow Prometheus to query Node Exporter for metrics. Grafana connects to Prometheus via its bridge network to gather aggregated metrics. +
+Custom configuration held in grafana.ini in the container. Container expects to copy in a file called "olomana.ini", which is not checked into git. +
+After starting this image, we still need to create a datasource. Select Prometheus as the type, and `prometheus_whitney:9090` is the address. Everything else can be default. The networks need to be set up correctly to be able to refer to the container like this. If not, specifying it over the local network works fine. +
+We also need to create a dashboard if starting from scratch. A good default one for node-exporter is `1860`. + +Setting up the data source is kind of dumb. you need to both indicate you want to communicate over http and to the container by name. So the correct thing to put when making a prometheus data source is `http://prometheus:9090` if the container name is "prometheus". + +You can check the contents of Prometheus with `curl localhost:9090/metrics`. + +The repo contains `grafana.ini`, the config file for grafana. By default this defines the admin account to be `admin:admin`. Change that and save the new file as `olomana.ini`, which is what will be copied into the container. + +### Start with Docker-Compose (USING SUDO, see ownership issues above.) + +`sudo docker-compose up -d` + +I usually had to manually give ownership to the right user to the /data/grafana_data folder hierarchy before grafana would work. + +Also, if using traefik, to expose this container, you probably need to restart traefik after this container goes up. + +#### Customization Notes +Images can be hosted by imgur and added in html to a Text Panel. + diff --git a/grafana/docker-compose.yml b/grafana/docker-compose.yml new file mode 100644 index 0000000..bb9afca --- /dev/null +++ b/grafana/docker-compose.yml @@ -0,0 +1,70 @@ +version: "3" + +networks: + grafana-network: + driver: bridge + traefik_traefik-network: + external: true + minecraft_minecraft_network: + external: true + +volumes: + grafana_data: {} + prometheus_data: {} + +services: + grafana: + image: grafana/grafana + user: "1001" + container_name: grafana + restart: always + networks: + - grafana-network + - traefik_traefik-network + ports: + - "3000:3000" + volumes: + - ./olomana.ini:/etc/grafana/grafana.ini + - /data/grafana_data:/var/lib/grafana + labels: + - traefik.http.routers.grafana.rule=Host(`grafana.whitney.rip`) + - traefik.http.routers.grafana.tls=true + - traefik.http.routers.grafana.tls.certresolver=lets-encrypt + - traefik.http.services.grafana.loadbalancer.server.port=3000 + - traefik.port=3000 + depends_on: + - node_exporter + - prometheus + node_exporter: + image: quay.io/prometheus/node-exporter:latest + container_name: node_exporter + user: "995:995" + restart: always + networks: + - grafana-network + pid: host + command: + - "--path.rootfs=/host" + volumes: + - "/:/host:ro,rslave" + depends_on: + - prometheus + prometheus: + image: prom/prometheus:latest + container_name: prometheus + restart: always + networks: + - grafana-network + - minecraft_minecraft_network + ports: + - "9090:9090" + volumes: + - "./prometheus.yml:/etc/prometheus.yml" + - prometheus_data:/prometheus + command: + - "--config.file=/etc/prometheus.yml" + - "--storage.tsdb.path=/prometheus" + - "--web.console.libraries=/usr/share/prometheus/console_libraries" + - "--web.console.templates=/usr/share/prometheus/consoles" + + diff --git a/grafana/grafana.ini b/grafana/grafana.ini new file mode 100755 index 0000000..47d057f --- /dev/null +++ b/grafana/grafana.ini @@ -0,0 +1,62 @@ +[paths] +[server] +[database] +[datasources] +[remote_cache] +[dataproxy] +[analytics] +[security] +admin_user = admin +admin_password = admin +[snapshots] +[dashboards] +[users] +default_theme = dark +[auth] +signout_redirect_url = www.whitney.rip +[auth.anonymous] +enabled = true +[auth.github] +[auth.gitlab] +[auth.google] +[auth.grafana_com] +[auth.azuread] +[auth.okta] +[auth.generic_oauth] +[auth.basic] +[auth.proxy] +[auth.jwt] +[auth.ldap] +[aws] +[smtp] +[emails] +[log] +[log.console] +[log.file] +[log.syslog] +[log.frontend] +[quota] +[alerting] +[annotations] +[annotations.dashboard] +[annotations.api] +[explore] +[metrics] +[metrics.environment_info] +[metrics.graphite] +[grafana_com] +[tracing.jaeger] +[external_image_storage] +[external_image_storage.s3] +[external_image_storage.webdav] +[external_image_storage.gcs] +[external_image_storage.azure_blob] +[external_image_storage.local] +[rendering] +[panels] +[plugins] +[plugin.grafana-image-renderer] +[enterprise] +[feature_toggles] +[date_formats] +[expressions] diff --git a/grafana/prometheus.yml b/grafana/prometheus.yml new file mode 100644 index 0000000..1aa5d01 --- /dev/null +++ b/grafana/prometheus.yml @@ -0,0 +1,21 @@ +global: + scrape_interval: 15s + external_labels: + monitor: 'codelab-monitor' +scrape_configs: + - job_name: 'prometheus' + scrape_interval: 5s + static_configs: + - targets: ['localhost:9090'] + - job_name: 'node_exporter' + scrape_interval: 5s + static_configs: + - targets: ['node_exporter:9100'] + - job_name: 'minecraft_2023' + scrape_interval: 5s + static_configs: + - targets: ['minecraft_2023:9225'] + - job_name: 'minecraft_creative' + scrape_interval: 5s + static_configs: + - targets: ['minecraft_creative:9225']