Etop (Etop v0.5.3)

A Top like implementation for Elixir Applications.

Usage

# Start with default options
ex> Etop.start()

# Temporarily pause/stop
ex> Etop.pause()

# Restart when paused
ex> Etop.start

# Start logging to an exs file
ex> Etop.start file: "/tmp/etop.exs"

# Load the current exs file
ex> data = Etop.load

# Start then change number of processes and interval between collecting results
ex> Etop.start
ex> Etop.set_opts nprocs: 15, interval: 15_000

# or
ex> Etop.start
ex> Etop.pause
ex> Etop.start nprocs: 15, interval: 15_000

# Stop Etop, killing its GenServer
ex> Etop.stop

Configuration

  • file - Save the output to a file.
  • format - the output file format. Values [:text, :exs]
  • interval (5000) - the time (ms) between each run
  • nprocs (10) - the number of processes to list
  • sort (reds_diff) - the field to sort the process list. Values [:memory, :msgq, :reds, :reds_diff, :status, :default]

Link to this section Summary

Functions

Add a new monitor to an Etop state map.

Returns a specification to start this module under a supervisor.

Restart Etop if its halted.

Callback implementation for GenServer.init/1.

Load the current exs log file.

Load the given .exs file.

Get the current monitors.

Pause a running Etop session.

Remove all monitors.

Enable or disable reporting.

Set Etop settings

Start Etop Reporting.

Get the status of the server

Stop Etop Reporting.

Link to this section Types

Specs

monitor() :: {monitor_type(), monitor_fields(), any(), monitor_callback()}
Link to this type

monitor_callback()

Specs

monitor_callback() :: (any(), any() -> none()) | {atom(), atom()}
Link to this type

monitor_fields()

Specs

monitor_fields() :: atom() | [atom()]
Link to this type

monitor_type()

Specs

monitor_type() :: :process | :summary

Specs

monitors() :: [monitor()]

Link to this section Functions

Link to this function

add_monitor(type, field, threshold, callback)

Specs

Add a new monitor.

Adds the given monitor to any existing monitors.

Examples

iex> Etop.start()
iex> callback = &{&1, &2}
iex> Etop.monitor(:summary, [:load, :sys], 10.0, callback)
iex> Etop.add_monitor(:process, :reductions, 1000, callback)
iex> Etop.monitors() ==
...> [
...>   {:process, :reductions, 1000, callback},
...>   {:summary, [:load, :sys], 10.0, callback}
...> ]
true
Link to this function

add_monitor(state, type, field, threshold, callback)

Specs

add_monitor(
  %{monitors: monitors()},
  monitor_type(),
  monitor_fields(),
  any(),
  monitor_callback()
) :: %{monitors: monitors()}

Add a new monitor to an Etop state map.

Link to this function

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

Link to this function

continue(opts \\ [])

Restart Etop if its halted.

Callback implementation for GenServer.init/1.

Load the current exs log file.

Load the given .exs file.

Link to this function

monitor(type, field, threshold, callback)

Specs

Set a monitor.

Replaces any existing monitors with the given monitor.

Examples

iex> Etop.start()
iex> callback = &{&1, &2}
iex> Etop.monitor(:summary, [:load, :sys], 10.0, callback)
iex> Etop.monitors() == [{:summary, [:load, :sys], 10.0, callback}]
true
Link to this function

monitor(state, type, field, threshold, callback)

Specs

monitor(
  %{monitors: monitors()},
  monitor_type(),
  monitor_fields(),
  any(),
  monitor_callback()
) :: %{monitors: monitors()}

Specs

monitors() :: [tuple()]

Get the current monitors.

Examples

iex> Etop.start()
iex> callback = &{&1, &2}
iex> Etop.monitor(:summary, [:load, :sys], 10.0, callback)
iex> Etop.monitors() == [{:summary, [:load, :sys], 10.0, callback}]
true

Pause a running Etop session.

Link to this function

remove_monitor(type, field, threshold)

Specs

remove_monitor(monitor_type(), monitor_fields(), any()) :: :ok | :not_found

Remove a monitor.

Examples

iex> Etop.start()
iex> Etop.monitor(:summary, [:load, :total], 10.0, &IO.inspect({&1, &2}))
iex> response = Etop.remove_monitor(:summary, [:load, :total], 10.0)
iex> {response, Etop.monitors()}
{:ok, []}
Link to this function

remove_monitors()

Remove all monitors.

Examples

iex> Etop.start()
iex> Etop.monitor(:summary, [:load, :total], 10.0, &IO.inspect({&1, &2}))
iex> Etop.remove_monitors()
iex> Etop.monitors()
[]
Link to this function

reporting(enable?)

Specs

reporting(boolean()) :: :ok | :already_reporting | :no_reporting

Enable or disable reporting.

Disabling reporting stops reporting printing or logging reports but keeps the Etop collecting data. This option can be used with a monitor to toggle logging when a threshold is reached.

Examples

iex> Etop.start()
iex> Etop.reporting(false)
:ok

iex> Etop.start()
iex> enable_callback = fn _, _ -> Etop.reporting(true) end
iex> disable_callback = fn _, value ->
...>   if value < 40.0, do: Etop.reporting(false)
...> end
iex> Etop.monitor(:summary, [:load, :total], 50.0, enable_callback)
iex> Etop.add_monitor(:summary, [:load, :total], 40.0, disable_callback)
:ok
Link to this function

sanitize_info_result(info)

Link to this function

sanitize_stats(state, stats)

Set Etop settings

Link to this function

start(opts \\ [])

Start Etop Reporting.

Link to this function

statistics(item)

Get the status of the server

Stop Etop Reporting.