Skip to content
Permalink
Browse files

Code for step 6

  • Loading branch information...
akoutmos committed Aug 21, 2019
1 parent 70161da commit 5c36869fe946cfb63a43f8d2d80caf90e1820258
Showing with 91 additions and 2 deletions.
  1. +21 −1 config/config.exs
  2. +17 −0 lib/elixir_monitoring_prom/application.ex
  3. +4 −0 lib/elixir_monitoring_prom_web/endpoint.ex
  4. +35 −0 lib/instrumenters.ex
  5. +7 −1 mix.exs
  6. +7 −0 mix.lock
@@ -15,7 +15,27 @@ config :elixir_monitoring_prom, ElixirMonitoringPromWeb.Endpoint,
url: [host: "localhost"],
secret_key_base: "nFSyXdlKCXuXTXWhnmEeVnA9VLzzbpuqX3UvpdaPo8uqpgjxd+cZorH+0GobASx8",
render_errors: [view: ElixirMonitoringPromWeb.ErrorView, accepts: ~w(html json)],
pubsub: [name: ElixirMonitoringProm.PubSub, adapter: Phoenix.PubSub.PG2]
pubsub: [name: ElixirMonitoringProm.PubSub, adapter: Phoenix.PubSub.PG2],
instrumenters: [ElixirMonitoringProm.PhoenixInstrumenter]

config :prometheus, ElixirMonitoringProm.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

# Configures Elixir's Logger
config :logger, :console,
@@ -6,6 +6,23 @@ defmodule ElixirMonitoringProm.Application do
use Application

def start(_type, _args) do
# Start all the instrumenters
ElixirMonitoringProm.PhoenixInstrumenter.setup()
ElixirMonitoringProm.PipelineInstrumenter.setup()
ElixirMonitoringProm.RepoInstrumenter.setup()
ElixirMonitoringProm.PrometheusExporter.setup()

# NOTE: Only for FreeBSD, Linux and OSX (experimental)
# https://github.com/deadtrickster/prometheus_process_collector
Prometheus.Registry.register_collector(:prometheus_process_collector)

:telemetry.attach(
"prometheus-ecto",
[:elixir_monitoring_prom, :repo, :query],
&ElixirMonitoringProm.RepoInstrumenter.handle_event/4,
nil
)

# List all child processes to be supervised
children = [
# Start the Ecto repository
@@ -42,5 +42,9 @@ defmodule ElixirMonitoringPromWeb.Endpoint do
key: "_elixir_monitoring_prom_key",
signing_salt: "iPbxnMI/"

# Creates the /metrics endpoint for prometheus & collect stats
plug ElixirMonitoringProm.PrometheusExporter
plug ElixirMonitoringProm.PipelineInstrumenter

plug ElixirMonitoringPromWeb.Router
end
@@ -0,0 +1,35 @@
defmodule ElixirMonitoringProm.PhoenixInstrumenter do
@moduledoc "Prometheus instrmenter for Phoenix"

use Prometheus.PhoenixInstrumenter
end

defmodule ElixirMonitoringProm.PipelineInstrumenter do
@moduledoc "Prometheus instrmenter for Phoenix"

use Prometheus.PlugPipelineInstrumenter

def label_value(:request_path, conn) do
case Phoenix.Router.route_info(
ElixirMonitoringPromWeb.Router,
conn.method,
conn.request_path,
""
) do
%{route: path} -> path
_ -> "unkown"
end
end
end

defmodule ElixirMonitoringProm.RepoInstrumenter do
@moduledoc "Prometheus instrmenter for Phoenix"

use Prometheus.EctoInstrumenter
end

defmodule ElixirMonitoringProm.PrometheusExporter do
@moduledoc "Prometheus instrmenter for Phoenix"

use Prometheus.PlugExporter
end
@@ -45,7 +45,13 @@ defmodule ElixirMonitoringProm.MixProject do
{:plug_cowboy, "~> 2.0"},
{:geo, "~> 3.1.0"},
{:geo_postgis, "~> 3.1.0"},
{:faker, "~> 0.12.0"}
{:faker, "~> 0.12.0"},
{:prometheus, "~> 4.4.1"},
{:prometheus_ex, "~> 3.0.5"},
{:prometheus_ecto, "~> 1.4.3"},
{:prometheus_phoenix, "~> 1.3.0"},
{:prometheus_plugs, "~> 1.1.5"},
{:prometheus_process_collector, "~> 1.4.3"}
]
end

