Skip to content

Commit

Permalink
mnesia contrib
Browse files Browse the repository at this point in the history
  • Loading branch information
deadtrickster committed Oct 21, 2016
1 parent 89b3892 commit a0b6cf8
Show file tree
Hide file tree
Showing 13 changed files with 87 additions and 7 deletions.
1 change: 1 addition & 0 deletions lib/prometheus.ex
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ defmodule Prometheus do
require Prometheus.Buckets
use Prometheus.Metric
require Prometheus.Contrib.HTTP
require Prometheus.Contrib.Mnesia
end
end

Expand Down
35 changes: 35 additions & 0 deletions lib/prometheus/contrib/mnesia.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
defmodule Prometheus.Contrib.Mnesia do
@moduledoc """
Mnesia instrumentation helpers.
"""
use Prometheus.Erlang, :prometheus_mnesia

@doc """
Returns sum of all mnesia files for the given `table` in bytes.
Mnesia can create different files for each table:
- .DAT - DETS files
- .TMP - temp files
- .DMP - dumped ets tables
- .DCD - disc copies data
- .DCL - disc copies log
- .LOGTMP - disc copies log
More on Mnesia files can be found in
<a href="http://erlang.org/doc/apps/mnesia/Mnesia_chap7.html">
Mnesia System Information chapter
</a> of Mnesia User's Guide
"""
defmacro table_disk_size(dir \\ quote do :mnesia.system_info(:directory) end, table) do
Erlang.call([dir, table])
end

@doc """
Returns {pcount, ccount} tuple, where
pcount is a number of participant transactions and
ccount is a number of coordinator transactions.
Can return {:undefined, :undefined} occasionally.
"""
defmacro tm_info() do
Erlang.call()
end
end
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ defmodule PrometheusEx.Mixfile do
end

