Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F112712
prometheus_phx.ex
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Award Token
Flag For Later
Size
3 KB
Referenced Files
None
Subscribers
None
prometheus_phx.ex
View Options
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
]
]
: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
)
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
File Metadata
Details
Attached
Mime Type
text/x-c++
Expires
Sat, Nov 23, 10:29 PM (21 h, 34 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
39170
Default Alt Text
prometheus_phx.ex (3 KB)
Attached To
Mode
R25 prometheus-phx
Attached
Detach File
Event Timeline
Log In to Comment