-
Notifications
You must be signed in to change notification settings - Fork 181
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added a prometheus metrics exporter (#51)
- Exposes metrics on `:9568/metrics` - Defines basic VM metrics and basic Postgres/Vaxine replication stream events.
- Loading branch information
1 parent
e1c0e2e
commit 67d0248
Showing
11 changed files
with
161 additions
and
7 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,33 @@ | ||
/.git/ | ||
|
||
# The directory Mix will write compiled artifacts to. | ||
/_build/ | ||
/.elixir_ls/ | ||
|
||
# If you run "mix test --cover", coverage assets end up here. | ||
/cover/ | ||
|
||
# The directory Mix downloads your dependencies sources to. | ||
/deps/ | ||
|
||
# Where third-party dependencies like ExDoc output generated docs. | ||
/doc/ | ||
|
||
# Ignore .fetch files in case you like to edit your project deps locally. | ||
/.fetch | ||
|
||
# If the VM crashes, it generates a dump, let's ignore it too. | ||
erl_crash.dump | ||
|
||
# Also ignore archive artifacts (built via "mix archive.build"). | ||
*.ez | ||
|
||
# Ignore package tarball (built via "mix hex.build"). | ||
electric-*.tar | ||
|
||
# Temporary files, for example, from tests. | ||
/tmp/ | ||
|
||
*offset_storage*.dat | ||
|
||
/integration_tests/ |
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 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 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,47 @@ | ||
defmodule Electric.Telemetry do | ||
use Supervisor | ||
alias 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}, | ||
{TelemetryMetricsPrometheus, [metrics: metrics()]} | ||
] | ||
|
||
Supervisor.init(children, strategy: :one_for_one) | ||
end | ||
|
||
defp metrics(), | ||
do: [ | ||
Metrics.counter("electric.postgres_tcp_server.connection.total"), | ||
Metrics.counter("electric.postgres_slot.replication.start"), | ||
Metrics.counter("electric.postgres_slot.replication.stop"), | ||
Metrics.sum("electric.postgres_slot.replication.sent_count"), | ||
Metrics.counter("electric.postgres_logical.received.total"), | ||
Metrics.counter("electric.vaxine_consumer.replication.saved"), | ||
Metrics.counter("electric.vaxine_consumer.replication.failed_to_write"), | ||
Metrics.counter("electric.satellite.connection.authorized_connection"), | ||
Metrics.counter("electric.satellite.connection.authorized_connection"), | ||
Metrics.counter("electric.satellite.replication.started"), | ||
Metrics.counter("electric.satellite.replication.stopped"), | ||
Metrics.last_value("vm.memory.total", unit: :byte), | ||
Metrics.last_value("vm.total_run_queue_lengths.total"), | ||
Metrics.last_value("vm.total_run_queue_lengths.cpu"), | ||
Metrics.last_value("vm.total_run_queue_lengths.io"), | ||
Metrics.last_value("vm.system_counts.process_count"), | ||
Metrics.last_value("vm.system_counts.atom_count"), | ||
Metrics.last_value("vm.system_counts.port_count") | ||
] | ||
|
||
defp periodic_measurements do | ||
[ | ||
# A module, function and arguments to be invoked periodically. | ||
# This function must call :telemetry.execute/3 and a metric must be added above. | ||
# {TestAuthAppWeb, :count_users, []} | ||
] | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
defmodule Electric.Telemetry.Metrics do | ||
def pg_producer_received(origin, type) when type in [:insert, :update, :delete] do | ||
:telemetry.execute([:electric, :postgres_logical, :received], %{total: 1}, %{ | ||
type: type, | ||
origin: origin | ||
}) | ||
end | ||
|
||
def pg_slot_replication_event(origin, data) when is_map(data) do | ||
:telemetry.execute([:electric, :postgres_slot, :replication], data, %{origin: origin}) | ||
end | ||
|
||
def vaxine_consumer_replication_event(origin, data) when is_map(data) do | ||
:telemetry.execute([:electric, :vaxine_consumer, :replication], data, %{origin: origin}) | ||
end | ||
|
||
def satellite_connection_event(data) when is_map(data) do | ||
:telemetry.execute([:electric, :satellite, :connection], data) | ||
end | ||
|
||
def satellite_replication_event(data) when is_map(data) do | ||
:telemetry.execute([:electric, :satellite, :replication], data) | ||
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