Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F113348
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Award Token
Flag For Later
Size
6 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/lib/prometheus_phx.ex b/lib/prometheus_phx.ex
index c3f0c39..c820aac 100644
--- a/lib/prometheus_phx.ex
+++ b/lib/prometheus_phx.ex
@@ -1,145 +1,158 @@
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}"
+ 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
- )
+ def handle_event([:phoenix, :endpoint, :stop] = event, %{duration: duration}, metadata, _config) do
+ with labels when is_list(labels) <- labels(metadata) do
+ Logger.info("Recording the phoenix telemetry events: #{inspect(event)}")
+
+ Histogram.observe(
+ [
+ name: :"phoenix_controller_call_duration_#{@duration_unit}",
+ labels: labels,
+ registry: :default
+ ],
+ duration
+ )
+ end
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
- )
+ def handle_event([:phoenix, :error_rendered] = event, %{duration: duration}, metadata, _config) do
+ with labels when is_list(labels) <- labels(metadata) do
+ Logger.info("Recording the phoenix telemetry events: #{inspect(event)}")
+
+ Histogram.observe(
+ [
+ name: :"phoenix_controller_error_rendered_duration_#{@duration_unit}",
+ labels: labels,
+ registry: :default
+ ],
+ duration
+ )
+ end
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
- )
+ def handle_event([:phoenix, :channel_joined] = event, %{duration: duration}, metadata, _config) do
+ with labels when is_list(labels) <- labels(metadata) do
+ Logger.info("Recording the phoenix telemetry events: #{inspect(event)}")
+
+ Histogram.observe(
+ [
+ name: :"phoenix_channel_join_duration_#{@duration_unit}",
+ labels: labels,
+ registry: :default
+ ],
+ duration
+ )
+ end
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
- )
+ def handle_event(
+ [:phoenix, :channel_handled_in] = event,
+ %{duration: duration},
+ metadata,
+ _config
+ ) do
+ with labels when is_list(labels) <- labels(metadata) do
+ Logger.info("Recording the phoenix telemetry events: #{inspect(event)}")
+
+ Histogram.observe(
+ [
+ name: :"phoenix_channel_receive_duration_#{@duration_unit}",
+ labels: labels,
+ registry: :default
+ ],
+ duration
+ )
+ end
end
def labels(%{
status: status,
conn: %{private: %{phoenix_action: action, phoenix_controller: controller}}
}) do
[action, controller, status]
end
def labels(%{
conn: %{
status: status,
private: %{phoenix_action: action, phoenix_controller: controller}
}
}) do
[action, controller, status]
end
def labels(%{status: status, stacktrace: [{module, function, _, _} | _]}) do
[function, module, 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
+
+ def labels(_metadata), do: nil
end
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Mon, Nov 25, 4:04 AM (1 d, 9 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
39572
Default Alt Text
(6 KB)
Attached To
Mode
R25 prometheus-phx
Attached
Detach File
Event Timeline
Log In to Comment