-
Notifications
You must be signed in to change notification settings - Fork 194
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
104 additions
and
22 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
DATABASE_URL=postgresql://postgres:password@localhost:54321/electric |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,11 @@ | ||
defmodule Electric do | ||
@moduledoc """ | ||
Documentation for `Electric`. | ||
""" | ||
|
||
@doc """ | ||
Hello world. | ||
## Examples | ||
iex> Electric.hello() | ||
:world | ||
Every electric cluster belongs to a particular console database instance | ||
This is that database instance id | ||
""" | ||
def hello do | ||
:world | ||
@spec instance_id() :: binary | no_return | ||
def instance_id do | ||
Application.fetch_env!(:electric, :instance_id) | ||
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
defmodule Electric.Telemetry do | ||
use Supervisor | ||
import Telemetry.Metrics | ||
|
||
def start_link(init_arg) do | ||
Supervisor.start_link(__MODULE__, init_arg, name: __MODULE__) | ||
end | ||
|
||
def init(_) do | ||
children = [ | ||
{:telemetry_poller, measurements: periodic_measurements(), period: 2_000} | ||
] | ||
|
||
children | ||
|> add_statsd_reporter(Application.fetch_env!(:electric, :telemetry_statsd_host)) | ||
|> Supervisor.init(strategy: :one_for_one) | ||
end | ||
|
||
defp add_statsd_reporter(children, nil), do: children | ||
|
||
defp add_statsd_reporter(children, host) do | ||
children ++ | ||
[ | ||
{TelemetryMetricsStatsd, | ||
host: host, | ||
formatter: :datadog, | ||
global_tags: [instance_id: Electric.instance_id()], | ||
metrics: statsd_metrics()} | ||
] | ||
end | ||
|
||
defp statsd_metrics() do | ||
[ | ||
last_value("vm.memory.total", unit: :byte), | ||
last_value("vm.memory.processes_used", unit: :byte), | ||
last_value("vm.memory.binary", unit: :byte), | ||
last_value("vm.memory.ets", unit: :byte), | ||
last_value("vm.total_run_queue_lengths.total"), | ||
last_value("vm.total_run_queue_lengths.cpu"), | ||
last_value("vm.total_run_queue_lengths.io"), | ||
summary("plug.router_dispatch.stop.duration", | ||
tags: [:route], | ||
unit: {:native, :millisecond} | ||
), | ||
summary("plug.router_dispatch.exception.duration", | ||
tags: [:route], | ||
unit: {:native, :millisecond} | ||
) | ||
] | ||
|> Enum.map(&%{&1 | tags: [:instance_id | &1.tags]}) | ||
end | ||
|
||
defp periodic_measurements do | ||
[ | ||
# A module, function and arguments to be invoked periodically. | ||
{__MODULE__, :uptime_event, []} | ||
] | ||
end | ||
|
||
def uptime_event do | ||
:telemetry.execute([:vm, :uptime], %{ | ||
total: :erlang.monotonic_time() - :erlang.system_info(:start_time) | ||
}) | ||
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
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
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
This file was deleted.
Oops, something went wrong.