Skip to content

Commit

Permalink
Merge pull request #75 from poanetwork/ferigis.74.dynamic_metric_types
Browse files Browse the repository at this point in the history
[#74] Collectors decide the metric type
  • Loading branch information
Dzol committed Aug 23, 2018
2 parents 1d0a518 + f0dcc03 commit 07527e8
Show file tree
Hide file tree
Showing 31 changed files with 161 additions and 74 deletions.
8 changes: 0 additions & 8 deletions .circleci/config.yml
Expand Up @@ -16,15 +16,7 @@ jobs:
- run: mix deps.get
- run: mix test
- run: mix credo
- restore_cache:
keys:
- dialyzer-PLT-cache-{{ checksum "mix.exs" }}
- dialyzer-PLT-cache
- 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.json
- run: bash <(curl -s https://codecov.io/bash)
2 changes: 1 addition & 1 deletion doc/.build
Expand Up @@ -4,7 +4,7 @@ fonts/icomoon.eot
fonts/icomoon.svg
fonts/icomoon.ttf
fonts/icomoon.woff
dist/sidebar_items-303975f305.js
dist/sidebar_items-75149ca71e.js
api-reference.html
initial_architecture.html
starting_guide.html
Expand Down
2 changes: 1 addition & 1 deletion doc/404.html
Expand Up @@ -8,7 +8,7 @@
<title>404 – poa_agent v0.1.0</title>
<link rel="stylesheet" href="dist/app-480ffdc169.css" />

<script src="dist/sidebar_items-303975f305.js"></script>
<script src="dist/sidebar_items-75149ca71e.js"></script>



Expand Down
2 changes: 1 addition & 1 deletion doc/POAAgent.Application.html
Expand Up @@ -8,7 +8,7 @@
<title>POAAgent.Application – poa_agent v0.1.0</title>
<link rel="stylesheet" href="dist/app-480ffdc169.css" />

<script src="dist/sidebar_items-303975f305.js"></script>
<script src="dist/sidebar_items-75149ca71e.js"></script>



Expand Down
2 changes: 1 addition & 1 deletion doc/POAAgent.Entity.NameConvention.html
Expand Up @@ -8,7 +8,7 @@
<title>POAAgent.Entity.NameConvention – poa_agent v0.1.0</title>
<link rel="stylesheet" href="dist/app-480ffdc169.css" />

<script src="dist/sidebar_items-303975f305.js"></script>
<script src="dist/sidebar_items-75149ca71e.js"></script>



Expand Down
2 changes: 1 addition & 1 deletion doc/POAAgent.Format.POAProtocol.Data.Format.html
Expand Up @@ -8,7 +8,7 @@
<title>POAAgent.Format.POAProtocol.Data.Format – poa_agent v0.1.0</title>
<link rel="stylesheet" href="dist/app-480ffdc169.css" />

<script src="dist/sidebar_items-303975f305.js"></script>
<script src="dist/sidebar_items-75149ca71e.js"></script>



Expand Down
56 changes: 51 additions & 5 deletions doc/POAAgent.Plugins.Collector.html
Expand Up @@ -8,7 +8,7 @@
<title>POAAgent.Plugins.Collector – poa_agent v0.1.0</title>
<link rel="stylesheet" href="dist/app-480ffdc169.css" />

<script src="dist/sidebar_items-303975f305.js"></script>
<script src="dist/sidebar_items-75149ca71e.js"></script>



Expand Down Expand Up @@ -129,13 +129,15 @@ <h2 id="module-implementing-a-collector-plugin" class="section-heading">
Implementing A Collector Plugin
</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>
<li><code class="inline">init_collector/1</code>: Called only once when the process starts
</li>
<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
</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>
</ul>
Expand All @@ -152,6 +154,10 @@ <h2 id="module-implementing-a-collector-plugin" class="section-heading">
{:transfer, &quot;data retrieved&quot;, :no_state}
end

def metric_type do
&quot;my_metrics_type&quot;
end

def terminate(_state) do
:ok
end
Expand Down Expand Up @@ -205,6 +211,16 @@ <h2>
metrics we want to send to the transfer</p>
</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 class="summary-row">
<div class="summary-signature">
Expand Down Expand Up @@ -245,7 +261,7 @@ <h1 class="section-heading">
</a>
<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="sr-only">View Source</span>
</a>
Expand Down Expand Up @@ -278,7 +294,7 @@ <h1 class="section-heading">
</a>
<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="sr-only">View Source</span>
</a>
Expand All @@ -304,6 +320,36 @@ <h1 class="section-heading">

</section>
</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">


Expand All @@ -314,7 +360,7 @@ <h1 class="section-heading">
</a>
<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="sr-only">View Source</span>
</a>
Expand Down
2 changes: 1 addition & 1 deletion doc/POAAgent.Plugins.Collectors.Eth.Information.html
Expand Up @@ -8,7 +8,7 @@
<title>POAAgent.Plugins.Collectors.Eth.Information – poa_agent v0.1.0</title>
<link rel="stylesheet" href="dist/app-480ffdc169.css" />

<script src="dist/sidebar_items-303975f305.js"></script>
<script src="dist/sidebar_items-75149ca71e.js"></script>



Expand Down
2 changes: 1 addition & 1 deletion doc/POAAgent.Plugins.Collectors.Eth.LatestBlock.html
Expand Up @@ -8,7 +8,7 @@
<title>POAAgent.Plugins.Collectors.Eth.LatestBlock – poa_agent v0.1.0</title>
<link rel="stylesheet" href="dist/app-480ffdc169.css" />

<script src="dist/sidebar_items-303975f305.js"></script>
<script src="dist/sidebar_items-75149ca71e.js"></script>



Expand Down
2 changes: 1 addition & 1 deletion doc/POAAgent.Plugins.Collectors.Eth.Pending.html
Expand Up @@ -8,7 +8,7 @@
<title>POAAgent.Plugins.Collectors.Eth.Pending – poa_agent v0.1.0</title>
<link rel="stylesheet" href="dist/app-480ffdc169.css" />

<script src="dist/sidebar_items-303975f305.js"></script>
<script src="dist/sidebar_items-75149ca71e.js"></script>



Expand Down
2 changes: 1 addition & 1 deletion doc/POAAgent.Plugins.Collectors.Eth.Stats.html
Expand Up @@ -8,7 +8,7 @@
<title>POAAgent.Plugins.Collectors.Eth.Stats – poa_agent v0.1.0</title>
<link rel="stylesheet" href="dist/app-480ffdc169.css" />

<script src="dist/sidebar_items-303975f305.js"></script>
<script src="dist/sidebar_items-75149ca71e.js"></script>



Expand Down
25 changes: 15 additions & 10 deletions doc/POAAgent.Plugins.Transfer.html
Expand Up @@ -8,7 +8,7 @@
<title>POAAgent.Plugins.Transfer – poa_agent v0.1.0</title>
<link rel="stylesheet" href="dist/app-480ffdc169.css" />

<script src="dist/sidebar_items-303975f305.js"></script>
<script src="dist/sidebar_items-75149ca71e.js"></script>



Expand Down Expand Up @@ -115,7 +115,7 @@ <h2 id="module-implementing-a-transfer-plugin" class="section-heading">
<ul>
<li><code class="inline">init_transfer/1</code>: Called only once when the process starts
</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><code class="inline">handle_message/1</code>: This is called when the transfer process receives an Erlang message
</li>
Expand All @@ -130,7 +130,7 @@ <h2 id="module-implementing-a-transfer-plugin" class="section-heading">
{:ok, :no_state}
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;
{:ok, :no_state}
end
Expand Down Expand Up @@ -168,7 +168,7 @@ <h2>
</h2>
<div class="summary-row">
<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 class="summary-synopsis"><p>In this callback is called when a Collector sends data to this Transfer</p>
Expand Down Expand Up @@ -225,15 +225,15 @@ <h1 class="section-heading">
</a>
Callbacks
</h1>
<div class="detail" id="c:data_received/3">
<div class="detail" id="c:data_received/4">


<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="sr-only">Link to this callback</span>
</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">
<span class="icon-code" aria-hidden="true"></span>
Expand All @@ -244,15 +244,20 @@ <h1 class="section-heading">

<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>
<section class="docstring">
<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
data is the real data received.</p>
<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
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 Collector’s state</p>
<p> It must return <code class="inline">{:ok, state}</code>.</p>

</section>
Expand Down
16 changes: 8 additions & 8 deletions doc/POAAgent.Plugins.Transfers.WebSocket.Primus.html
Expand Up @@ -8,7 +8,7 @@
<title>POAAgent.Plugins.Transfers.WebSocket.Primus – poa_agent v0.1.0</title>
<link rel="stylesheet" href="dist/app-480ffdc169.css" />

<script src="dist/sidebar_items-303975f305.js"></script>
<script src="dist/sidebar_items-75149ca71e.js"></script>



Expand Down Expand Up @@ -99,7 +99,7 @@ <h2>
</h2>
<div class="summary-row">
<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 class="summary-synopsis"><p>In this callback is called when a Collector sends data to this Transfer</p>
Expand Down Expand Up @@ -156,15 +156,15 @@ <h1 class="section-heading">
</a>
Functions
</h1>
<div class="detail" id="data_received/3">
<div class="detail" id="data_received/4">


<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="sr-only">Link to this function</span>
</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">
<span class="icon-code" aria-hidden="true"></span>
Expand All @@ -176,10 +176,10 @@ <h1 class="section-heading">
</div>
<section class="docstring">
<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
data is the real data received.</p>
<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
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 Collector’s state</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>
</div>
Expand Down
2 changes: 1 addition & 1 deletion doc/POAAgent.html
Expand Up @@ -8,7 +8,7 @@
<title>POAAgent – poa_agent v0.1.0</title>
<link rel="stylesheet" href="dist/app-480ffdc169.css" />

<script src="dist/sidebar_items-303975f305.js"></script>
<script src="dist/sidebar_items-75149ca71e.js"></script>



Expand Down
2 changes: 1 addition & 1 deletion doc/api-reference.html
Expand Up @@ -8,7 +8,7 @@
<title>API Reference – poa_agent v0.1.0</title>
<link rel="stylesheet" href="dist/app-480ffdc169.css" />

<script src="dist/sidebar_items-303975f305.js"></script>
<script src="dist/sidebar_items-75149ca71e.js"></script>



Expand Down

0 comments on commit 07527e8

Please sign in to comment.