Skip to content

Instantly share code, notes, and snippets.

@lexmag
Last active November 19, 2020 15:10
Show Gist options
  • Save lexmag/b833080763d09a9a134d3de8df39d071 to your computer and use it in GitHub Desktop.
Save lexmag/b833080763d09a9a134d3de8df39d071 to your computer and use it in GitHub Desktop.
Zen and the Art of Elixir Applications Monitoring
# We do this at compile-time as we don't have Mix available in releases.
@version Mix.Project.config().version
def start(_type, _args) do
#...
with {:ok, _} = result <- Supervisor.start_link(children, options) do
MyApp.Fluxter.write("start", version: @version)
result
end
end
def handle_event([:my_app, :repo, :query], measurements, metadata, %{}) do
fields =
[]
|> Fluxter.put_request_id()
|> include_if_present(measurements, :queue_time)
|> include_if_present(measurements, :query_time)
|> include_if_present(measurements, :decode_time)
MyApp.Fluxter.write("ecto_repo_exec", [repo: metadata.repo], fields)
end
defp include_if_present(fields, measurements, key) do
case measurements do
%{^key => value} ->
microseconds = System.convert_time_unit(value, :native, :microsecond)
[{key, microseconds} | fields]
_ ->
fields
end
end
# Measurements
%{
queue_time: 14,
query_time: 57,
decode_time: 4
}
# Metadata
%{
repo: "foo"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment