[#59] improving documentation

This commit is contained in:
Felipe Ripoll 2018-08-29 08:05:59 -06:00
parent c5525e853d
commit 2bede602c2
32 changed files with 2733 additions and 50 deletions

View File

@ -19,23 +19,56 @@ mix docs
That command will create a `doc/` folder with the actual Documentation.
## Run Tests
## Configuring Databases for first time
`POABackend` uses [Mnesia](http://erlang.org/doc/man/mnesia.html) as a local database with [Ecto](https://hexdocs.pm/ecto/Ecto.html). In order to have this running we have to create a folder where `Mnesia` will store our data. In order to do that we have to define it in the `config/test.exs` file like this:
`POABackend` uses many Databases. For Authentication we use [Mnesia](http://erlang.org/doc/man/mnesia.html) as a local database and for some receivers which require storage we use Postgres. All databases are managed on top of [Ecto](https://hexdocs.pm/ecto/Ecto.html) a widly used database wrapper for Elixir projects.
For this reason we have to set the databases before running the `POABackend` for the first time.
- Auth Database (Mnesia): Setting up Mnesia is easy since it is working localy and is built in the Erlang Virtual Machine. We only have to say "where" we are going to store the database's files. In order to do that we have to add the configuration to the config file (`prod.exs` or `test.exs` depending if you want to run tests or production)
```
config :mnesia,
dir: 'your/local/path' # make sure this directory exists!
```
once we have the path defined we have to create the database (those commands must be run only once if you are going to use always this same path for testing). In your root folder run:
- Receivers Database (Postgres): This is a little more complex than Mnesia. We need a Postgres instance running somewhere and we have to add the config to the config files
```
config :poa_backend, POABackend.Receivers.Repo,
priv: "priv/receivers", # this value is not changed
adapter: Ecto.Adapters.Postgres,
database: "poabackend_stats",
username: "postgres",
password: "postgres",
hostname: "localhost"
```
The important fields here are `database`, `username`, `password` and `hostname`. The rest of values must remain exactly as the example.
Once we have set the database configuration we have to create and migrate the databases, in order to do that we should be in the root of the project and run:
- for production
```
MIX_ENV=prod mix ecto.create
MIX_ENV=prod mix ecto.migrate
```
- for test
```
MIX_ENV=test mix ecto.create
MIX_ENV=test mix ecto.migrate
```
Now the environment is set. We can run the tests with:
Now the environment is ready for running `POABackend`
## Run Tests
The first time you run the tests you will need having the Database's environment set up. Check the previous section and set the configuration in the `config/test.exs` file.
Once the environment is set. We can run the tests with:
```
mix test

View File

@ -23,4 +23,12 @@ config :poa_backend, POABackend.Auth.Repo,
config :mnesia,
dir: 'priv/data/mnesia' # make sure this directory exists!
config :poa_backend, POABackend.Receivers.Repo,
priv: "priv/receivers", # this value is not changed
adapter: Ecto.Adapters.Postgres,
database: "poabackend_stats",
username: "postgres",
password: "postgres",
hostname: "localhost"
import_config "#{Mix.env}.exs"

View File

@ -85,7 +85,7 @@ config :mnesia,
dir: 'priv/data/mnesia' # make sure this directory exists!
config :poa_backend, POABackend.Receivers.Repo,
priv: "priv/receivers",
priv: "priv/receivers", # this value is not changed
adapter: Ecto.Adapters.Postgres,
database: "poabackend_stats",
username: "postgres",

View File

@ -4,12 +4,13 @@ fonts/icomoon.eot
fonts/icomoon.svg
fonts/icomoon.ttf
fonts/icomoon.woff
dist/sidebar_items-3739fd4c82.js
dist/sidebar_items-3d14d8fe9b.js
api-reference.html
initial_architecture.html
search.html
404.html
POABackend.html
POABackend.Receivers.Repo.html
POABackend.Auth.html
POABackend.Auth.Guardian.Plug.html
POABackend.Auth.Models.Token.html
@ -24,4 +25,6 @@ POABackend.CustomHandler.REST.html
POABackend.Receiver.html
POABackend.Receivers.Dashboard.html
POABackend.Receivers.DynamoDB.html
POABackend.Receivers.Eth.Stats.html
POABackend.Receivers.System.Stats.html
index.html

View File

@ -8,7 +8,7 @@
<title>404 poa_backend v0.1.0</title>
<link rel="stylesheet" href="dist/app-480ffdc169.css" />
<script src="dist/sidebar_items-3739fd4c82.js"></script>
<script src="dist/sidebar_items-3d14d8fe9b.js"></script>

View File

@ -8,7 +8,7 @@
<title>POABackend.Auth.Guardian.Plug poa_backend v0.1.0</title>
<link rel="stylesheet" href="dist/app-480ffdc169.css" />
<script src="dist/sidebar_items-3739fd4c82.js"></script>
<script src="dist/sidebar_items-3d14d8fe9b.js"></script>

View File

@ -8,7 +8,7 @@
<title>POABackend.Auth.Models.Token poa_backend v0.1.0</title>
<link rel="stylesheet" href="dist/app-480ffdc169.css" />
<script src="dist/sidebar_items-3739fd4c82.js"></script>
<script src="dist/sidebar_items-3d14d8fe9b.js"></script>

View File

@ -8,7 +8,7 @@
<title>POABackend.Auth.Models.User poa_backend v0.1.0</title>
<link rel="stylesheet" href="dist/app-480ffdc169.css" />
<script src="dist/sidebar_items-3739fd4c82.js"></script>
<script src="dist/sidebar_items-3d14d8fe9b.js"></script>

View File

@ -8,7 +8,7 @@
<title>POABackend.Auth.REST poa_backend v0.1.0</title>
<link rel="stylesheet" href="dist/app-480ffdc169.css" />
<script src="dist/sidebar_items-3739fd4c82.js"></script>
<script src="dist/sidebar_items-3d14d8fe9b.js"></script>

View File

@ -8,7 +8,7 @@
<title>POABackend.Auth poa_backend v0.1.0</title>
<link rel="stylesheet" href="dist/app-480ffdc169.css" />
<script src="dist/sidebar_items-3739fd4c82.js"></script>
<script src="dist/sidebar_items-3d14d8fe9b.js"></script>
@ -318,7 +318,7 @@ with that name in the database already</p>
</a>
<span class="signature">authenticate_admin(admin_name, password)</span>
<a href="https://github.com/poanetwork/poa-netstats-wharehouse/blob/v0.1.0/lib/poa_backend/auth.ex#L97" class="view-source" rel="help" title="View Source">
<a href="https://github.com/poanetwork/poa-netstats-wharehouse/blob/v0.1.0/lib/poa_backend/auth.ex#L98" class="view-source" rel="help" title="View Source">
<span class="icon-code" aria-hidden="true"></span>
<span class="sr-only">View Source</span>
</a>
@ -378,7 +378,7 @@ with that name in the database already</p>
</a>
<span class="signature">create_banned_token(jwt_token)</span>
<a href="https://github.com/poanetwork/poa-netstats-wharehouse/blob/v0.1.0/lib/poa_backend/auth.ex#L157" class="view-source" rel="help" title="View Source">
<a href="https://github.com/poanetwork/poa-netstats-wharehouse/blob/v0.1.0/lib/poa_backend/auth.ex#L158" class="view-source" rel="help" title="View Source">
<span class="icon-code" aria-hidden="true"></span>
<span class="sr-only">View Source</span>
</a>
@ -409,7 +409,7 @@ This function will extract the expiration time from the claims and store them in
</a>
<span class="signature">create_banned_token(token, expires)</span>
<a href="https://github.com/poanetwork/poa-netstats-wharehouse/blob/v0.1.0/lib/poa_backend/auth.ex#L171" class="view-source" rel="help" title="View Source">
<a href="https://github.com/poanetwork/poa-netstats-wharehouse/blob/v0.1.0/lib/poa_backend/auth.ex#L172" class="view-source" rel="help" title="View Source">
<span class="icon-code" aria-hidden="true"></span>
<span class="sr-only">View Source</span>
</a>
@ -504,7 +504,7 @@ expiration time as Integer.</p>
</a>
<span class="signature">generate_password()</span>
<a href="https://github.com/poanetwork/poa-netstats-wharehouse/blob/v0.1.0/lib/poa_backend/auth.ex#L132" class="view-source" rel="help" title="View Source">
<a href="https://github.com/poanetwork/poa-netstats-wharehouse/blob/v0.1.0/lib/poa_backend/auth.ex#L133" class="view-source" rel="help" title="View Source">
<span class="icon-code" aria-hidden="true"></span>
<span class="sr-only">View Source</span>
</a>
@ -533,7 +533,7 @@ expiration time as Integer.</p>
</a>
<span class="signature">generate_user_name()</span>
<a href="https://github.com/poanetwork/poa-netstats-wharehouse/blob/v0.1.0/lib/poa_backend/auth.ex#L111" class="view-source" rel="help" title="View Source">
<a href="https://github.com/poanetwork/poa-netstats-wharehouse/blob/v0.1.0/lib/poa_backend/auth.ex#L112" class="view-source" rel="help" title="View Source">
<span class="icon-code" aria-hidden="true"></span>
<span class="sr-only">View Source</span>
</a>
@ -562,7 +562,7 @@ expiration time as Integer.</p>
</a>
<span class="signature">generate_user_name(user_name)</span>
<a href="https://github.com/poanetwork/poa-netstats-wharehouse/blob/v0.1.0/lib/poa_backend/auth.ex#L121" class="view-source" rel="help" title="View Source">
<a href="https://github.com/poanetwork/poa-netstats-wharehouse/blob/v0.1.0/lib/poa_backend/auth.ex#L122" class="view-source" rel="help" title="View Source">
<span class="icon-code" aria-hidden="true"></span>
<span class="sr-only">View Source</span>
</a>
@ -620,7 +620,7 @@ expiration time as Integer.</p>
</a>
<span class="signature">purge_banned_tokens()</span>
<a href="https://github.com/poanetwork/poa-netstats-wharehouse/blob/v0.1.0/lib/poa_backend/auth.ex#L203" class="view-source" rel="help" title="View Source">
<a href="https://github.com/poanetwork/poa-netstats-wharehouse/blob/v0.1.0/lib/poa_backend/auth.ex#L204" class="view-source" rel="help" title="View Source">
<span class="icon-code" aria-hidden="true"></span>
<span class="sr-only">View Source</span>
</a>
@ -678,7 +678,7 @@ expiration time as Integer.</p>
</a>
<span class="signature">token_banned?(token)</span>
<a href="https://github.com/poanetwork/poa-netstats-wharehouse/blob/v0.1.0/lib/poa_backend/auth.ex#L220" class="view-source" rel="help" title="View Source">
<a href="https://github.com/poanetwork/poa-netstats-wharehouse/blob/v0.1.0/lib/poa_backend/auth.ex#L221" class="view-source" rel="help" title="View Source">
<span class="icon-code" aria-hidden="true"></span>
<span class="sr-only">View Source</span>
</a>
@ -736,7 +736,7 @@ expiration time as Integer.</p>
</a>
<span class="signature">valid_token?(jwt_token)</span>
<a href="https://github.com/poanetwork/poa-netstats-wharehouse/blob/v0.1.0/lib/poa_backend/auth.ex#L185" class="view-source" rel="help" title="View Source">
<a href="https://github.com/poanetwork/poa-netstats-wharehouse/blob/v0.1.0/lib/poa_backend/auth.ex#L186" class="view-source" rel="help" title="View Source">
<span class="icon-code" aria-hidden="true"></span>
<span class="sr-only">View Source</span>
</a>
@ -765,7 +765,7 @@ expiration time as Integer.</p>
</a>
<span class="signature">valid_user_name?(user_name)</span>
<a href="https://github.com/poanetwork/poa-netstats-wharehouse/blob/v0.1.0/lib/poa_backend/auth.ex#L141" class="view-source" rel="help" title="View Source">
<a href="https://github.com/poanetwork/poa-netstats-wharehouse/blob/v0.1.0/lib/poa_backend/auth.ex#L142" class="view-source" rel="help" title="View Source">
<span class="icon-code" aria-hidden="true"></span>
<span class="sr-only">View Source</span>
</a>

View File

@ -8,7 +8,7 @@
<title>POABackend.CustomHandler.REST poa_backend v0.1.0</title>
<link rel="stylesheet" href="dist/app-480ffdc169.css" />
<script src="dist/sidebar_items-3739fd4c82.js"></script>
<script src="dist/sidebar_items-3d14d8fe9b.js"></script>

View File

@ -8,7 +8,7 @@
<title>POABackend.CustomHandler poa_backend v0.1.0</title>
<link rel="stylesheet" href="dist/app-480ffdc169.css" />
<script src="dist/sidebar_items-3739fd4c82.js"></script>
<script src="dist/sidebar_items-3d14d8fe9b.js"></script>

View File

@ -8,7 +8,7 @@
<title>POABackend.Protocol.DataType poa_backend v0.1.0</title>
<link rel="stylesheet" href="dist/app-480ffdc169.css" />
<script src="dist/sidebar_items-3739fd4c82.js"></script>
<script src="dist/sidebar_items-3d14d8fe9b.js"></script>

View File

@ -8,7 +8,7 @@
<title>POABackend.Protocol.Message poa_backend v0.1.0</title>
<link rel="stylesheet" href="dist/app-480ffdc169.css" />
<script src="dist/sidebar_items-3739fd4c82.js"></script>
<script src="dist/sidebar_items-3d14d8fe9b.js"></script>

View File

@ -8,7 +8,7 @@
<title>POABackend.Protocol.MessageType poa_backend v0.1.0</title>
<link rel="stylesheet" href="dist/app-480ffdc169.css" />
<script src="dist/sidebar_items-3739fd4c82.js"></script>
<script src="dist/sidebar_items-3d14d8fe9b.js"></script>

View File

@ -8,7 +8,7 @@
<title>POABackend.Protocol poa_backend v0.1.0</title>
<link rel="stylesheet" href="dist/app-480ffdc169.css" />
<script src="dist/sidebar_items-3739fd4c82.js"></script>
<script src="dist/sidebar_items-3d14d8fe9b.js"></script>

View File

@ -8,7 +8,7 @@
<title>POABackend.Receiver poa_backend v0.1.0</title>
<link rel="stylesheet" href="dist/app-480ffdc169.css" />
<script src="dist/sidebar_items-3739fd4c82.js"></script>
<script src="dist/sidebar_items-3d14d8fe9b.js"></script>

View File

@ -8,7 +8,7 @@
<title>POABackend.Receivers.Dashboard poa_backend v0.1.0</title>
<link rel="stylesheet" href="dist/app-480ffdc169.css" />
<script src="dist/sidebar_items-3739fd4c82.js"></script>
<script src="dist/sidebar_items-3d14d8fe9b.js"></script>

View File

@ -8,7 +8,7 @@
<title>POABackend.Receivers.DynamoDB poa_backend v0.1.0</title>
<link rel="stylesheet" href="dist/app-480ffdc169.css" />
<script src="dist/sidebar_items-3739fd4c82.js"></script>
<script src="dist/sidebar_items-3d14d8fe9b.js"></script>

View File

@ -0,0 +1,336 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="generator" content="ExDoc v0.18.4">
<title>POABackend.Receivers.Eth.Stats poa_backend v0.1.0</title>
<link rel="stylesheet" href="dist/app-480ffdc169.css" />
<script src="dist/sidebar_items-3d14d8fe9b.js"></script>
</head>
<body data-type="modules">
<script>try { if(localStorage.getItem('night-mode')) document.body.className += ' night-mode'; } catch (e) { }</script>
<div class="main">
<button class="sidebar-button sidebar-toggle">
<span class="icon-menu" aria-hidden="true"></span>
<span class="sr-only">Toggle Sidebar</span>
</button>
<button class="sidebar-button night-mode-toggle">
<span class="icon-theme" aria-hidden="true"></span>
<span class="sr-only">Toggle Theme</span>
</button>
<section class="sidebar">
<a href="POABackend.html" class="sidebar-projectLink">
<div class="sidebar-projectDetails">
<h1 class="sidebar-projectName">
poa_backend
</h1>
<h2 class="sidebar-projectVersion">
v0.1.0
</h2>
</div>
</a>
<form class="sidebar-search" action="search.html">
<button type="submit" class="search-button">
<span class="icon-search" aria-hidden="true"></span>
</button>
<input name="q" type="text" id="search-list" class="search-input" placeholder="Search" aria-label="Search" autocomplete="off" />
</form>
<ul class="sidebar-listNav">
<li><a id="extras-list" href="#full-list">Pages</a></li>
<li><a id="modules-list" href="#full-list">Modules</a></li>
</ul>
<div class="gradient"></div>
<ul id="full-list" class="sidebar-fullList"></ul>
</section>
<section class="content">
<div class="content-outer">
<div id="content" class="content-inner">
<h1>
<small class="visible-xs">poa_backend v0.1.0</small>
POABackend.Receivers.Eth.Stats
<a href="https://github.com/poanetwork/poa-netstats-wharehouse/blob/v0.1.0/lib/poa_backend/receivers/eth/stats.ex#L1" title="View Source" class="view-source" rel="help">
<span class="icon-code" aria-hidden="true"></span>
<span class="sr-only">View Source</span>
</a>
</h1>
<section id="moduledoc">
<p>This is a Receiver Plugin which is in charge of storing the Ethereum Statistics received from the Agents in a Postgres
database. If we want to use it we have to declare it in the Config file, inside the <code class="inline">:receivers</code> section, ie:</p>
<pre><code class="elixir">{:store_eth_stats, POABackend.Receivers.Eth.Stats, []}</code></pre>
<p>This Plugin uses Postgres as a backend, specifically the <code class="inline">eth_stats</code> table. Make sure that table exists before using
this Plugin.</p>
<p>We also need to subscribe this plugin to <code class="inline">:ethereum_metrics</code> metrics in the config file. For that we have to add this line
to the list in the <code class="inline">:subscriptions</code> section:</p>
<pre><code class="elixir">{:store_eth_stats, [:ethereum_metrics]}</code></pre>
</section>
<section id="summary" class="details-list">
<h1 class="section-heading">
<a class="hover-link" href="#summary">
<span class="icon-link" aria-hidden="true"></span>
<span class="sr-only">Link to this section</span>
</a>
Summary
</h1>
<div class="summary-functions summary">
<h2>
<a href="#functions">Functions</a>
</h2>
<div class="summary-row">
<div class="summary-signature">
<a href="#handle_inactive/2">handle_inactive(agent_id, state)</a>
</div>
<div class="summary-synopsis"><p>This function is called when a Custom Handler detects a client is inactive</p>
</div>
</div>
<div class="summary-row">
<div class="summary-signature">
<a href="#handle_message/2">handle_message(message, state)</a>
</div>
<div class="summary-synopsis"><p>In this callback is called when the Receiver process receives an erlang message</p>
</div>
</div>
<div class="summary-row">
<div class="summary-signature">
<a href="#init_receiver/1">init_receiver(args)</a>
</div>
<div class="summary-synopsis"><p>A callback executed when the Receiver Plugin starts.
The argument is retrieved from the configuration file when the Receiver is defined
It must return <code class="inline">{:ok, state}</code>, that <code class="inline">state</code> will be keept as in <a href="https://hexdocs.pm/elixir/GenServer.html"><code class="inline">GenServer</code></a> and can be
retrieved in the <a href="#metrics_received/3"><code class="inline">metrics_received/3</code></a> function</p>
</div>
</div>
<div class="summary-row">
<div class="summary-signature">
<a href="#metrics_received/3">metrics_received(arg1, from, state)</a>
</div>
<div class="summary-synopsis"><p>This callback will be called every time a message to the subscribed metric type arrives. It must
return the tuple <code class="inline">{:ok, state}</code></p>
</div>
</div>
<div class="summary-row">
<div class="summary-signature">
<a href="#terminate/1">terminate(state)</a>
</div>
<div class="summary-synopsis"><p>This callback is called just before the Process goes down. This is a good place for closing connections</p>
</div>
</div>
</div>
</section>
<section id="functions" class="details-list">
<h1 class="section-heading">
<a class="hover-link" href="#functions">
<span class="icon-link" aria-hidden="true"></span>
<span class="sr-only">Link to this section</span>
</a>
Functions
</h1>
<div class="detail" id="handle_inactive/2">
<div class="detail-header">
<a href="#handle_inactive/2" class="detail-link" title="Link to this function">
<span class="icon-link" aria-hidden="true"></span>
<span class="sr-only">Link to this function</span>
</a>
<span class="signature">handle_inactive(agent_id, state)</span>
<a href="https://github.com/poanetwork/poa-netstats-wharehouse/blob/v0.1.0/lib/poa_backend/receivers/eth/stats.ex#L39" class="view-source" rel="help" title="View Source">
<span class="icon-code" aria-hidden="true"></span>
<span class="sr-only">View Source</span>
</a>
</div>
<section class="docstring">
<p> This function is called when a Custom Handler detects a client is inactive.</p>
<p> The Custom Handler must to call explicity to <a href="POABackend.CustomHandler.html#publish_inactive/1"><code class="inline">POABackend.CustomHandler.publish_inactive/1</code></a> and it will publish the
<code class="inline">inactive</code> message to all the metrics in the system (defined in the config file).</p>
<p>Callback implementation for <a href="POABackend.Receiver.html#c:handle_inactive/2"><code class="inline">POABackend.Receiver.handle_inactive/2</code></a>.</p>
</section>
</div>
<div class="detail" id="handle_message/2">
<div class="detail-header">
<a href="#handle_message/2" class="detail-link" title="Link to this function">
<span class="icon-link" aria-hidden="true"></span>
<span class="sr-only">Link to this function</span>
</a>
<span class="signature">handle_message(message, state)</span>
<a href="https://github.com/poanetwork/poa-netstats-wharehouse/blob/v0.1.0/lib/poa_backend/receivers/eth/stats.ex#L35" class="view-source" rel="help" title="View Source">
<span class="icon-code" aria-hidden="true"></span>
<span class="sr-only">View Source</span>
</a>
</div>
<section class="docstring">
<p> In this callback is called when the Receiver process receives an erlang message.</p>
<p> It must return <code class="inline">{:ok, state}</code>.</p>
<p>Callback implementation for <a href="POABackend.Receiver.html#c:handle_message/2"><code class="inline">POABackend.Receiver.handle_message/2</code></a>.</p>
</section>
</div>
<div class="detail" id="init_receiver/1">
<div class="detail-header">
<a href="#init_receiver/1" class="detail-link" title="Link to this function">
<span class="icon-link" aria-hidden="true"></span>
<span class="sr-only">Link to this function</span>
</a>
<span class="signature">init_receiver(args)</span>
<a href="https://github.com/poanetwork/poa-netstats-wharehouse/blob/v0.1.0/lib/poa_backend/receivers/eth/stats.ex#L23" class="view-source" rel="help" title="View Source">
<span class="icon-code" aria-hidden="true"></span>
<span class="sr-only">View Source</span>
</a>
</div>
<section class="docstring">
<p> A callback executed when the Receiver Plugin starts.
The argument is retrieved from the configuration file when the Receiver is defined
It must return <code class="inline">{:ok, state}</code>, that <code class="inline">state</code> will be keept as in <a href="https://hexdocs.pm/elixir/GenServer.html"><code class="inline">GenServer</code></a> and can be
retrieved in the <a href="#metrics_received/3"><code class="inline">metrics_received/3</code></a> function.</p>
<p>Callback implementation for <a href="POABackend.Receiver.html#c:init_receiver/1"><code class="inline">POABackend.Receiver.init_receiver/1</code></a>.</p>
</section>
</div>
<div class="detail" id="metrics_received/3">
<div class="detail-header">
<a href="#metrics_received/3" class="detail-link" title="Link to this function">
<span class="icon-link" aria-hidden="true"></span>
<span class="sr-only">Link to this function</span>
</a>
<span class="signature">metrics_received(arg1, from, state)</span>
<a href="https://github.com/poanetwork/poa-netstats-wharehouse/blob/v0.1.0/lib/poa_backend/receivers/eth/stats.ex#L31" class="view-source" rel="help" title="View Source">
<span class="icon-code" aria-hidden="true"></span>
<span class="sr-only">View Source</span>
</a>
</div>
<section class="docstring">
<p> This callback will be called every time a message to the subscribed metric type arrives. It must
return the tuple <code class="inline">{:ok, state}</code></p>
<p>Callback implementation for <a href="POABackend.Receiver.html#c:metrics_received/3"><code class="inline">POABackend.Receiver.metrics_received/3</code></a>.</p>
</section>
</div>
<div class="detail" id="terminate/1">
<div class="detail-header">
<a href="#terminate/1" class="detail-link" title="Link to this function">
<span class="icon-link" aria-hidden="true"></span>
<span class="sr-only">Link to this function</span>
</a>
<span class="signature">terminate(state)</span>
<a href="https://github.com/poanetwork/poa-netstats-wharehouse/blob/v0.1.0/lib/poa_backend/receivers/eth/stats.ex#L43" class="view-source" rel="help" title="View Source">
<span class="icon-code" aria-hidden="true"></span>
<span class="sr-only">View Source</span>
</a>
</div>
<section class="docstring">
<p> This callback is called just before the Process goes down. This is a good place for closing connections.</p>
<p>Callback implementation for <a href="POABackend.Receiver.html#c:terminate/1"><code class="inline">POABackend.Receiver.terminate/1</code></a>.</p>
</section>
</div>
</section>
<footer class="footer">
<p>
<span class="line">
Built using
<a href="https://github.com/elixir-lang/ex_doc" title="ExDoc" rel="help" target="_blank">ExDoc</a> (v0.18.4),
</span>
<span class="line">
designed by
<a href="https://twitter.com/dignifiedquire" target="_blank" title="@dignifiedquire">Friedel Ziegelmayer</a>.
</span>
</p>
</footer>
</div>
</div>
</section>
</div>
<script src="dist/app-9bd040e5e5.js"></script>
</body>
</html>

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,336 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="generator" content="ExDoc v0.18.4">
<title>POABackend.Receivers.System.Stats poa_backend v0.1.0</title>
<link rel="stylesheet" href="dist/app-480ffdc169.css" />
<script src="dist/sidebar_items-3d14d8fe9b.js"></script>
</head>
<body data-type="modules">
<script>try { if(localStorage.getItem('night-mode')) document.body.className += ' night-mode'; } catch (e) { }</script>
<div class="main">
<button class="sidebar-button sidebar-toggle">
<span class="icon-menu" aria-hidden="true"></span>
<span class="sr-only">Toggle Sidebar</span>
</button>
<button class="sidebar-button night-mode-toggle">
<span class="icon-theme" aria-hidden="true"></span>
<span class="sr-only">Toggle Theme</span>
</button>
<section class="sidebar">
<a href="POABackend.html" class="sidebar-projectLink">
<div class="sidebar-projectDetails">
<h1 class="sidebar-projectName">
poa_backend
</h1>
<h2 class="sidebar-projectVersion">
v0.1.0
</h2>
</div>
</a>
<form class="sidebar-search" action="search.html">
<button type="submit" class="search-button">
<span class="icon-search" aria-hidden="true"></span>
</button>
<input name="q" type="text" id="search-list" class="search-input" placeholder="Search" aria-label="Search" autocomplete="off" />
</form>
<ul class="sidebar-listNav">
<li><a id="extras-list" href="#full-list">Pages</a></li>
<li><a id="modules-list" href="#full-list">Modules</a></li>
</ul>
<div class="gradient"></div>
<ul id="full-list" class="sidebar-fullList"></ul>
</section>
<section class="content">
<div class="content-outer">
<div id="content" class="content-inner">
<h1>
<small class="visible-xs">poa_backend v0.1.0</small>
POABackend.Receivers.System.Stats
<a href="https://github.com/poanetwork/poa-netstats-wharehouse/blob/v0.1.0/lib/poa_backend/receivers/system/stats.ex#L1" title="View Source" class="view-source" rel="help">
<span class="icon-code" aria-hidden="true"></span>
<span class="sr-only">View Source</span>
</a>
</h1>
<section id="moduledoc">
<p>This is a Receiver Plugin which is in charge of storing the System Metrics received from the Agents in a Postgres
database. If we want to use it we have to declare it in the Config file, inside the <code class="inline">:receivers</code> section, ie:</p>
<pre><code class="elixir">{:store_system_stats, POABackend.Receivers.System.Stats, []}</code></pre>
<p>This Plugin uses Postgres as a backend, specifically the <code class="inline">system_stats</code> table. Make sure that table exists before using
this Plugin.</p>
<p>We also need to subscribe this plugin to <code class="inline">:system_metrics</code> metrics in the config file. For that we have to add this line
to the list in the <code class="inline">:subscriptions</code> section:</p>
<pre><code class="elixir">{:store_system_stats, [:system_metrics]}</code></pre>
</section>
<section id="summary" class="details-list">
<h1 class="section-heading">
<a class="hover-link" href="#summary">
<span class="icon-link" aria-hidden="true"></span>
<span class="sr-only">Link to this section</span>
</a>
Summary
</h1>
<div class="summary-functions summary">
<h2>
<a href="#functions">Functions</a>
</h2>
<div class="summary-row">
<div class="summary-signature">
<a href="#handle_inactive/2">handle_inactive(agent_id, state)</a>
</div>
<div class="summary-synopsis"><p>This function is called when a Custom Handler detects a client is inactive</p>
</div>
</div>
<div class="summary-row">
<div class="summary-signature">
<a href="#handle_message/2">handle_message(message, state)</a>
</div>
<div class="summary-synopsis"><p>In this callback is called when the Receiver process receives an erlang message</p>
</div>
</div>
<div class="summary-row">
<div class="summary-signature">
<a href="#init_receiver/1">init_receiver(args)</a>
</div>
<div class="summary-synopsis"><p>A callback executed when the Receiver Plugin starts.
The argument is retrieved from the configuration file when the Receiver is defined
It must return <code class="inline">{:ok, state}</code>, that <code class="inline">state</code> will be keept as in <a href="https://hexdocs.pm/elixir/GenServer.html"><code class="inline">GenServer</code></a> and can be
retrieved in the <a href="#metrics_received/3"><code class="inline">metrics_received/3</code></a> function</p>
</div>
</div>
<div class="summary-row">
<div class="summary-signature">
<a href="#metrics_received/3">metrics_received(arg1, from, state)</a>
</div>
<div class="summary-synopsis"><p>This callback will be called every time a message to the subscribed metric type arrives. It must
return the tuple <code class="inline">{:ok, state}</code></p>
</div>
</div>
<div class="summary-row">
<div class="summary-signature">
<a href="#terminate/1">terminate(state)</a>
</div>
<div class="summary-synopsis"><p>This callback is called just before the Process goes down. This is a good place for closing connections</p>
</div>
</div>
</div>
</section>
<section id="functions" class="details-list">
<h1 class="section-heading">
<a class="hover-link" href="#functions">
<span class="icon-link" aria-hidden="true"></span>
<span class="sr-only">Link to this section</span>
</a>
Functions
</h1>
<div class="detail" id="handle_inactive/2">
<div class="detail-header">
<a href="#handle_inactive/2" class="detail-link" title="Link to this function">
<span class="icon-link" aria-hidden="true"></span>
<span class="sr-only">Link to this function</span>
</a>
<span class="signature">handle_inactive(agent_id, state)</span>
<a href="https://github.com/poanetwork/poa-netstats-wharehouse/blob/v0.1.0/lib/poa_backend/receivers/system/stats.ex#L39" class="view-source" rel="help" title="View Source">
<span class="icon-code" aria-hidden="true"></span>
<span class="sr-only">View Source</span>
</a>
</div>
<section class="docstring">
<p> This function is called when a Custom Handler detects a client is inactive.</p>
<p> The Custom Handler must to call explicity to <a href="POABackend.CustomHandler.html#publish_inactive/1"><code class="inline">POABackend.CustomHandler.publish_inactive/1</code></a> and it will publish the
<code class="inline">inactive</code> message to all the metrics in the system (defined in the config file).</p>
<p>Callback implementation for <a href="POABackend.Receiver.html#c:handle_inactive/2"><code class="inline">POABackend.Receiver.handle_inactive/2</code></a>.</p>
</section>
</div>
<div class="detail" id="handle_message/2">
<div class="detail-header">
<a href="#handle_message/2" class="detail-link" title="Link to this function">
<span class="icon-link" aria-hidden="true"></span>
<span class="sr-only">Link to this function</span>
</a>
<span class="signature">handle_message(message, state)</span>
<a href="https://github.com/poanetwork/poa-netstats-wharehouse/blob/v0.1.0/lib/poa_backend/receivers/system/stats.ex#L35" class="view-source" rel="help" title="View Source">
<span class="icon-code" aria-hidden="true"></span>
<span class="sr-only">View Source</span>
</a>
</div>
<section class="docstring">
<p> In this callback is called when the Receiver process receives an erlang message.</p>
<p> It must return <code class="inline">{:ok, state}</code>.</p>
<p>Callback implementation for <a href="POABackend.Receiver.html#c:handle_message/2"><code class="inline">POABackend.Receiver.handle_message/2</code></a>.</p>
</section>
</div>
<div class="detail" id="init_receiver/1">
<div class="detail-header">
<a href="#init_receiver/1" class="detail-link" title="Link to this function">
<span class="icon-link" aria-hidden="true"></span>
<span class="sr-only">Link to this function</span>
</a>
<span class="signature">init_receiver(args)</span>
<a href="https://github.com/poanetwork/poa-netstats-wharehouse/blob/v0.1.0/lib/poa_backend/receivers/system/stats.ex#L23" class="view-source" rel="help" title="View Source">
<span class="icon-code" aria-hidden="true"></span>
<span class="sr-only">View Source</span>
</a>
</div>
<section class="docstring">
<p> A callback executed when the Receiver Plugin starts.
The argument is retrieved from the configuration file when the Receiver is defined
It must return <code class="inline">{:ok, state}</code>, that <code class="inline">state</code> will be keept as in <a href="https://hexdocs.pm/elixir/GenServer.html"><code class="inline">GenServer</code></a> and can be
retrieved in the <a href="#metrics_received/3"><code class="inline">metrics_received/3</code></a> function.</p>
<p>Callback implementation for <a href="POABackend.Receiver.html#c:init_receiver/1"><code class="inline">POABackend.Receiver.init_receiver/1</code></a>.</p>
</section>
</div>
<div class="detail" id="metrics_received/3">
<div class="detail-header">
<a href="#metrics_received/3" class="detail-link" title="Link to this function">
<span class="icon-link" aria-hidden="true"></span>
<span class="sr-only">Link to this function</span>
</a>
<span class="signature">metrics_received(arg1, from, state)</span>
<a href="https://github.com/poanetwork/poa-netstats-wharehouse/blob/v0.1.0/lib/poa_backend/receivers/system/stats.ex#L31" class="view-source" rel="help" title="View Source">
<span class="icon-code" aria-hidden="true"></span>
<span class="sr-only">View Source</span>
</a>
</div>
<section class="docstring">
<p> This callback will be called every time a message to the subscribed metric type arrives. It must
return the tuple <code class="inline">{:ok, state}</code></p>
<p>Callback implementation for <a href="POABackend.Receiver.html#c:metrics_received/3"><code class="inline">POABackend.Receiver.metrics_received/3</code></a>.</p>
</section>
</div>
<div class="detail" id="terminate/1">
<div class="detail-header">
<a href="#terminate/1" class="detail-link" title="Link to this function">
<span class="icon-link" aria-hidden="true"></span>
<span class="sr-only">Link to this function</span>
</a>
<span class="signature">terminate(state)</span>
<a href="https://github.com/poanetwork/poa-netstats-wharehouse/blob/v0.1.0/lib/poa_backend/receivers/system/stats.ex#L43" class="view-source" rel="help" title="View Source">
<span class="icon-code" aria-hidden="true"></span>
<span class="sr-only">View Source</span>
</a>
</div>
<section class="docstring">
<p> This callback is called just before the Process goes down. This is a good place for closing connections.</p>
<p>Callback implementation for <a href="POABackend.Receiver.html#c:terminate/1"><code class="inline">POABackend.Receiver.terminate/1</code></a>.</p>
</section>
</div>
</section>
<footer class="footer">
<p>
<span class="line">
Built using
<a href="https://github.com/elixir-lang/ex_doc" title="ExDoc" rel="help" target="_blank">ExDoc</a> (v0.18.4),
</span>
<span class="line">
designed by
<a href="https://twitter.com/dignifiedquire" target="_blank" title="@dignifiedquire">Friedel Ziegelmayer</a>.
</span>
</p>
</footer>
</div>
</div>
</section>
</div>
<script src="dist/app-9bd040e5e5.js"></script>
</body>
</html>

View File

@ -8,7 +8,7 @@
<title>POABackend poa_backend v0.1.0</title>
<link rel="stylesheet" href="dist/app-480ffdc169.css" />
<script src="dist/sidebar_items-3739fd4c82.js"></script>
<script src="dist/sidebar_items-3d14d8fe9b.js"></script>
@ -100,18 +100,52 @@
<pre><code class="elixir">mix deps.get
mix docs</code></pre>
<p>That command will create a <code class="inline">doc/</code> folder with the actual Documentation.</p>
<h2 id="module-configuring-databases-for-first-time" class="section-heading">
<a href="#module-configuring-databases-for-first-time" class="hover-link"><span class="icon-link" aria-hidden="true"></span></a>
Configuring Databases for first time
</h2>
<p><a href="POABackend.html#content"><code class="inline">POABackend</code></a> uses many Databases. For Authentication we use <a href="http://erlang.org/doc/man/mnesia.html">Mnesia</a> as a local database and for some receivers which require storage we use Postgres. All databases are managed on top of <a href="https://hexdocs.pm/ecto/Ecto.html">Ecto</a> a widly used database wrapper for Elixir projects.</p>
<p>For this reason we have to set the databases before running the <a href="POABackend.html#content"><code class="inline">POABackend</code></a> for the first time.</p>
<ul>
<li>Auth Database (Mnesia): Setting up Mnesia is easy since it is working localy and is built in the Erlang Virtual Machine. We only have to say “where” we are going to store the databases files. In order to do that we have to add the configuration to the config file (<code class="inline">prod.exs</code> or <code class="inline">test.exs</code> depending if you want to run tests or production)
</li>
</ul>
<pre><code class="elixir">config :mnesia,
dir: &#39;your/local/path&#39; # make sure this directory exists!</code></pre>
<ul>
<li>Receivers Database (Postgres): This is a little more complex than Mnesia. We need a Postgres instance running somewhere and we have to add the config to the config files
</li>
</ul>
<pre><code class="elixir">config :poa_backend, POABackend.Receivers.Repo,
priv: &quot;priv/receivers&quot;, # this value is not changed
adapter: Ecto.Adapters.Postgres,
database: &quot;poabackend_stats&quot;,
username: &quot;postgres&quot;,
password: &quot;postgres&quot;,
hostname: &quot;localhost&quot;</code></pre>
<p>The important fields here are <code class="inline">database</code>, <code class="inline">username</code>, <code class="inline">password</code> and <code class="inline">hostname</code>. The rest of values must remain exactly as the example.</p>
<p>Once we have set the database configuration we have to create and migrate the databases, in order to do that we should be in the root of the project and run:</p>
<ul>
<li>for production
</li>
</ul>
<pre><code class="elixir">MIX_ENV=prod mix ecto.create
MIX_ENV=prod mix ecto.migrate</code></pre>
<ul>
<li>for test
</li>
</ul>
<pre><code class="elixir">MIX_ENV=test mix ecto.create
MIX_ENV=test mix ecto.migrate</code></pre>
<p>Now the environment is ready for running <a href="POABackend.html#content"><code class="inline">POABackend</code></a></p>
<h2 id="module-run-tests" class="section-heading">
<a href="#module-run-tests" class="hover-link"><span class="icon-link" aria-hidden="true"></span></a>
Run Tests
</h2>
<p><a href="POABackend.html#content"><code class="inline">POABackend</code></a> uses <a href="http://erlang.org/doc/man/mnesia.html">Mnesia</a> as a local database with <a href="https://hexdocs.pm/ecto/Ecto.html">Ecto</a>. In order to have this running we have to create a folder where <code class="inline">Mnesia</code> will store our data. In order to do that we have to define it in the <code class="inline">config/test.exs</code> file like this:</p>
<pre><code class="elixir">config :mnesia,
dir: &#39;your/local/path&#39; # make sure this directory exists!</code></pre>
<p>once we have the path defined we have to create the database (those commands must be run only once if you are going to use always this same path for testing). In your root folder run:</p>
<pre><code class="elixir">MIX_ENV=test mix ecto.create
MIX_ENV=test mix ecto.migrate</code></pre>
<p>Now the environment is set. We can run the tests with:</p>
<p>The first time you run the tests you will need having the Databases environment set up. Check the previous section and set the configuration in the <code class="inline">config/test.exs</code> file.</p>
<p>Once the environment is set. We can run the tests with:</p>
<pre><code class="elixir">mix test</code></pre>
<p><a href="POABackend.html#content"><code class="inline">POABackend</code></a> comes also with a code analysis tool <a href="https://github.com/rrrene/credo">Credo</a> and a types checker tool <a href="https://github.com/jeremyjh/dialyxir">Dialyxir</a>. In order to run them we have to run</p>
<pre><code class="elixir">mix credo

View File

@ -8,7 +8,7 @@
<title>API Reference poa_backend v0.1.0</title>
<link rel="stylesheet" href="dist/app-480ffdc169.css" />
<script src="dist/sidebar_items-3739fd4c82.js"></script>
<script src="dist/sidebar_items-3d14d8fe9b.js"></script>
@ -195,6 +195,26 @@ Those Admins are defined in the Config (ie <code class="inline">prod.exs</code>)
<div class="summary-synopsis"><p>This is a Receiver Plugin which stores the received Ethereum Blocks in DynamoDB</p>
</div>
</div>
<div class="summary-row">
<div class="summary-signature"><a href="POABackend.Receivers.Eth.Stats.html">POABackend.Receivers.Eth.Stats</a></div>
<div class="summary-synopsis"><p>This is a Receiver Plugin which is in charge of storing the Ethereum Statistics received from the Agents in a Postgres
database. If we want to use it we have to declare it in the Config file, inside the <code class="inline">:receivers</code> section, ie</p>
</div>
</div>
<div class="summary-row">
<div class="summary-signature"><a href="POABackend.Receivers.Repo.html">POABackend.Receivers.Repo</a></div>
</div>
<div class="summary-row">
<div class="summary-signature"><a href="POABackend.Receivers.System.Stats.html">POABackend.Receivers.System.Stats</a></div>
<div class="summary-synopsis"><p>This is a Receiver Plugin which is in charge of storing the System Metrics received from the Agents in a Postgres
database. If we want to use it we have to declare it in the Config file, inside the <code class="inline">:receivers</code> section, ie</p>
</div>
</div>
</div>

View File

@ -1 +0,0 @@
sidebarNodes={"extras":[{"id":"api-reference","title":"API Reference","group":"","headers":[{"id":"Modules","anchor":"modules"},{"id":"POA Protocol","anchor":"poa-protocol"}]},{"id":"initial_architecture","title":"Initial Architecture","group":"","headers":[]}],"exceptions":[],"modules":[{"id":"POABackend","title":"POABackend","group":""},{"id":"POABackend.Auth","title":"POABackend.Auth","group":"POA Auth","functions":[{"id":"activate_user/1","anchor":"activate_user/1"},{"id":"authenticate_admin/2","anchor":"authenticate_admin/2"},{"id":"authenticate_user/2","anchor":"authenticate_user/2"},{"id":"create_banned_token/1","anchor":"create_banned_token/1"},{"id":"create_banned_token/2","anchor":"create_banned_token/2"},{"id":"create_user/3","anchor":"create_user/3"},{"id":"deactivate_user/1","anchor":"deactivate_user/1"},{"id":"generate_password/0","anchor":"generate_password/0"},{"id":"generate_user_name/0","anchor":"generate_user_name/0"},{"id":"generate_user_name/1","anchor":"generate_user_name/1"},{"id":"get_user/1","anchor":"get_user/1"},{"id":"purge_banned_tokens/0","anchor":"purge_banned_tokens/0"},{"id":"remove_user/1","anchor":"remove_user/1"},{"id":"token_banned?/1","anchor":"token_banned?/1"},{"id":"user_active?/1","anchor":"user_active?/1"},{"id":"valid_token?/1","anchor":"valid_token?/1"},{"id":"valid_user_name?/1","anchor":"valid_user_name?/1"}]},{"id":"POABackend.Auth.Guardian.Plug","title":"POABackend.Auth.Guardian.Plug","group":"POA Auth","functions":[{"id":"authenticated?/2","anchor":"authenticated?/2"},{"id":"current_claims/2","anchor":"current_claims/2"},{"id":"current_resource/2","anchor":"current_resource/2"},{"id":"current_token/2","anchor":"current_token/2"},{"id":"implementation/0","anchor":"implementation/0"},{"id":"put_current_claims/3","anchor":"put_current_claims/3"},{"id":"put_current_resource/3","anchor":"put_current_resource/3"},{"id":"put_current_token/3","anchor":"put_current_token/3"},{"id":"remember_me/4","anchor":"remember_me/4"},{"id":"remember_me_from_token/4","anchor":"remember_me_from_token/4"},{"id":"sign_in/4","anchor":"sign_in/4"},{"id":"sign_out/2","anchor":"sign_out/2"}]},{"id":"POABackend.Auth.Models.Token","title":"POABackend.Auth.Models.Token","group":"POA Auth","functions":[{"id":"new/2","anchor":"new/2"}],"types":[{"id":"t/0","anchor":"t:t/0"}]},{"id":"POABackend.Auth.Models.User","title":"POABackend.Auth.Models.User","group":"POA Auth","functions":[{"id":"changeset/2","anchor":"changeset/2"}],"types":[{"id":"t/0","anchor":"t:t/0"}]},{"id":"POABackend.Auth.REST","title":"POABackend.Auth.REST","group":"POA Auth"},{"id":"POABackend.Protocol","title":"POABackend.Protocol","group":"POA Protocol"},{"id":"POABackend.Protocol.DataType","title":"POABackend.Protocol.DataType","group":"POA Protocol","types":[{"id":"t/0","anchor":"t:t/0"}]},{"id":"POABackend.Protocol.Message","title":"POABackend.Protocol.Message","group":"POA Protocol","functions":[{"id":"assign/3","anchor":"assign/3"},{"id":"new/0","anchor":"new/0"},{"id":"new/4","anchor":"new/4"}],"types":[{"id":"t/0","anchor":"t:t/0"}]},{"id":"POABackend.Protocol.MessageType","title":"POABackend.Protocol.MessageType","group":"POA Protocol","types":[{"id":"t/0","anchor":"t:t/0"}]},{"id":"POABackend.CustomHandler","title":"POABackend.CustomHandler","group":"Custom Handler","callbacks":[{"id":"child_spec/1","anchor":"c:child_spec/1"}],"functions":[{"id":"publish_inactive/1","anchor":"publish_inactive/1"},{"id":"send_to_receivers/1","anchor":"send_to_receivers/1"}]},{"id":"POABackend.CustomHandler.REST","title":"POABackend.CustomHandler.REST","group":"Custom Handler","functions":[{"id":"ping_monitor/1","anchor":"ping_monitor/1"}]},{"id":"POABackend.Receiver","title":"POABackend.Receiver","group":"Receivers","callbacks":[{"id":"handle_inactive/2","anchor":"c:handle_inactive/2"},{"id":"handle_message/2","anchor":"c:handle_message/2"},{"id":"init_receiver/1","anchor":"c:init_receiver/1"},{"id":"metrics_received/3","anchor":"c:metrics_received/3"},{"id":"terminate/1","anchor":"c:terminate/1"}]},{"id":"POABackend.Receivers.Dashboard","title":"POABackend.Receivers.Dashboard","group":"Receivers","functions":[{"id":"handle_inactive/2","anchor":"handle_inactive/2"},{"id":"handle_message/2","anchor":"handle_message/2"},{"id":"init_receiver/1","anchor":"init_receiver/1"},{"id":"metrics_received/3","anchor":"metrics_received/3"},{"id":"terminate/1","anchor":"terminate/1"}]},{"id":"POABackend.Receivers.DynamoDB","title":"POABackend.Receivers.DynamoDB","group":"Receivers","functions":[{"id":"handle_inactive/2","anchor":"handle_inactive/2"},{"id":"handle_message/2","anchor":"handle_message/2"},{"id":"init_receiver/1","anchor":"init_receiver/1"},{"id":"metrics_received/3","anchor":"metrics_received/3"},{"id":"terminate/1","anchor":"terminate/1"}]}],"tasks":[]}

1
doc/dist/sidebar_items-3d14d8fe9b.js vendored Normal file

File diff suppressed because one or more lines are too long

View File

@ -8,7 +8,7 @@
<title>Initial Architecture poa_backend v0.1.0</title>
<link rel="stylesheet" href="dist/app-480ffdc169.css" />
<script src="dist/sidebar_items-3739fd4c82.js"></script>
<script src="dist/sidebar_items-3d14d8fe9b.js"></script>

View File

@ -8,7 +8,7 @@
<title>Search poa_backend v0.1.0</title>
<link rel="stylesheet" href="dist/app-480ffdc169.css" />
<script src="dist/sidebar_items-3739fd4c82.js"></script>
<script src="dist/sidebar_items-3d14d8fe9b.js"></script>

View File

@ -21,23 +21,56 @@ defmodule POABackend do
That command will create a `doc/` folder with the actual Documentation.
## Run Tests
## Configuring Databases for first time
`POABackend` uses [Mnesia](http://erlang.org/doc/man/mnesia.html) as a local database with [Ecto](https://hexdocs.pm/ecto/Ecto.html). In order to have this running we have to create a folder where `Mnesia` will store our data. In order to do that we have to define it in the `config/test.exs` file like this:
`POABackend` uses many Databases. For Authentication we use [Mnesia](http://erlang.org/doc/man/mnesia.html) as a local database and for some receivers which require storage we use Postgres. All databases are managed on top of [Ecto](https://hexdocs.pm/ecto/Ecto.html) a widly used database wrapper for Elixir projects.
For this reason we have to set the databases before running the `POABackend` for the first time.
- Auth Database (Mnesia): Setting up Mnesia is easy since it is working localy and is built in the Erlang Virtual Machine. We only have to say "where" we are going to store the database's files. In order to do that we have to add the configuration to the config file (`prod.exs` or `test.exs` depending if you want to run tests or production)
```
config :mnesia,
dir: 'your/local/path' # make sure this directory exists!
```
once we have the path defined we have to create the database (those commands must be run only once if you are going to use always this same path for testing). In your root folder run:
- Receivers Database (Postgres): This is a little more complex than Mnesia. We need a Postgres instance running somewhere and we have to add the config to the config files
```
config :poa_backend, POABackend.Receivers.Repo,
priv: "priv/receivers", # this value is not changed
adapter: Ecto.Adapters.Postgres,
database: "poabackend_stats",
username: "postgres",
password: "postgres",
hostname: "localhost"
```
The important fields here are `database`, `username`, `password` and `hostname`. The rest of values must remain exactly as the example.
Once we have set the database configuration we have to create and migrate the databases, in order to do that we should be in the root of the project and run:
- for production
```
MIX_ENV=prod mix ecto.create
MIX_ENV=prod mix ecto.migrate
```
- for test
```
MIX_ENV=test mix ecto.create
MIX_ENV=test mix ecto.migrate
```
Now the environment is set. We can run the tests with:
Now the environment is ready for running `POABackend`
## Run Tests
The first time you run the tests you will need having the Database's environment set up. Check the previous section and set the configuration in the `config/test.exs` file.
Once the environment is set. We can run the tests with:
```
mix test

View File

@ -1,7 +1,20 @@
defmodule POABackend.Receivers.Eth.Stats do
use POABackend.Receiver
@moduledoc false
@moduledoc """
This is a Receiver Plugin which is in charge of storing the Ethereum Statistics received from the Agents in a Postgres
database. If we want to use it we have to declare it in the Config file, inside the `:receivers` section, ie:
{:store_eth_stats, POABackend.Receivers.Eth.Stats, []}
This Plugin uses Postgres as a backend, specifically the `eth_stats` table. Make sure that table exists before using
this Plugin.
We also need to subscribe this plugin to `:ethereum_metrics` metrics in the config file. For that we have to add this line
to the list in the `:subscriptions` section:
{:store_eth_stats, [:ethereum_metrics]}
"""
alias POABackend.Protocol.Message
alias POABackend.Receivers.Models.EthStats

View File

@ -1,7 +1,20 @@
defmodule POABackend.Receivers.System.Stats do
use POABackend.Receiver
@moduledoc false
@moduledoc """
This is a Receiver Plugin which is in charge of storing the System Metrics received from the Agents in a Postgres
database. If we want to use it we have to declare it in the Config file, inside the `:receivers` section, ie:
{:store_system_stats, POABackend.Receivers.System.Stats, []}
This Plugin uses Postgres as a backend, specifically the `system_stats` table. Make sure that table exists before using
this Plugin.
We also need to subscribe this plugin to `:system_metrics` metrics in the config file. For that we have to add this line
to the list in the `:subscriptions` section:
{:store_system_stats, [:system_metrics]}
"""
alias POABackend.Protocol.Message
alias POABackend.Receivers.Models.SystemStats

View File

@ -88,7 +88,9 @@ defmodule POABackend.MixProject do
"Receivers": [
POABackend.Receiver,
POABackend.Receivers.DynamoDB,
POABackend.Receivers.Dashboard
POABackend.Receivers.Dashboard,
POABackend.Receivers.System.Stats,
POABackend.Receivers.Eth.Stats
]
]
]