Skip to content

Instantly share code, notes, and snippets.

@dougo-chris
Forked from colinrymer/config-config.exs
Last active September 24, 2018 06:09
Show Gist options
  • Save dougo-chris/3420ecce6bdba45bcd3df638d3112d56 to your computer and use it in GitHub Desktop.
Save dougo-chris/3420ecce6bdba45bcd3df638d3112d56 to your computer and use it in GitHub Desktop.
Phoenix Prometheus Setup
...
defp deps do
[...
{:prometheus, "~> 4.0", override: true},
{:prometheus_ex, "~> 3.0"},
{:prometheus_phoenix, "~> 1.2"},
{:prometheus_plugs, "~> 1.1.5"},
{:prometheus_ecto, "~> 1.0.1"},
{:prometheus_process_collector, "~> 1.3.1"}
...]
end
...
defmodule MyApp.Metrics.PhoenixInstrumenter do
use Prometheus.PhoenixInstrumenter
end
defmodule MyApp.Metrics.EctoInstrumenter do
use Prometheus.EctoInstrumenter
end
defmodule MyApp.Metrics.PipelineInstrumenter do
use Prometheus.PlugPipelineInstrumenter
def label_value(:request_path, conn) do
conn.request_path
end
end
defmodule MyApp.Metrics.PrometheusExporter do
use Prometheus.PlugExporter
end
defmodule MyApp.Metrics.VersionInstrumenter do
use Prometheus.Metric
def setup(otp_app) do
gauge_name = String.to_atom("#{otp_app}_build_info")
Gauge.declare([name: gauge_name,
help: help(otp_app),
labels: [:version],
registry: :default])
Gauge.set([name: gauge_name,
labels: [version(otp_app)],
registry: :default], 1)
end
defp help(otp_app), do: "Build information for the currently deployed version of #{app_name(otp_app)}"
defp app_name(otp_app), do: otp_app |> Atom.to_string() |> String.capitalize()
defp version(otp_app), do: otp_app |> Application.spec() |> Keyword.get(:vsn) |> List.to_string
end
end
defmodule MyApp do
def start(_type, _args) do
import Supervisor.Spec, warn: false
require Prometheus.Registry
MyApp.Metrics.PhoenixInstrumenter.setup()
MyApp.Metrics.PipelineInstrumenter.setup()
MyApp.Metrics.EctoInstrumenter.setup()
Prometheus.Registry.register_collector(:prometheus_process_collector)
MyApp.Metrics.PrometheusExporter.setup()
MyApp.Metrics.VersionInstrumenter.setup(:my_app)
...
defmodule MyApp.Endpoint do
plug MyApp.Metrics.PrometheusExporter
plug MyApp.Metrics.PipelineInstrumenter
plug MyApp.Router
end
...
config :my_app, MyApp.Repo,
...
loggers: [MyApp.Metrics.EctoInstrumenter, Ecto.LogEntry]
# Import environment specific config. This must remain at the bottom
# of this file so it overrides the configuration defined above.
config :prometheus, MyApp.Metrics.PhoenixInstrumenter,
controller_call_labels: [:controller, :action],
duration_buckets: [10, 25, 50, 100, 250, 500, 1000, 2500, 5000,
10_000, 25_000, 50_000, 100_000, 250_000, 500_000,
1_000_000, 2_500_000, 5_000_000, 10_000_000],
registry: :default,
duration_unit: :microseconds
config :prometheus, MyApp.Metrics.PipelineInstrumenter,
labels: [:status_class, :method, :host, :scheme, :request_path],
duration_buckets: [10, 100, 1_000, 10_000, 100_000,
300_000, 500_000, 750_000, 1_000_000,
1_500_000, 2_000_000, 3_000_000],
registry: :default,
duration_unit: :microseconds
...
# my global config
global:
scrape_interval: 15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.
# scrape_timeout is set to the global default (10s).
# Alertmanager configuration
alerting:
alertmanagers:
- static_configs:
- targets:
# - alertmanager:9093
# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
rule_files:
# - "first_rules.yml"
# - "second_rules.yml"
# A scrape configuration containing exactly one endpoint to scrape:
# Here it's Prometheus itself.
scrape_configs:
# The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
- job_name: 'prometheus'
# metrics_path defaults to '/metrics'
# scheme defaults to 'http'.
static_configs:
- targets: ['HOSTNAME:4000']
docker run \
-d \
-p 9090:9090 \
--name=tlive-prometheus \
--volume "$PWD/prometheus.yml:/etc/prometheus/prometheus.yml" \
prom/prometheus
docker run \
-d \
-p 3001:3000 \
--name=tlive-grafana \
--user $ID \
--volume "$PWD/_data:/var/lib/grafana" \
-e "GF_PATHS_LOGS=/var/lib/grafana/logs" \
-e "GF_AUTH_ANONYMOUS_ENABLED=true" \
-e "GF_SECURITY_ADMIN_USER=admin" \
-e "GF_SECURITY_ADMIN_PASSWORD=admin" \
-e "GF_USERS_ALLOW_ORG_CREATE=false" \
-e "GF_USERS_ALLOW_SIGN_UP=false" \
grafana/grafana
https://github.com/deadtrickster/beam-dashboards
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment