Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F113571
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Award Token
Flag For Later
Size
5 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/lib/prometheus_phx.ex b/lib/prometheus_phx.ex
index a8827b6..d928242 100644
--- a/lib/prometheus_phx.ex
+++ b/lib/prometheus_phx.ex
@@ -1,141 +1,145 @@
defmodule PrometheusPhx do
use Prometheus.Metric
require Logger
require Prometheus.Contrib.HTTP
alias Prometheus.Contrib.HTTP
@duration_unit :microseconds
def setup do
events = [
[:phoenix, :endpoint, :stop],
[:phoenix, :error_rendered],
[:phoenix, :channel_joined],
[:phoenix, :channel_handled_in]
]
+ Logger.info "Attaching the phoenix telemetry events: #{inspect events}"
+
:telemetry.attach_many(
"telemetry_web__event_handler",
events,
&handle_event/4,
nil
)
Histogram.declare(
name: :"phoenix_controller_call_duration_#{@duration_unit}",
help: "Whole controller pipeline execution time in #{@duration_unit}.",
labels: [:action, :controller, :status],
buckets: HTTP.microseconds_duration_buckets(),
duration_unit: @duration_unit,
registry: :default
)
Histogram.declare(
name: :"phoenix_controller_error_rendered_duration_#{@duration_unit}",
help: "View error rendering time in #{@duration_unit}.",
labels: [:action, :controller, :status],
buckets: HTTP.microseconds_duration_buckets(),
duration_unit: @duration_unit,
registry: :default
)
Histogram.declare(
name: :"phoenix_channel_join_duration_#{@duration_unit}",
help: "Phoenix channel join handler time in #{@duration_unit}",
labels: [:channel, :topic, :transport],
buckets: HTTP.microseconds_duration_buckets(),
duration_unit: @duration_unit,
registry: :default
)
Histogram.declare(
name: :"phoenix_channel_receive_duration_#{@duration_unit}",
help: "Phoenix channel receive handler time in #{@duration_unit}",
labels: [:channel, :topic, :transport, :event],
buckets: HTTP.microseconds_duration_buckets(),
duration_unit: @duration_unit,
registry: :default
)
end
def handle_event([:phoenix, :endpoint, :stop], %{duration: duration}, metadata, _config) do
labels = labels(metadata)
+ Logger.info "Recording event phoenix_controller_call_duration_#{@duration_unit} for #{inspect labels}"
+
Histogram.observe(
[
name: :"phoenix_controller_call_duration_#{@duration_unit}",
labels: labels,
registry: :default
],
duration
)
end
def handle_event([:phoenix, :error_rendered], %{duration: duration}, metadata, _config) do
labels = labels(metadata)
Histogram.observe(
[
name: :"phoenix_controller_error_rendered_duration_#{@duration_unit}",
labels: labels,
registry: :default
],
duration
)
end
def handle_event([:phoenix, :channel_joined], %{duration: duration}, metadata, _config) do
labels = labels(metadata)
Histogram.observe(
[
name: :"phoenix_channel_join_duration_#{@duration_unit}",
labels: labels,
registry: :default
],
duration
)
end
def handle_event([:phoenix, :channel_handled_in], %{duration: duration}, metadata, _config) do
labels = labels(metadata)
Histogram.observe(
[
name: :"phoenix_channel_receive_duration_#{@duration_unit}",
labels: labels,
registry: :default
],
duration
)
end
def labels(%{
status: status,
conn: %{private: %{phoenix_action: action, phoenix_controller: controller}}
}) do
[controller, action, status]
end
def labels(%{
conn: %{
status: status,
private: %{phoenix_action: action, phoenix_controller: controller}
}
}) do
[controller, action, status]
end
def labels(%{status: status, stacktrace: [{module, function, _, _} | _]}) do
[module, function, status]
end
def labels(%{event: event, socket: %{channel: channel, topic: topic, transport: transport}}) do
[channel, topic, transport, event]
end
def labels(%{socket: %{channel: channel, topic: topic, transport: transport}}) do
[channel, topic, transport]
end
end
diff --git a/mix.exs b/mix.exs
index f45aded..649a536 100644
--- a/mix.exs
+++ b/mix.exs
@@ -1,33 +1,38 @@
defmodule PrometheusPhx.MixProject do
use Mix.Project
def project do
[
app: :prometheus_phx,
- version: "0.1.0",
+ version: "0.1.1",
elixir: "~> 1.8",
+ build_embedded: Mix.env() == :prod,
start_permanent: Mix.env() == :prod,
elixirc_paths: elixirc_paths(Mix.env()),
compilers: compilers(Mix.env()),
deps: deps()
]
end
+ def application do
+ [applications: [:logger, :prometheus_ex]]
+ end
+
defp elixirc_paths(:test), do: ["lib", "test/support"]
defp elixirc_paths(_), do: ["lib"]
defp deps do
[
{:prometheus_ex, "~> 3.0"},
{:phoenix, "~> 1.5.1", only: [:test]},
{:phoenix_html, "~> 2.11", only: [:test]},
{:telemetry_metrics, "~> 0.4", only: [:test]},
{:telemetry_poller, "~> 0.4", only: [:test]},
{:jason, "~> 1.0", only: [:test]},
{:plug_cowboy, "~> 2.0", only: [:test]}
]
end
def compilers(:test), do: [:phoenix] ++ Mix.compilers()
def compilers(_), do: Mix.compilers()
end
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Mon, Nov 25, 10:15 AM (1 d, 13 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
39765
Default Alt Text
(5 KB)
Attached To
Mode
R25 prometheus-phx
Attached
Detach File
Event Timeline
Log In to Comment