Discourse Prometheus 404 metrics for Grafana

I have managed to make this work. My problems were:

  1. My instance redirects to `https`
  2. The default grafana configuration for `alloy` was trying to reach localhost:80 (if you don’t know, `alloy` is a prometheus-like server that grafana spins and reads `/metrics` to expose them to grafana)

this is what my config looks like in case it helps anyone

... removed the part that's auto generated when installing alloy ...

discovery.relabel "metrics_integrations_integrations_discourse" {
	targets = [{
		__address__ = "your.domain.com", # <--- THIS IS A CHANGE I DID 
		__scheme__  = "https", # <--- THIS IS A CHANGE I DID 
	}]

	rule {
		target_label = "instance"
		replacement  = constants.hostname
	}
}

prometheus.scrape "metrics_integrations_integrations_discourse" {
	targets    = discovery.relabel.metrics_integrations_integrations_discourse.output
	forward_to = [prometheus.relabel.metrics_integrations_integrations_discourse.receiver]
	job_name   = "integrations/discourse"

	tls_config {
		insecure_skip_verify = true # <--- THIS IS A CHANGE I DID 
	}
}

prometheus.relabel "metrics_integrations_integrations_discourse" {
	forward_to = [prometheus.remote_write.metrics_service.receiver]

	rule {
		source_labels = ["__name__"]
		regex         = "up|discourse_active_app_reqs|discourse_http_duration_seconds|discourse_http_requests|discourse_page_views|discourse_queued_app_reqs|discourse_rss|discourse_scheduled_job_count|discourse_scheduled_job_duration_seconds|discourse_sidekiq_job_count|discourse_sidekiq_job_duration_seconds|discourse_sidekiq_jobs_enqueued|discourse_v8_used_heap_size"
		action        = "keep"
	}
}

with this grafana started getting data…

Don’t forget to set DISCOURSE_PROMETHEUS_TRUSTED_IP_ALLOWLIST_REGEX

I searched for grafana’s IPs and added them all as a long line, there may be a better or smarter way but I couldn’t find it lol

here’s an example of adding multiple ips

DISCOURSE_PROMETHEUS_TRUSTED_IP_ALLOWLIST_REGEX: "^(localhost|127\\.0\\.0\\.1|::1)$