Browse Source

feat: Add monitoring stack

pull/3/head
Karan Sharma 1 year ago
parent
commit
0864db1a72
  1. 7
      floyd/terraform/caddy/conf/Caddyfile.tpl
  2. 5
      floyd/terraform/main.tf
  3. 51
      floyd/terraform/monitoring/cadviser.tf
  4. 19
      floyd/terraform/monitoring/conf/prometheus.yml
  5. 0
      floyd/terraform/monitoring/data.tf
  6. 31
      floyd/terraform/monitoring/grafana.tf
  7. 35
      floyd/terraform/monitoring/image.tf
  8. 5
      floyd/terraform/monitoring/network.tf
  9. 40
      floyd/terraform/monitoring/nodeexporter.tf
  10. 39
      floyd/terraform/monitoring/prometheus.tf
  11. 3
      floyd/terraform/monitoring/variables.tf
  12. 8
      floyd/terraform/monitoring/versions.tf

7
floyd/terraform/caddy/conf/Caddyfile.tpl

@ -18,3 +18,10 @@ wiki.mrkaran.dev {
dns cloudflare "${cloudflare_api_token}"
}
}
grafana.mrkaran.dev {
reverse_proxy grafana:3000
tls {
dns cloudflare "${cloudflare_api_token}"
}
}

5
floyd/terraform/main.tf

@ -28,3 +28,8 @@ module "caddy" {
ips = var.ips
cloudflare_api_token = var.cloudflare_api_token
}
module "monitoring" {
source = "./monitoring"
ips = var.ips
}

51
floyd/terraform/monitoring/cadviser.tf

@ -0,0 +1,51 @@
# Referred to https://github.com/google/cadvisor
# and https://prometheus.io/docs/guides/cadvisor/.
resource "docker_container" "cadvisor" {
name = "cadvisor"
image = docker_image.cadvisor.latest
volumes {
host_path = "/"
container_path = "/rootfs"
read_only = true
}
volumes {
host_path = "/var/run"
container_path = "/var/run"
read_only = true
}
volumes {
host_path = "/sys"
container_path = "/sys"
read_only = true
}
volumes {
host_path = "/var/lib/docker"
container_path = "/var/lib/docker"
read_only = true
}
volumes {
host_path = "/dev/disk"
container_path = "/dev/disk"
read_only = true
}
networks_advanced {
name = docker_network.monitoring.name
}
devices {
host_path = "/dev/kmsg"
}
privileged = true
restart = "unless-stopped"
destroy_grace_seconds = 30
must_run = true
}

19
floyd/terraform/monitoring/conf/prometheus.yml

@ -0,0 +1,19 @@
global:
scrape_interval: 15s
external_labels:
hydra_component: "floyd"
scrape_configs:
- job_name: "prometheus"
static_configs:
- targets: ["localhost:9090"]
- job_name: "node"
scrape_interval: 5s
static_configs:
- targets: ["nodeexporter:9100"]
- job_name: "cadvisor"
scrape_interval: 5s
static_configs:
- targets: ["cadvisor:8080"]

0
floyd/terraform/monitoring/data.tf

31
floyd/terraform/monitoring/grafana.tf

@ -0,0 +1,31 @@
# Referred to https://github.com/stefanprodan/dockprom/blob/master/docker-compose.yml
resource "docker_container" "grafana" {
name = "grafana"
image = docker_image.grafana.latest
ports {
internal = 3000
external = 9000
ip = var.ips["tailscale_floyd"]
protocol = "tcp"
}
volumes {
host_path = "/data/grafana"
container_path = "/var/lib/grafana"
}
networks_advanced {
name = docker_network.monitoring.name
}
networks_advanced {
name = "caddy"
}
user = "root"
restart = "unless-stopped"
destroy_grace_seconds = 30
must_run = true
}

35
floyd/terraform/monitoring/image.tf

@ -0,0 +1,35 @@
data "docker_registry_image" "cadvisor" {
name = "gcr.io/cadvisor/cadvisor:v0.36.0"
}
resource "docker_image" "cadvisor" {
name = data.docker_registry_image.cadvisor.name
pull_triggers = [data.docker_registry_image.cadvisor.sha256_digest]
}
data "docker_registry_image" "grafana" {
name = "grafana/grafana:7.1.4-ubuntu"
}
resource "docker_image" "grafana" {
name = data.docker_registry_image.grafana.name
pull_triggers = [data.docker_registry_image.grafana.sha256_digest]
}
data "docker_registry_image" "prometheus" {
name = "prom/prometheus:v2.20.1"
}
resource "docker_image" "prometheus" {
name = data.docker_registry_image.prometheus.name
pull_triggers = [data.docker_registry_image.prometheus.sha256_digest]
}
data "docker_registry_image" "nodeexporter" {
name = "prom/node-exporter:v1.0.1"
}
resource "docker_image" "nodeexporter" {
name = data.docker_registry_image.nodeexporter.name
pull_triggers = [data.docker_registry_image.nodeexporter.sha256_digest]
}

5
floyd/terraform/monitoring/network.tf

@ -0,0 +1,5 @@
resource "docker_network" "monitoring" {
name = "monitoring"
driver = "bridge"
internal = "false"
}

40
floyd/terraform/monitoring/nodeexporter.tf

@ -0,0 +1,40 @@
# Referred to https://github.com/stefanprodan/dockprom/blob/master/docker-compose.yml
resource "docker_container" "nodeexporter" {
name = "nodeexporter"
image = docker_image.nodeexporter.latest
command = [
"--path.procfs=/host/proc",
"--path.rootfs=/rootfs",
"--path.sysfs=/host/sys",
"--collector.filesystem.ignored-mount-points=^/(sys|proc|dev|host|etc)($$|/)"
]
volumes {
host_path = "/proc"
container_path = "/host/proc"
read_only = true
}
volumes {
host_path = "/sys"
container_path = "/host/sys"
read_only = true
}
volumes {
host_path = "/"
container_path = "/rootfs"
read_only = true
}
networks_advanced {
name = docker_network.monitoring.name
}
user = "root"
restart = "unless-stopped"
destroy_grace_seconds = 30
must_run = true
}

39
floyd/terraform/monitoring/prometheus.tf

@ -0,0 +1,39 @@
# Referred to https://github.com/stefanprodan/dockprom/blob/master/docker-compose.yml
resource "docker_container" "prometheus" {
name = "prometheus"
image = docker_image.prometheus.latest
command = [
"--config.file=/etc/prometheus/prometheus.yml",
"--storage.tsdb.path=/prometheus",
"--web.console.libraries=/etc/prometheus/console_libraries",
"--web.console.templates=/etc/prometheus/consoles",
"--storage.tsdb.retention.time=30d",
"--web.enable-lifecycle"
]
volumes {
host_path = "/data/prometheus/config"
container_path = "/etc/prometheus"
}
volumes {
host_path = "/data/prometheus/data"
container_path = "/prometheus"
}
upload {
content = "${file("${path.module}/conf/prometheus.yml")}"
file = "/etc/prometheus/prometheus.yml"
}
networks_advanced {
name = docker_network.monitoring.name
}
user = "root"
restart = "unless-stopped"
destroy_grace_seconds = 30
must_run = true
}

3
floyd/terraform/monitoring/variables.tf

@ -0,0 +1,3 @@
variable "ips" {
type = map
}

8
floyd/terraform/monitoring/versions.tf

@ -0,0 +1,8 @@
terraform {
required_providers {
docker = {
source = "terraform-providers/docker"
}
}
required_version = ">= 0.13"
}
Loading…
Cancel
Save