Merge pull request #75 from poanetwork/ferigis.74.dynamic_metric_types

[#74] Collectors decide the metric type
This commit is contained in:
Joseph Yiasemides 2018-08-23 16:23:44 +02:00 committed by GitHub
commit 07527e811f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
31 changed files with 161 additions and 74 deletions

View File

@ -16,15 +16,7 @@ jobs:
- run: mix deps.get - run: mix deps.get
- run: mix test - run: mix test
- run: mix credo - run: mix credo
- restore_cache:
keys:
- dialyzer-PLT-cache-{{ checksum "mix.exs" }}
- dialyzer-PLT-cache
- run: mix dialyzer - run: mix dialyzer
- save_cache:
key: dialyzer-PLT-cache-{{ checksum "mix.exs" }}
paths:
- _build
- run: env MIX_ENV=test mix coveralls.circle - run: env MIX_ENV=test mix coveralls.circle
- run: env MIX_ENV=test mix coveralls.json - run: env MIX_ENV=test mix coveralls.json
- run: bash <(curl -s https://codecov.io/bash) - run: bash <(curl -s https://codecov.io/bash)

View File

@ -4,7 +4,7 @@ fonts/icomoon.eot
fonts/icomoon.svg fonts/icomoon.svg
fonts/icomoon.ttf fonts/icomoon.ttf
fonts/icomoon.woff fonts/icomoon.woff
dist/sidebar_items-303975f305.js dist/sidebar_items-75149ca71e.js
api-reference.html api-reference.html
initial_architecture.html initial_architecture.html
starting_guide.html starting_guide.html

View File

@ -8,7 +8,7 @@
<title>404 poa_agent v0.1.0</title> <title>404 poa_agent v0.1.0</title>
<link rel="stylesheet" href="dist/app-480ffdc169.css" /> <link rel="stylesheet" href="dist/app-480ffdc169.css" />
<script src="dist/sidebar_items-303975f305.js"></script> <script src="dist/sidebar_items-75149ca71e.js"></script>

View File

@ -8,7 +8,7 @@
<title>POAAgent.Application poa_agent v0.1.0</title> <title>POAAgent.Application poa_agent v0.1.0</title>
<link rel="stylesheet" href="dist/app-480ffdc169.css" /> <link rel="stylesheet" href="dist/app-480ffdc169.css" />
<script src="dist/sidebar_items-303975f305.js"></script> <script src="dist/sidebar_items-75149ca71e.js"></script>

View File

@ -8,7 +8,7 @@
<title>POAAgent.Entity.NameConvention poa_agent v0.1.0</title> <title>POAAgent.Entity.NameConvention poa_agent v0.1.0</title>
<link rel="stylesheet" href="dist/app-480ffdc169.css" /> <link rel="stylesheet" href="dist/app-480ffdc169.css" />
<script src="dist/sidebar_items-303975f305.js"></script> <script src="dist/sidebar_items-75149ca71e.js"></script>

View File

@ -8,7 +8,7 @@
<title>POAAgent.Format.POAProtocol.Data.Format poa_agent v0.1.0</title> <title>POAAgent.Format.POAProtocol.Data.Format poa_agent v0.1.0</title>
<link rel="stylesheet" href="dist/app-480ffdc169.css" /> <link rel="stylesheet" href="dist/app-480ffdc169.css" />
<script src="dist/sidebar_items-303975f305.js"></script> <script src="dist/sidebar_items-75149ca71e.js"></script>

View File

@ -8,7 +8,7 @@
<title>POAAgent.Plugins.Collector poa_agent v0.1.0</title> <title>POAAgent.Plugins.Collector poa_agent v0.1.0</title>
<link rel="stylesheet" href="dist/app-480ffdc169.css" /> <link rel="stylesheet" href="dist/app-480ffdc169.css" />
<script src="dist/sidebar_items-303975f305.js"></script> <script src="dist/sidebar_items-75149ca71e.js"></script>
@ -129,13 +129,15 @@ and the Transfers related with it. A <code class="inline">Transfer</code> is a P
Implementing A Collector Plugin Implementing A Collector Plugin
</h2> </h2>
<p>In order to implement your Collector Plugin you must implement 3 functions.</p> <p>In order to implement your Collector Plugin you must implement 4 functions.</p>
<ul> <ul>
<li><code class="inline">init_collector/1</code>: Called only once when the process starts <li><code class="inline">init_collector/1</code>: Called only once when the process starts
</li> </li>
<li><code class="inline">collect/1</code>: This function is called periodically after <code class="inline">frequency</code> milliseconds. It is responsible <li><code class="inline">collect/1</code>: This function is called periodically after <code class="inline">frequency</code> milliseconds. It is responsible
of retrieving the metrics of retrieving the metrics
</li> </li>
<li><code class="inline">metric_type/0</code>: This function must return the metric type in <code class="inline">string</code> format (i.e “ethereum_metric”)
</li>
<li><code class="inline">terminate/1</code>: Called just before stopping the process <li><code class="inline">terminate/1</code>: Called just before stopping the process
</li> </li>
</ul> </ul>
@ -152,6 +154,10 @@ of retrieving the metrics
{:transfer, &quot;data retrieved&quot;, :no_state} {:transfer, &quot;data retrieved&quot;, :no_state}
end end
def metric_type do
&quot;my_metrics_type&quot;
end
def terminate(_state) do def terminate(_state) do
:ok :ok
end end
@ -205,6 +211,16 @@ end</code></pre>
metrics we want to send to the transfer</p> metrics we want to send to the transfer</p>
</div> </div>
</div>
<div class="summary-row">
<div class="summary-signature">
<a href="#c:metric_type/0">metric_type()</a>
</div>
<div class="summary-synopsis"><p>This callback must return the metric type in <code class="inline">string</code> format. For example, if your collector is gathering metrics about
Ethereum you can use “ethereum_metric” here</p>
</div>
</div> </div>
<div class="summary-row"> <div class="summary-row">
<div class="summary-signature"> <div class="summary-signature">
@ -245,7 +261,7 @@ end</code></pre>
</a> </a>
<span class="signature">collect(state)</span> <span class="signature">collect(state)</span>
<a href="https://github.com/poanetwork/poa-netstats-agent/blob/v0.1.0/lib/poa_agent/plugins/collector.ex#L101" class="view-source" rel="help" title="View Source"> <a href="https://github.com/poanetwork/poa-netstats-agent/blob/v0.1.0/lib/poa_agent/plugins/collector.ex#L106" class="view-source" rel="help" title="View Source">
<span class="icon-code" aria-hidden="true"></span> <span class="icon-code" aria-hidden="true"></span>
<span class="sr-only">View Source</span> <span class="sr-only">View Source</span>
</a> </a>
@ -278,7 +294,7 @@ end</code></pre>
</a> </a>
<span class="signature">init_collector(args)</span> <span class="signature">init_collector(args)</span>
<a href="https://github.com/poanetwork/poa-netstats-agent/blob/v0.1.0/lib/poa_agent/plugins/collector.ex#L92" class="view-source" rel="help" title="View Source"> <a href="https://github.com/poanetwork/poa-netstats-agent/blob/v0.1.0/lib/poa_agent/plugins/collector.ex#L97" class="view-source" rel="help" title="View Source">
<span class="icon-code" aria-hidden="true"></span> <span class="icon-code" aria-hidden="true"></span>
<span class="sr-only">View Source</span> <span class="sr-only">View Source</span>
</a> </a>
@ -304,6 +320,36 @@ end</code></pre>
</section> </section>
</div> </div>
<div class="detail" id="c:metric_type/0">
<div class="detail-header">
<a href="#c:metric_type/0" class="detail-link" title="Link to this callback">
<span class="icon-link" aria-hidden="true"></span>
<span class="sr-only">Link to this callback</span>
</a>
<span class="signature">metric_type()</span>
<a href="https://github.com/poanetwork/poa-netstats-agent/blob/v0.1.0/lib/poa_agent/plugins/collector.ex#L113" 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 class="specs">
<pre>metric_type() :: <a href="https://hexdocs.pm/elixir/String.html#t:t/0">String.t</a>()</pre>
</div>
</div>
<section class="docstring">
<p>This callback must return the metric type in <code class="inline">string</code> format. For example, if your collector is gathering metrics about
Ethereum you can use “ethereum_metric” here.</p>
</section>
</div>
<div class="detail" id="c:terminate/1"> <div class="detail" id="c:terminate/1">
@ -314,7 +360,7 @@ end</code></pre>
</a> </a>
<span class="signature">terminate(state)</span> <span class="signature">terminate(state)</span>
<a href="https://github.com/poanetwork/poa-netstats-agent/blob/v0.1.0/lib/poa_agent/plugins/collector.ex#L107" class="view-source" rel="help" title="View Source"> <a href="https://github.com/poanetwork/poa-netstats-agent/blob/v0.1.0/lib/poa_agent/plugins/collector.ex#L118" class="view-source" rel="help" title="View Source">
<span class="icon-code" aria-hidden="true"></span> <span class="icon-code" aria-hidden="true"></span>
<span class="sr-only">View Source</span> <span class="sr-only">View Source</span>
</a> </a>

View File

@ -8,7 +8,7 @@
<title>POAAgent.Plugins.Collectors.Eth.Information poa_agent v0.1.0</title> <title>POAAgent.Plugins.Collectors.Eth.Information poa_agent v0.1.0</title>
<link rel="stylesheet" href="dist/app-480ffdc169.css" /> <link rel="stylesheet" href="dist/app-480ffdc169.css" />
<script src="dist/sidebar_items-303975f305.js"></script> <script src="dist/sidebar_items-75149ca71e.js"></script>

View File

@ -8,7 +8,7 @@
<title>POAAgent.Plugins.Collectors.Eth.LatestBlock poa_agent v0.1.0</title> <title>POAAgent.Plugins.Collectors.Eth.LatestBlock poa_agent v0.1.0</title>
<link rel="stylesheet" href="dist/app-480ffdc169.css" /> <link rel="stylesheet" href="dist/app-480ffdc169.css" />
<script src="dist/sidebar_items-303975f305.js"></script> <script src="dist/sidebar_items-75149ca71e.js"></script>

View File

@ -8,7 +8,7 @@
<title>POAAgent.Plugins.Collectors.Eth.Pending poa_agent v0.1.0</title> <title>POAAgent.Plugins.Collectors.Eth.Pending poa_agent v0.1.0</title>
<link rel="stylesheet" href="dist/app-480ffdc169.css" /> <link rel="stylesheet" href="dist/app-480ffdc169.css" />
<script src="dist/sidebar_items-303975f305.js"></script> <script src="dist/sidebar_items-75149ca71e.js"></script>

View File

@ -8,7 +8,7 @@
<title>POAAgent.Plugins.Collectors.Eth.Stats poa_agent v0.1.0</title> <title>POAAgent.Plugins.Collectors.Eth.Stats poa_agent v0.1.0</title>
<link rel="stylesheet" href="dist/app-480ffdc169.css" /> <link rel="stylesheet" href="dist/app-480ffdc169.css" />
<script src="dist/sidebar_items-303975f305.js"></script> <script src="dist/sidebar_items-75149ca71e.js"></script>

View File

@ -8,7 +8,7 @@
<title>POAAgent.Plugins.Transfer poa_agent v0.1.0</title> <title>POAAgent.Plugins.Transfer poa_agent v0.1.0</title>
<link rel="stylesheet" href="dist/app-480ffdc169.css" /> <link rel="stylesheet" href="dist/app-480ffdc169.css" />
<script src="dist/sidebar_items-303975f305.js"></script> <script src="dist/sidebar_items-75149ca71e.js"></script>
@ -115,7 +115,7 @@ process per each one of them. That configuration is referenced by :transfers key
<ul> <ul>
<li><code class="inline">init_transfer/1</code>: Called only once when the process starts <li><code class="inline">init_transfer/1</code>: Called only once when the process starts
</li> </li>
<li><code class="inline">data_received/2</code>: This function is called every time a Collector sends metrics to the Transfer <li><code class="inline">data_received/4</code>: This function is called every time a Collector sends metrics to the Transfer
</li> </li>
<li><code class="inline">handle_message/1</code>: This is called when the transfer process receives an Erlang message <li><code class="inline">handle_message/1</code>: This is called when the transfer process receives an Erlang message
</li> </li>
@ -130,7 +130,7 @@ process per each one of them. That configuration is referenced by :transfers key
{:ok, :no_state} {:ok, :no_state}
end end
def data_received(label, data, state) do def data_received(label, metric_type, data, state) do
IO.puts &quot;Received data from the collector referenced by label&quot; IO.puts &quot;Received data from the collector referenced by label&quot;
{:ok, :no_state} {:ok, :no_state}
end end
@ -168,7 +168,7 @@ end</code></pre>
</h2> </h2>
<div class="summary-row"> <div class="summary-row">
<div class="summary-signature"> <div class="summary-signature">
<a href="#c:data_received/3">data_received(label, data, state)</a> <a href="#c:data_received/4">data_received(label, metric_type, data, state)</a>
</div> </div>
<div class="summary-synopsis"><p>In this callback is called when a Collector sends data to this Transfer</p> <div class="summary-synopsis"><p>In this callback is called when a Collector sends data to this Transfer</p>
@ -225,15 +225,15 @@ end</code></pre>
</a> </a>
Callbacks Callbacks
</h1> </h1>
<div class="detail" id="c:data_received/3"> <div class="detail" id="c:data_received/4">
<div class="detail-header"> <div class="detail-header">
<a href="#c:data_received/3" class="detail-link" title="Link to this callback"> <a href="#c:data_received/4" class="detail-link" title="Link to this callback">
<span class="icon-link" aria-hidden="true"></span> <span class="icon-link" aria-hidden="true"></span>
<span class="sr-only">Link to this callback</span> <span class="sr-only">Link to this callback</span>
</a> </a>
<span class="signature">data_received(label, data, state)</span> <span class="signature">data_received(label, metric_type, data, state)</span>
<a href="https://github.com/poanetwork/poa-netstats-agent/blob/v0.1.0/lib/poa_agent/plugins/transfer.ex#L84" class="view-source" rel="help" title="View Source"> <a href="https://github.com/poanetwork/poa-netstats-agent/blob/v0.1.0/lib/poa_agent/plugins/transfer.ex#L84" class="view-source" rel="help" title="View Source">
<span class="icon-code" aria-hidden="true"></span> <span class="icon-code" aria-hidden="true"></span>
@ -244,15 +244,20 @@ end</code></pre>
<div class="specs"> <div class="specs">
<pre>data_received(label :: <a href="https://hexdocs.pm/elixir/typespecs.html#basic-types">atom</a>(), data :: <a href="https://hexdocs.pm/elixir/typespecs.html#basic-types">any</a>(), state :: <a href="https://hexdocs.pm/elixir/typespecs.html#basic-types">any</a>()) :: {:ok, <a href="https://hexdocs.pm/elixir/typespecs.html#basic-types">any</a>()}</pre> <pre>data_received(
label :: <a href="https://hexdocs.pm/elixir/typespecs.html#basic-types">atom</a>(),
metric_type :: <a href="https://hexdocs.pm/elixir/String.html#t:t/0">String.t</a>(),
data :: <a href="https://hexdocs.pm/elixir/typespecs.html#basic-types">any</a>(),
state :: <a href="https://hexdocs.pm/elixir/typespecs.html#basic-types">any</a>()
) :: {:ok, <a href="https://hexdocs.pm/elixir/typespecs.html#basic-types">any</a>()}</pre>
</div> </div>
</div> </div>
<section class="docstring"> <section class="docstring">
<p> In this callback is called when a Collector sends data to this Transfer.</p> <p> In this callback is called when a Collector sends data to this Transfer.</p>
<p> The data received is in <code class="inline">{label, data}</code> format where <code class="inline">label</code> identifies the Collector and the <p> Regarding the parameters, <code class="inline">label</code> identifies the Collector, <code class="inline">metric_type</code> is the metric type in String format, it is used in order
data is the real data received.</p> to know which kind of data we are sending, the <code class="inline">data</code> is the real data received, and the <code class="inline">state</code> is the Collectors state</p>
<p> It must return <code class="inline">{:ok, state}</code>.</p> <p> It must return <code class="inline">{:ok, state}</code>.</p>
</section> </section>

View File

@ -8,7 +8,7 @@
<title>POAAgent.Plugins.Transfers.WebSocket.Primus poa_agent v0.1.0</title> <title>POAAgent.Plugins.Transfers.WebSocket.Primus poa_agent v0.1.0</title>
<link rel="stylesheet" href="dist/app-480ffdc169.css" /> <link rel="stylesheet" href="dist/app-480ffdc169.css" />
<script src="dist/sidebar_items-303975f305.js"></script> <script src="dist/sidebar_items-75149ca71e.js"></script>
@ -99,7 +99,7 @@
</h2> </h2>
<div class="summary-row"> <div class="summary-row">
<div class="summary-signature"> <div class="summary-signature">
<a href="#data_received/3">data_received(label, data, state)</a> <a href="#data_received/4">data_received(label, metric_type, data, state)</a>
</div> </div>
<div class="summary-synopsis"><p>In this callback is called when a Collector sends data to this Transfer</p> <div class="summary-synopsis"><p>In this callback is called when a Collector sends data to this Transfer</p>
@ -156,15 +156,15 @@
</a> </a>
Functions Functions
</h1> </h1>
<div class="detail" id="data_received/3"> <div class="detail" id="data_received/4">
<div class="detail-header"> <div class="detail-header">
<a href="#data_received/3" class="detail-link" title="Link to this function"> <a href="#data_received/4" class="detail-link" title="Link to this function">
<span class="icon-link" aria-hidden="true"></span> <span class="icon-link" aria-hidden="true"></span>
<span class="sr-only">Link to this function</span> <span class="sr-only">Link to this function</span>
</a> </a>
<span class="signature">data_received(label, data, state)</span> <span class="signature">data_received(label, metric_type, data, state)</span>
<a href="https://github.com/poanetwork/poa-netstats-agent/blob/v0.1.0/lib/poa_agent/plugins/transfers/web_socket/primus.ex#L82" class="view-source" rel="help" title="View Source"> <a href="https://github.com/poanetwork/poa-netstats-agent/blob/v0.1.0/lib/poa_agent/plugins/transfers/web_socket/primus.ex#L82" class="view-source" rel="help" title="View Source">
<span class="icon-code" aria-hidden="true"></span> <span class="icon-code" aria-hidden="true"></span>
@ -176,10 +176,10 @@
</div> </div>
<section class="docstring"> <section class="docstring">
<p> In this callback is called when a Collector sends data to this Transfer.</p> <p> In this callback is called when a Collector sends data to this Transfer.</p>
<p> The data received is in <code class="inline">{label, data}</code> format where <code class="inline">label</code> identifies the Collector and the <p> Regarding the parameters, <code class="inline">label</code> identifies the Collector, <code class="inline">metric_type</code> is the metric type in String format, it is used in order
data is the real data received.</p> to know which kind of data we are sending, the <code class="inline">data</code> is the real data received, and the <code class="inline">state</code> is the Collectors state</p>
<p> It must return <code class="inline">{:ok, state}</code>.</p> <p> It must return <code class="inline">{:ok, state}</code>.</p>
<p>Callback implementation for <a href="POAAgent.Plugins.Transfer.html#c:data_received/3"><code class="inline">POAAgent.Plugins.Transfer.data_received/3</code></a>.</p> <p>Callback implementation for <a href="POAAgent.Plugins.Transfer.html#c:data_received/4"><code class="inline">POAAgent.Plugins.Transfer.data_received/4</code></a>.</p>
</section> </section>
</div> </div>

View File

@ -8,7 +8,7 @@
<title>POAAgent poa_agent v0.1.0</title> <title>POAAgent poa_agent v0.1.0</title>
<link rel="stylesheet" href="dist/app-480ffdc169.css" /> <link rel="stylesheet" href="dist/app-480ffdc169.css" />
<script src="dist/sidebar_items-303975f305.js"></script> <script src="dist/sidebar_items-75149ca71e.js"></script>

View File

@ -8,7 +8,7 @@
<title>API Reference poa_agent v0.1.0</title> <title>API Reference poa_agent v0.1.0</title>
<link rel="stylesheet" href="dist/app-480ffdc169.css" /> <link rel="stylesheet" href="dist/app-480ffdc169.css" />
<script src="dist/sidebar_items-303975f305.js"></script> <script src="dist/sidebar_items-75149ca71e.js"></script>

View File

@ -1 +1 @@
sidebarNodes={"extras":[{"id":"api-reference","title":"API Reference","group":"","headers":[{"id":"Modules","anchor":"modules"}]},{"id":"initial_architecture","title":"Initial Architecture","group":"","headers":[{"id":"Network Agent Architecture","anchor":"network-agent-architecture"},{"id":"Network Server Architecture","anchor":"network-server-architecture"}]},{"id":"starting_guide","title":"Getting Started","group":"","headers":[{"id":"Setting up","anchor":"setting-up"},{"id":"Connecting to POA Warehouse","anchor":"connecting-to-poa-warehouse"}]}],"exceptions":[],"modules":[{"id":"POAAgent","title":"POAAgent","group":""},{"id":"POAAgent.Application","title":"POAAgent.Application","group":"","functions":[{"id":"start/2","anchor":"start/2"}]},{"id":"POAAgent.Entity.NameConvention","title":"POAAgent.Entity.NameConvention","group":"","functions":[{"id":"from_elixir_to_node/1","anchor":"from_elixir_to_node/1"}],"types":[{"id":"t/0","anchor":"t:t/0"}]},{"id":"POAAgent.Format.POAProtocol.Data.Format","title":"POAAgent.Format.POAProtocol.Data.Format","group":"","functions":[{"id":"to_data/1","anchor":"to_data/1"}],"types":[{"id":"t/0","anchor":"t:t/0"}]},{"id":"POAAgent.Plugins.Transfers.WebSocket.Primus","title":"POAAgent.Plugins.Transfers.WebSocket.Primus","group":"","functions":[{"id":"data_received/3","anchor":"data_received/3"},{"id":"handle_message/2","anchor":"handle_message/2"},{"id":"init_transfer/1","anchor":"init_transfer/1"},{"id":"terminate/1","anchor":"terminate/1"}]},{"id":"POAAgent.Plugins.Collector","title":"POAAgent.Plugins.Collector","group":"Plugins","callbacks":[{"id":"collect/1","anchor":"c:collect/1"},{"id":"init_collector/1","anchor":"c:init_collector/1"},{"id":"terminate/1","anchor":"c:terminate/1"}]},{"id":"POAAgent.Plugins.Transfer","title":"POAAgent.Plugins.Transfer","group":"Plugins","callbacks":[{"id":"data_received/3","anchor":"c:data_received/3"},{"id":"handle_message/2","anchor":"c:handle_message/2"},{"id":"init_transfer/1","anchor":"c:init_transfer/1"},{"id":"terminate/1","anchor":"c:terminate/1"}]},{"id":"POAAgent.Plugins.Collectors.Eth.Information","title":"POAAgent.Plugins.Collectors.Eth.Information","group":"Ethereum Plugins"},{"id":"POAAgent.Plugins.Collectors.Eth.LatestBlock","title":"POAAgent.Plugins.Collectors.Eth.LatestBlock","group":"Ethereum Plugins"},{"id":"POAAgent.Plugins.Collectors.Eth.Pending","title":"POAAgent.Plugins.Collectors.Eth.Pending","group":"Ethereum Plugins"},{"id":"POAAgent.Plugins.Collectors.Eth.Stats","title":"POAAgent.Plugins.Collectors.Eth.Stats","group":"Ethereum Plugins"}],"tasks":[]} sidebarNodes={"extras":[{"id":"api-reference","title":"API Reference","group":"","headers":[{"id":"Modules","anchor":"modules"}]},{"id":"initial_architecture","title":"Initial Architecture","group":"","headers":[{"id":"Network Agent Architecture","anchor":"network-agent-architecture"},{"id":"Network Server Architecture","anchor":"network-server-architecture"}]},{"id":"starting_guide","title":"Getting Started","group":"","headers":[{"id":"Setting up","anchor":"setting-up"},{"id":"Connecting to POA Warehouse","anchor":"connecting-to-poa-warehouse"}]}],"exceptions":[],"modules":[{"id":"POAAgent","title":"POAAgent","group":""},{"id":"POAAgent.Application","title":"POAAgent.Application","group":"","functions":[{"id":"start/2","anchor":"start/2"}]},{"id":"POAAgent.Entity.NameConvention","title":"POAAgent.Entity.NameConvention","group":"","functions":[{"id":"from_elixir_to_node/1","anchor":"from_elixir_to_node/1"}],"types":[{"id":"t/0","anchor":"t:t/0"}]},{"id":"POAAgent.Format.POAProtocol.Data.Format","title":"POAAgent.Format.POAProtocol.Data.Format","group":"","functions":[{"id":"to_data/1","anchor":"to_data/1"}],"types":[{"id":"t/0","anchor":"t:t/0"}]},{"id":"POAAgent.Plugins.Transfers.WebSocket.Primus","title":"POAAgent.Plugins.Transfers.WebSocket.Primus","group":"","functions":[{"id":"data_received/4","anchor":"data_received/4"},{"id":"handle_message/2","anchor":"handle_message/2"},{"id":"init_transfer/1","anchor":"init_transfer/1"},{"id":"terminate/1","anchor":"terminate/1"}]},{"id":"POAAgent.Plugins.Collector","title":"POAAgent.Plugins.Collector","group":"Plugins","callbacks":[{"id":"collect/1","anchor":"c:collect/1"},{"id":"init_collector/1","anchor":"c:init_collector/1"},{"id":"metric_type/0","anchor":"c:metric_type/0"},{"id":"terminate/1","anchor":"c:terminate/1"}]},{"id":"POAAgent.Plugins.Transfer","title":"POAAgent.Plugins.Transfer","group":"Plugins","callbacks":[{"id":"data_received/4","anchor":"c:data_received/4"},{"id":"handle_message/2","anchor":"c:handle_message/2"},{"id":"init_transfer/1","anchor":"c:init_transfer/1"},{"id":"terminate/1","anchor":"c:terminate/1"}]},{"id":"POAAgent.Plugins.Collectors.Eth.Information","title":"POAAgent.Plugins.Collectors.Eth.Information","group":"Ethereum Plugins"},{"id":"POAAgent.Plugins.Collectors.Eth.LatestBlock","title":"POAAgent.Plugins.Collectors.Eth.LatestBlock","group":"Ethereum Plugins"},{"id":"POAAgent.Plugins.Collectors.Eth.Pending","title":"POAAgent.Plugins.Collectors.Eth.Pending","group":"Ethereum Plugins"},{"id":"POAAgent.Plugins.Collectors.Eth.Stats","title":"POAAgent.Plugins.Collectors.Eth.Stats","group":"Ethereum Plugins"}],"tasks":[]}

View File

@ -8,7 +8,7 @@
<title>Initial Architecture poa_agent v0.1.0</title> <title>Initial Architecture poa_agent v0.1.0</title>
<link rel="stylesheet" href="dist/app-480ffdc169.css" /> <link rel="stylesheet" href="dist/app-480ffdc169.css" />
<script src="dist/sidebar_items-303975f305.js"></script> <script src="dist/sidebar_items-75149ca71e.js"></script>

View File

@ -8,7 +8,7 @@
<title>Search poa_agent v0.1.0</title> <title>Search poa_agent v0.1.0</title>
<link rel="stylesheet" href="dist/app-480ffdc169.css" /> <link rel="stylesheet" href="dist/app-480ffdc169.css" />
<script src="dist/sidebar_items-303975f305.js"></script> <script src="dist/sidebar_items-75149ca71e.js"></script>

View File

@ -8,7 +8,7 @@
<title>Getting Started poa_agent v0.1.0</title> <title>Getting Started poa_agent v0.1.0</title>
<link rel="stylesheet" href="dist/app-480ffdc169.css" /> <link rel="stylesheet" href="dist/app-480ffdc169.css" />
<script src="dist/sidebar_items-303975f305.js"></script> <script src="dist/sidebar_items-75149ca71e.js"></script>

View File

@ -51,11 +51,12 @@ defmodule POAAgent.Plugins.Collector do
## Implementing A Collector Plugin ## Implementing A Collector Plugin
In order to implement your Collector Plugin you must implement 3 functions. In order to implement your Collector Plugin you must implement 4 functions.
- `init_collector/1`: Called only once when the process starts - `init_collector/1`: Called only once when the process starts
- `collect/1`: This function is called periodically after `frequency` milliseconds. It is responsible - `collect/1`: This function is called periodically after `frequency` milliseconds. It is responsible
of retrieving the metrics of retrieving the metrics
- `metric_type/0`: This function must return the metric type in `string` format (i.e "ethereum_metric")
- `terminate/1`: Called just before stopping the process - `terminate/1`: Called just before stopping the process
This is a simple example of custom Collector Plugin This is a simple example of custom Collector Plugin
@ -72,6 +73,10 @@ defmodule POAAgent.Plugins.Collector do
{:transfer, "data retrieved", :no_state} {:transfer, "data retrieved", :no_state}
end end
def metric_type do
"my_metrics_type"
end
def terminate(_state) do def terminate(_state) do
:ok :ok
end end
@ -101,6 +106,12 @@ defmodule POAAgent.Plugins.Collector do
@callback collect(state :: any()) :: {:transfer, data :: any(), state :: any()} @callback collect(state :: any()) :: {:transfer, data :: any(), state :: any()}
| {:notransfer, state :: any()} | {:notransfer, state :: any()}
@doc """
This callback must return the metric type in `string` format. For example, if your collector is gathering metrics about
Ethereum you can use "ethereum_metric" here.
"""
@callback metric_type() :: String.t()
@doc """ @doc """
This callback is called just before the Process goes down. This is a good place for closing connections. This callback is called just before the Process goes down. This is a good place for closing connections.
""" """
@ -166,7 +177,7 @@ defmodule POAAgent.Plugins.Collector do
@doc false @doc false
defp transfer({:transfer, data, internal_state}, label, transfers) do defp transfer({:transfer, data, internal_state}, label, transfers) do
Enum.each(transfers, &GenServer.cast(&1, %{label: label, data: data})) Enum.each(transfers, &GenServer.cast(&1, %{label: label, metric_type: metric_type(), data: data}))
internal_state internal_state
end end
defp transfer({:notransfer, internal_state}, _label, _transfers) do defp transfer({:notransfer, internal_state}, _label, _transfers) do

View File

@ -36,6 +36,12 @@ defmodule POAAgent.Plugins.Collectors.Eth.Information do
{:transfer, information(args), %{state | information: information}} {:transfer, information(args), %{state | information: information}}
end end
@doc false
@spec metric_type() :: String.t
def metric_type do
"ethereum_metrics"
end
@doc false @doc false
@spec terminate(internal_state()) :: :ok @spec terminate(internal_state()) :: :ok
def terminate(_state) do def terminate(_state) do

View File

@ -59,6 +59,12 @@ defmodule POAAgent.Plugins.Collectors.Eth.LatestBlock do
end end
end end
@doc false
@spec metric_type() :: String.t
def metric_type do
"ethereum_metrics"
end
@doc false @doc false
@spec terminate(internal_state()) :: :ok @spec terminate(internal_state()) :: :ok
def terminate(_state) do def terminate(_state) do

View File

@ -37,6 +37,12 @@ defmodule POAAgent.Plugins.Collectors.Eth.Pending do
end end
end end
@doc false
@spec metric_type() :: String.t
def metric_type do
"ethereum_metrics"
end
@doc false @doc false
@spec terminate(internal_state()) :: :ok @spec terminate(internal_state()) :: :ok
def terminate(_state) do def terminate(_state) do

View File

@ -48,6 +48,12 @@ defmodule POAAgent.Plugins.Collectors.Eth.Stats do
end end
end end
@doc false
@spec metric_type() :: String.t
def metric_type do
"ethereum_metrics"
end
@doc false @doc false
@spec terminate(internal_state()) :: :ok @spec terminate(internal_state()) :: :ok
def terminate(_state) do def terminate(_state) do

View File

@ -34,7 +34,7 @@ defmodule POAAgent.Plugins.Transfer do
In order to implement your Transfer Plugin you must implement 3 functions. In order to implement your Transfer Plugin you must implement 3 functions.
- `init_transfer/1`: Called only once when the process starts - `init_transfer/1`: Called only once when the process starts
- `data_received/2`: This function is called every time a Collector sends metrics to the Transfer - `data_received/4`: This function is called every time a Collector sends metrics to the Transfer
- `handle_message/1`: This is called when the transfer process receives an Erlang message - `handle_message/1`: This is called when the transfer process receives an Erlang message
- `terminate/1`: Called just before stopping the process - `terminate/1`: Called just before stopping the process
@ -47,7 +47,7 @@ defmodule POAAgent.Plugins.Transfer do
{:ok, :no_state} {:ok, :no_state}
end end
def data_received(label, data, state) do def data_received(label, metric_type, data, state) do
IO.puts "Received data from the collector referenced by label" IO.puts "Received data from the collector referenced by label"
{:ok, :no_state} {:ok, :no_state}
end end
@ -76,12 +76,12 @@ defmodule POAAgent.Plugins.Transfer do
@doc """ @doc """
In this callback is called when a Collector sends data to this Transfer. In this callback is called when a Collector sends data to this Transfer.
The data received is in `{label, data}` format where `label` identifies the Collector and the Regarding the parameters, `label` identifies the Collector, `metric_type` is the metric type in String format, it is used in order
data is the real data received. to know which kind of data we are sending, the `data` is the real data received, and the `state` is the Collector's state
It must return `{:ok, state}`. It must return `{:ok, state}`.
""" """
@callback data_received(label :: atom(), data :: any(), state :: any()) :: {:ok, any()} @callback data_received(label :: atom(), metric_type :: String.t, data :: any(), state :: any()) :: {:ok, any()}
@doc """ @doc """
In this callback is called when the Transfer process receives an erlang message. In this callback is called when the Transfer process receives an erlang message.
@ -123,8 +123,8 @@ defmodule POAAgent.Plugins.Transfer do
end end
@doc false @doc false
def handle_cast(%{label: label, data: data}, state) do def handle_cast(%{label: label, metric_type: metric_type, data: data}, state) do
{:ok, internal_state} = data_received(label, data, state.internal_state) {:ok, internal_state} = data_received(label, metric_type, data, state.internal_state)
{:noreply, %{state | internal_state: internal_state}} {:noreply, %{state | internal_state: internal_state}}
end end
def handle_cast(msg, state) do def handle_cast(msg, state) do

View File

@ -32,12 +32,12 @@ defmodule POAAgent.Plugins.Transfers.HTTP.REST do
{:ok, state} {:ok, state}
end end
def data_received(label, data, state) when is_list(data) do def data_received(label, metric_type, data, state) when is_list(data) do
require Logger require Logger
Logger.info("Received data from the collector referenced by label: #{label}.") Logger.info("Received data from the collector referenced by label: #{label}.")
state = Enum.reduce(data, state, fn(message, state) -> state = Enum.reduce(data, state, fn(message, state) ->
{_, state} = send_metric(message, state) {_, state} = send_metric(message, metric_type, state)
state state
end) end)
@ -45,8 +45,8 @@ defmodule POAAgent.Plugins.Transfers.HTTP.REST do
{:ok, state} {:ok, state}
end end
def data_received(label, data, state) do def data_received(label, metric_type, data, state) do
data_received(label, [data], state) data_received(label, metric_type, [data], state)
end end
def terminate(_) do def terminate(_) do
@ -80,10 +80,10 @@ defmodule POAAgent.Plugins.Transfers.HTTP.REST do
latency latency
|> Latency.new |> Latency.new
|> send_metric(state) |> send_metric("networking_metrics", state)
end end
defp send_metric(metric, state) do defp send_metric(metric, metric_type, state) do
url = "/data" url = "/data"
data = data =
@ -94,7 +94,7 @@ defmodule POAAgent.Plugins.Transfers.HTTP.REST do
event = event =
%{} %{}
|> Map.put(:id, state.identifier) |> Map.put(:id, state.identifier)
|> Map.put(:type, "ethereum_metrics") # for now only ethereum_metrics |> Map.put(:type, metric_type)
|> Map.put(:data, data) |> Map.put(:data, data)
|> Msgpax.pack!() |> Msgpax.pack!()

View File

@ -43,7 +43,7 @@ defmodule POAAgent.Plugins.Transfers.WebSocket.Primus do
{:ok, state} {:ok, state}
end end
def data_received(label, data, %{connected?: false} = state) when is_list(data) do def data_received(label, _metric_type, data, %{connected?: false} = state) when is_list(data) do
last_metrics = Enum.reduce(data, state.last_metrics, fn(message, metrics) -> last_metrics = Enum.reduce(data, state.last_metrics, fn(message, metrics) ->
Map.put(metrics, label, message) Map.put(metrics, label, message)
end) end)
@ -51,7 +51,7 @@ defmodule POAAgent.Plugins.Transfers.WebSocket.Primus do
{:ok, %{state | last_metrics: last_metrics}} {:ok, %{state | last_metrics: last_metrics}}
end end
def data_received(label, [%Ethereum.Block{} = block], %{client: client} = state) do def data_received(label, _metric_type, [%Ethereum.Block{} = block], %{client: client} = state) do
require Logger require Logger
Logger.info("Received data from the collector referenced by label: #{label}.") Logger.info("Received data from the collector referenced by label: #{label}.")
@ -66,7 +66,7 @@ defmodule POAAgent.Plugins.Transfers.WebSocket.Primus do
{:ok, %{state | last_metrics: Map.put(state.last_metrics, label, block)}} {:ok, %{state | last_metrics: Map.put(state.last_metrics, label, block)}}
end end
def data_received(label, data, %{client: client} = state) when is_list(data) do def data_received(label, _metric_type, data, %{client: client} = state) when is_list(data) do
require Logger require Logger
Logger.info("Received data from the collector referenced by label: #{label}.") Logger.info("Received data from the collector referenced by label: #{label}.")
@ -79,8 +79,8 @@ defmodule POAAgent.Plugins.Transfers.WebSocket.Primus do
{:ok, %{state | last_metrics: last_metrics}} {:ok, %{state | last_metrics: last_metrics}}
end end
def data_received(label, data, state) do def data_received(label, metric_type, data, state) do
data_received(label, [data], state) data_received(label, metric_type, [data], state)
end end
def handle_message(:attempt_to_connect, state) do def handle_message(:attempt_to_connect, state) do

View File

@ -11,7 +11,7 @@ defmodule EchoTransfer do
{:ok, caller} {:ok, caller}
end end
def data_received(label, data, caller) do def data_received(label, _metric_type, data, caller) do
send(caller, {label, data}) send(caller, {label, data})
{:ok, caller} {:ok, caller}
end end

View File

@ -13,6 +13,10 @@ defmodule POAAgent.PluginsTest do
{:transfer, "data retrieved", :no_state} {:transfer, "data retrieved", :no_state}
end end
def metric_type do
"my_metric_type"
end
def terminate(_state) do def terminate(_state) do
:ok :ok
end end
@ -23,6 +27,7 @@ defmodule POAAgent.PluginsTest do
assert Collector1.handle_info(:msg, :state) == {:noreply, :state} assert Collector1.handle_info(:msg, :state) == {:noreply, :state}
assert Collector1.handle_cast(:msg, :state) == {:noreply, :state} assert Collector1.handle_cast(:msg, :state) == {:noreply, :state}
assert Collector1.code_change(:old, :state, :extra) == {:ok, :state} assert Collector1.code_change(:old, :state, :extra) == {:ok, :state}
assert Collector1.metric_type() == "my_metric_type"
assert Collector1.terminate(:reason, :state) == :ok assert Collector1.terminate(:reason, :state) == :ok
end end
@ -35,7 +40,7 @@ defmodule POAAgent.PluginsTest do
{:ok, :no_state} {:ok, :no_state}
end end
def data_received(_label, _data, _state) do def data_received(_label, _metric_type, _data, _state) do
{:ok, :no_state} {:ok, :no_state}
end end
@ -70,6 +75,10 @@ defmodule POAAgent.PluginsTest do
{:transfer, data, test_pid} {:transfer, data, test_pid}
end end
def metric_type do
"my_metric_type"
end
def terminate(_state) do def terminate(_state) do
:ok :ok
end end
@ -82,8 +91,8 @@ defmodule POAAgent.PluginsTest do
{:ok, test_pid} {:ok, test_pid}
end end
def data_received(label, data, test_pid) do def data_received(label, metric_type, data, test_pid) do
send test_pid, {:received, self(), label, data} send test_pid, {:received, self(), label, metric_type, data}
{:ok, test_pid} {:ok, test_pid}
end end
@ -102,7 +111,7 @@ defmodule POAAgent.PluginsTest do
{:ok, cpid} = Collector2.start_link(%{name: :collector2, transfers: [transfer1], label: :label, args: self(), frequency: 2_000}) {:ok, cpid} = Collector2.start_link(%{name: :collector2, transfers: [transfer1], label: :label, args: self(), frequency: 2_000})
assert_receive {:sent, ^cpid, "data retrieved"}, 20_000 assert_receive {:sent, ^cpid, "data retrieved"}, 20_000
assert_receive {:received, ^tpid, :label, "data retrieved"}, 20_000 assert_receive {:received, ^tpid, :label, "my_metric_type", "data retrieved"}, 20_000
end end
end end

View File

@ -257,7 +257,7 @@ defmodule POAAgent.Plugins.Collectors.Eth.PrimusTest do
end end
defp send_to_transfer(transfer, label, data) do defp send_to_transfer(transfer, label, data) do
GenServer.cast(transfer, %{label: label, data: data}) GenServer.cast(transfer, %{label: label, metric_type: "my_metric_type", data: data})
end end
defp last_block_message() do defp last_block_message() do

View File

@ -113,7 +113,7 @@ defmodule POAAgent.Transfers.RestTest do
end end
defp send_to_transfer(transfer, label, data) do defp send_to_transfer(transfer, label, data) do
GenServer.cast(transfer, %{label: label, data: data}) GenServer.cast(transfer, %{label: label, metric_type: "my_metric_type", data: data})
end end
defp data_message() do defp data_message() do