Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 1 addition & 29 deletions lib/instruments.ex
Original file line number Diff line number Diff line change
Expand Up @@ -199,35 +199,7 @@ defmodule Instruments do
title_iodata = MacroHelpers.to_iolist(title_ast, __CALLER__)

quote do
title = unquote(title_iodata)

header = [
"_e{",
Integer.to_charlist(IO.iodata_length(title)),
",",
Integer.to_charlist(IO.iodata_length(unquote(text))),
"}:",
title,
"|",
unquote(text)
]

message =
case Keyword.get(unquote(opts), :tags) do
nil ->
header

tag_list ->
[header, "|#", Enum.intersperse(tag_list, ",")]
end

# Statix registers a port to the name of the metrics module.
# and this code assumes that the metrics module is bound to
# a port, and sends directly to it. If we move off of Statix,
# this will have to be changed.
unquote(@metrics_module)
|> Process.whereis()
|> :gen_udp.send(Instruments.statsd_host(), Instruments.statsd_port(), message)
unquote(@metrics_module).send_event(unquote(title_iodata), unquote(text), unquote(opts))
end
end

Expand Down
19 changes: 17 additions & 2 deletions lib/probes/schedulers.ex
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,13 @@ defmodule Instruments.Probes.Schedulers do

This module reports Erlang's internal view of its scheduler utilization and is
a better gauge of how loaded your system is. It reports two values, the total
utilization, and a [weighted utilization](http://erlang.org/doc/man/erlang.html#statistics_scheduler_wall_time),
which can be used as a proxy for CPU usage.
utilization, and a [weighted
utilization](http://erlang.org/doc/man/erlang.html#statistics_scheduler_wall_time),
which can be used as a proxy for CPU usage. Weighted utilization is calculated
based on the number of logical CPUs available, but in containerized
environments, the number of CPUs available may differ from what erlang
reports. In these cases, you can override the count by configuring
`num_logical_processors_override` on the `instruments` application.

To use this probe, add the following function somewhwere in your application's
initialization:
Expand Down Expand Up @@ -104,6 +109,16 @@ defmodule Instruments.Probes.Schedulers do
end

defp logical_processor_count() do
case Application.fetch_env(:instruments, :num_logical_processors_override) do
{:ok, override} when is_integer(override) ->
override

:error ->
actual_logical_processor_count()
end
end

defp actual_logical_processor_count() do
case :erlang.system_info(:logical_processors_available) do
:unknown ->
:erlang.system_info(:logical_processors_online)
Expand Down
7 changes: 7 additions & 0 deletions lib/stats_reporter.ex
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,11 @@ defmodule Instruments.StatsReporter do
Write the value into the set defined by `key`
"""
@callback set(key, integer, keyword) :: stats_return

@doc """
Send a DataDog event with the given title and text
"""
@callback send_event(title :: iodata, text :: iodata, keyword) :: stats_return

@optional_callbacks [send_event: 3]
end
5 changes: 5 additions & 0 deletions lib/stats_reporter/logger.ex
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,9 @@ defmodule Instruments.StatsReporter.Logger do
def set(key, value, _options \\ []) do
Logger.info("setting #{key} to #{value}")
end

@doc false
def send_event(title, text, _options \\ []) do
Logger.info("event #{title}: #{text}")
end
end
3 changes: 3 additions & 0 deletions lib/stats_reporter/null.ex
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,7 @@ defmodule Instruments.StatsReporter.Null do

@doc false
def set(_key, _value, _options \\ []), do: :ok

@doc false
def send_event(_title, _text, _options \\ []), do: :ok
end
4 changes: 2 additions & 2 deletions mix.exs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
defmodule Instruments.Mixfile do
use Mix.Project

@version "2.6.0"
@version "2.11.0"
@github_url "https://github.com/discord/instruments"

def project do
Expand Down Expand Up @@ -51,7 +51,7 @@ defmodule Instruments.Mixfile do
{:benchee, "~> 1.4", only: :dev},
{:ex_doc, "~> 0.28", only: :dev, runtime: false},
{:recon, "~> 2.5.2"},
{:statix, "~> 1.5.1", hex: :discord_statix},
{:statix, "~> 1.8.0", hex: :discord_statix},
{:dialyxir, "~> 1.0", only: :dev, runtime: false}
]
end
Expand Down
3 changes: 1 addition & 2 deletions mix.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
"benchee": {:hex, :benchee, "1.4.0", "9f1f96a30ac80bab94faad644b39a9031d5632e517416a8ab0a6b0ac4df124ce", [:mix], [{:deep_merge, "~> 1.0", [hex: :deep_merge, repo: "hexpm", optional: false]}, {:statistex, "~> 1.0", [hex: :statistex, repo: "hexpm", optional: false]}, {:table, "~> 0.1.0", [hex: :table, repo: "hexpm", optional: true]}], "hexpm", "299cd10dd8ce51c9ea3ddb74bb150f93d25e968f93e4c1fa31698a8e4fa5d715"},
"deep_merge": {:hex, :deep_merge, "1.0.0", "b4aa1a0d1acac393bdf38b2291af38cb1d4a52806cf7a4906f718e1feb5ee961", [:mix], [], "hexpm", "ce708e5f094b9cd4e8f2be4f00d2f4250c4095be93f8cd6d018c753894885430"},
"dialyxir": {:hex, :dialyxir, "1.0.0", "6a1fa629f7881a9f5aaf3a78f094b2a51a0357c843871b8bc98824e7342d00a5", [:mix], [{:erlex, ">= 0.2.6", [hex: :erlex, repo: "hexpm", optional: false]}], "hexpm", "aeb06588145fac14ca08d8061a142d52753dbc2cf7f0d00fc1013f53f8654654"},
"discord_statix": {:hex, :discord_statix, "1.5.1", "e0904aef402628beb91548f6e1b9d2f2a6923810605bc5a2ac56b22663c82610", [:mix], [], "hexpm", "dff9d1b114204fb7a49b429bdeaf24fe92576f63f2c756d9d89a3eadd2004a33"},
"earmark": {:hex, :earmark, "1.3.1", "73812f447f7a42358d3ba79283cfa3075a7580a3a2ed457616d6517ac3738cb9", [:mix], [], "hexpm", "000aaeff08919e95e7aea13e4af7b2b9734577b3e6a7c50ee31ee88cab6ec4fb"},
"earmark_parser": {:hex, :earmark_parser, "1.4.26", "f4291134583f373c7d8755566122908eb9662df4c4b63caa66a0eabe06569b0a", [:mix], [], "hexpm", "48d460899f8a0c52c5470676611c01f64f3337bad0b26ddab43648428d94aabc"},
"erlex": {:hex, :erlex, "0.2.6", "c7987d15e899c7a2f34f5420d2a2ea0d659682c06ac607572df55a43753aa12e", [:mix], [], "hexpm", "2ed2e25711feb44d52b17d2780eabf998452f6efda104877a3881c2f8c0c0c75"},
Expand All @@ -13,5 +12,5 @@
"nimble_parsec": {:hex, :nimble_parsec, "1.2.3", "244836e6e3f1200c7f30cb56733fd808744eca61fd182f731eac4af635cc6d0b", [:mix], [], "hexpm", "c8d789e39b9131acf7b99291e93dae60ab48ef14a7ee9d58c6964f59efb570b0"},
"recon": {:hex, :recon, "2.5.2", "cba53fa8db83ad968c9a652e09c3ed7ddcc4da434f27c3eaa9ca47ffb2b1ff03", [:mix, :rebar3], [], "hexpm", "2c7523c8dee91dff41f6b3d63cba2bd49eb6d2fe5bf1eec0df7f87eb5e230e1c"},
"statistex": {:hex, :statistex, "1.1.0", "7fec1eb2f580a0d2c1a05ed27396a084ab064a40cfc84246dbfb0c72a5c761e5", [:mix], [], "hexpm", "f5950ea26ad43246ba2cce54324ac394a4e7408fdcf98b8e230f503a0cba9cf5"},
"statix": {:hex, :discord_statix, "1.5.1", "e0904aef402628beb91548f6e1b9d2f2a6923810605bc5a2ac56b22663c82610", [:mix], [], "hexpm", "dff9d1b114204fb7a49b429bdeaf24fe92576f63f2c756d9d89a3eadd2004a33"},
"statix": {:hex, :discord_statix, "1.8.0", "11a5daa60029b39cfab2e11f7158bb1be3a426a9349731145184c3e257bd820a", [:mix], [], "hexpm", "a840f9c2f5789986830cb259e50947c5263c09eaf8c1662b9511f28e772a7acd"},
}