@@ -1,4 +1,5 @@
%{
"accept": {:hex, :accept, "0.3.5", "b33b127abca7cc948bbe6caa4c263369abf1347cfa9d8e699c6d214660f10cd1", [:rebar3], [], "hexpm"},
"connection": {:hex, :connection, "1.0.4", "a1cae72211f0eef17705aaededacac3eb30e6625b04a6117c1b2db6ace7d5976", [:mix], [], "hexpm"},
"cowboy": {:hex, :cowboy, "2.6.3", "99aa50e94e685557cad82e704457336a453d4abcb77839ad22dbe71f311fcc06", [:rebar3], [{:cowlib, "~> 2.7.3", [hex: :cowlib, repo: "hexpm", optional: false]}, {:ranch, "~> 1.7.1", [hex: :ranch, repo: "hexpm", optional: false]}], "hexpm"},
"cowlib": {:hex, :cowlib, "2.7.3", "a7ffcd0917e6d50b4d5fb28e9e2085a0ceb3c97dea310505f7460ff5ed764ce9", [:rebar3], [], "hexpm"},
@@ -22,6 +23,12 @@
"plug_cowboy": {:hex, :plug_cowboy, "2.1.0", "b75768153c3a8a9e8039d4b25bb9b14efbc58e9c4a6e6a270abff1cd30cbe320", [:mix], [{:cowboy, "~> 2.5", [hex: :cowboy, repo: "hexpm", optional: false]}, {:plug, "~> 1.7", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm"},
"plug_crypto": {:hex, :plug_crypto, "1.0.0", "18e49317d3fa343f24620ed22795ec29d4a5e602d52d1513ccea0b07d8ea7d4d", [:mix], [], "hexpm"},
"postgrex": {:hex, :postgrex, "0.15.0", "dd5349161019caeea93efa42f9b22f9d79995c3a86bdffb796427b4c9863b0f0", [:mix], [{:connection, "~> 1.0", [hex: :connection, repo: "hexpm", optional: false]}, {:db_connection, "~> 2.1", [hex: :db_connection, repo: "hexpm", optional: false]}, {:decimal, "~> 1.5", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}], "hexpm"},
"prometheus": {:hex, :prometheus, "4.4.1", "1e96073b3ed7788053768fea779cbc896ddc3bdd9ba60687f2ad50b252ac87d6", [:mix, :rebar3], [], "hexpm"},
"prometheus_ecto": {:hex, :prometheus_ecto, "1.4.3", "3dd4da1812b8e0dbee81ea58bb3b62ed7588f2eae0c9e97e434c46807ff82311", [:mix], [{:ecto, "~> 2.0 or ~> 3.0", [hex: :ecto, repo: "hexpm", optional: false]}, {:prometheus_ex, "~> 1.1 or ~> 2.0 or ~> 3.0", [hex: :prometheus_ex, repo: "hexpm", optional: false]}], "hexpm"},
"prometheus_ex": {:hex, :prometheus_ex, "3.0.5", "fa58cfd983487fc5ead331e9a3e0aa622c67232b3ec71710ced122c4c453a02f", [:mix], [{:prometheus, "~> 4.0", [hex: :prometheus, repo: "hexpm", optional: false]}], "hexpm"},
"prometheus_phoenix": {:hex, :prometheus_phoenix, "1.3.0", "c4b527e0b3a9ef1af26bdcfbfad3998f37795b9185d475ca610fe4388fdd3bb5", [:mix], [{:phoenix, "~> 1.4", [hex: :phoenix, repo: "hexpm", optional: false]}, {:prometheus_ex, "~> 1.3 or ~> 2.0 or ~> 3.0", [hex: :prometheus_ex, repo: "hexpm", optional: false]}], "hexpm"},
"prometheus_plugs": {:hex, :prometheus_plugs, "1.1.5", "25933d48f8af3a5941dd7b621c889749894d8a1082a6ff7c67cc99dec26377c5", [:mix], [{:accept, "~> 0.1", [hex: :accept, repo: "hexpm", optional: false]}, {:plug, "~> 1.0", [hex: :plug, repo: "hexpm", optional: false]}, {:prometheus_ex, "~> 1.1 or ~> 2.0 or ~> 3.0", [hex: :prometheus_ex, repo: "hexpm", optional: false]}, {:prometheus_process_collector, "~> 1.1", [hex: :prometheus_process_collector, repo: "hexpm", optional: true]}], "hexpm"},
"prometheus_process_collector": {:hex, :prometheus_process_collector, "1.4.3", "657386e8f142fc817347d95c1f3a05ab08710f7df9e7f86db6facaed107ed929", [:rebar3], [{:prometheus, "~> 4.0", [hex: :prometheus, repo: "hexpm", optional: false]}], "hexpm"},
"ranch": {:hex, :ranch, "1.7.1", "6b1fab51b49196860b733a49c07604465a47bdb78aa10c1c16a3d199f7f8c881", [:rebar3], [], "hexpm"},
"telemetry": {:hex, :telemetry, "0.4.0", "8339bee3fa8b91cb84d14c2935f8ecf399ccd87301ad6da6b71c09553834b2ab", [:rebar3], [], "hexpm"},
}

0 comments on commit 5c36869

Please sign in to comment.
You can’t perform that action at this time.