summaryrefslogtreecommitdiff
path: root/roles/install_monitoring/templates/ffmyk-influx/traffic.php.j2
blob: dde5dba3ba22f5144f3fe8021f094f9d7b5fdd1a (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
28
29
30
31
<?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('vpn{{ site.name }}'));
(traffic('wg{{ site.name }}'));
{% endfor %}
{% for uplink in groups['uplink'] %}
(traffic('bb{{ hostvars[uplink]['wireguard_bb_name'] }}'));
{% endfor %}

?>