defp deps do
[{:prometheus, "~> 3.0"},
[{:prometheus, "~> 3.1"},
{:excoveralls, "~> 0.5.6", only: :test},
{:ex_doc, "~> 0.11", only: :dev},
{:earmark, ">= 0.0.0", only: :dev}]
Expand Down
12 changes: 6 additions & 6 deletions mix.lock
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
%{"certifi": {:hex, :certifi, "0.4.0", "a7966efb868b179023618d29a407548f70c52466bf1849b9e8ebd0e34b7ea11f", [:rebar3], []},
"earmark": {:hex, :earmark, "1.0.1", "2c2cd903bfdc3de3f189bd9a8d4569a075b88a8981ded9a0d95672f6e2b63141", [:mix], []},
"ex_doc": {:hex, :ex_doc, "0.13.1", "658dbfc8cc5b0fac192f0f3254efe66ee6294200804a291549e0aeb052053bba", [:mix], [{:earmark, "~> 1.0", [hex: :earmark, optional: false]}]},
"excoveralls": {:hex, :excoveralls, "0.5.6", "35a903f6f78619ee7f951448dddfbef094b3a0d8581657afaf66465bc930468e", [:mix], [{:exjsx, "~> 3.0", [hex: :exjsx, optional: false]}, {:hackney, ">= 0.12.0", [hex: :hackney, optional: false]}]},
"exjsx": {:hex, :exjsx, "3.2.0", "7136cc739ace295fc74c378f33699e5145bead4fdc1b4799822d0287489136fb", [:mix], [{:jsx, "~> 2.6.2", [hex: :jsx, optional: false]}]},
"earmark": {:hex, :earmark, "1.0.2", "a0b0904d74ecc14da8bd2e6e0248e1a409a2bc91aade75fcf428125603de3853", [:mix], []},
"ex_doc": {:hex, :ex_doc, "0.14.3", "e61cec6cf9731d7d23d254266ab06ac1decbb7651c3d1568402ec535d387b6f7", [:mix], [{:earmark, "~> 1.0", [hex: :earmark, optional: false]}]},
"excoveralls": {:hex, :excoveralls, "0.5.7", "5d26e4a7cdf08294217594a1b0643636accc2ad30e984d62f1d166f70629ff50", [:mix], [{:exjsx, "~> 3.0", [hex: :exjsx, optional: false]}, {:hackney, ">= 0.12.0", [hex: :hackney, optional: false]}]},
"exjsx": {:hex, :exjsx, "3.2.1", "1bc5bf1e4fd249104178f0885030bcd75a4526f4d2a1e976f4b428d347614f0f", [:mix], [{:jsx, "~> 2.8.0", [hex: :jsx, optional: false]}]},
"hackney": {:hex, :hackney, "1.6.1", "ddd22d42db2b50e6a155439c8811b8f6df61a4395de10509714ad2751c6da817", [:rebar3], [{:certifi, "0.4.0", [hex: :certifi, optional: false]}, {:idna, "1.2.0", [hex: :idna, optional: false]}, {:metrics, "1.0.1", [hex: :metrics, optional: false]}, {:mimerl, "1.0.2", [hex: :mimerl, optional: false]}, {:ssl_verify_fun, "1.1.0", [hex: :ssl_verify_fun, optional: false]}]},
"idna": {:hex, :idna, "1.2.0", "ac62ee99da068f43c50dc69acf700e03a62a348360126260e87f2b54eced86b2", [:rebar3], []},
"jsx": {:hex, :jsx, "2.6.2", "213721e058da0587a4bce3cc8a00ff6684ced229c8f9223245c6ff2c88fbaa5a", [:mix, :rebar], []},
"jsx": {:hex, :jsx, "2.8.0", "749bec6d205c694ae1786d62cea6cc45a390437e24835fd16d12d74f07097727", [:mix, :rebar], []},
"metrics": {:hex, :metrics, "1.0.1", "25f094dea2cda98213cecc3aeff09e940299d950904393b2a29d191c346a8486", [:rebar3], []},
"mimerl": {:hex, :mimerl, "1.0.2", "993f9b0e084083405ed8252b99460c4f0563e41729ab42d9074fd5e52439be88", [:rebar3], []},
"prometheus": {:hex, :prometheus, "3.0.0", "f868b68e9532e4bed456216e06b6c0f8527dfeca103544e7faabd33282b040ea", [:rebar3], []},
"prometheus": {:hex, :prometheus, "3.1.0", "32a148a6c906d8d31113cad5cb07d4b61dec3f77c6f6fe2ce837d1ff62e9a049", [:rebar3], []},
"ssl_verify_fun": {:hex, :ssl_verify_fun, "1.1.0", "edee20847c42e379bf91261db474ffbe373f8acb56e9079acb6038d4e0bf414f", [:rebar, :make], []}}
36 changes: 36 additions & 0 deletions test/contrib/mnesia_test.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
defmodule Prometheus.Contrib.MnesiaTest do
use ExUnit.Case

use Prometheus

test "table disk size" do
{:ok, root} = :file.get_cwd()
mnesia_dir = root ++ '/test/mnesia'
set_custom_mnesia_dir(mnesia_dir)

assert mnesia_dir == :mnesia.system_info(:directory)

assert 3 = Prometheus.Contrib.Mnesia.table_disk_size(mnesia_dir, :table)
assert 21 = Prometheus.Contrib.Mnesia.table_disk_size(:my_table)
end

test "tm info test" do
try do
:mnesia.start()
assert {_, _} = Prometheus.Contrib.Mnesia.tm_info()
after
:mnesia.stop()
end
end

defp set_custom_mnesia_dir(dir) do
try do
:ets.lookup_element(:mnesia_gvar, :dir, 2)
:ets.update_element(:mnesia_gvar, :dir, dir)
rescue
ArgumentError ->
:application.set_env(:mnesia, :dir, dir)
end
end

end
1 change: 1 addition & 0 deletions test/mnesia/my_table.DAT
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
111111
1 change: 1 addition & 0 deletions test/mnesia/my_table.DCD
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
11111
1 change: 1 addition & 0 deletions test/mnesia/my_table.DCL
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1111
1 change: 1 addition & 0 deletions test/mnesia/my_table.DMP
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
111
1 change: 1 addition & 0 deletions test/mnesia/my_table.LOGTMP
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
11
1 change: 1 addition & 0 deletions test/mnesia/my_table.TMP
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1
1 change: 1 addition & 0 deletions test/mnesia/table.DCD
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
11
1 change: 1 addition & 0 deletions test/mnesia/table.DCL
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1

0 comments on commit a0b6cf8

Please sign in to comment.