summaryrefslogtreecommitdiff
path: root/roles/install_monitoring/templates/ffmyk-influx/traffic.php.j2
blob: 78220da94ee8572382e203b31f0a0ce1893d672a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
<?php

require('func.php');

function traffic($iface, $alias=false) {

    if(!$alias) $alias = $iface;

    $rx = file_get_contents('/sys/class/net/'.$iface.'/statistics/rx_bytes');
    $tx = file_get_contents('/sys/class/net/'.$iface.'/statistics/tx_bytes');

    $data = 'rx,if='.$alias.',host={{ ansible_hostname }},type=backend value='.$rx."\n";
    $data.= 'tx,if='.$alias.',host={{ ansible_hostname }},type=backend value='.$tx;

    sendflux($data);
}

(traffic('{{ ansible_default_ipv4.interface }}', 'wan'));
{% if ansible_default_ipv4.interface != ansible_default_ipv6.interface %}
(traffic('{{ ansible_default_ipv6.interface }}', 'wan6'));
{% endif %}
{% for site in sites %}
(traffic('bat{{ site.name }}'));
(traffic('wg{{ site.name }}'));
{% endfor %}

?>