Last active
November 19, 2020 15:10
-
-
Save lexmag/b833080763d09a9a134d3de8df39d071 to your computer and use it in GitHub Desktop.
Zen and the Art of Elixir Applications Monitoring
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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