From eade06a930c16f5cb08edd454d9e41364edf8103 Mon Sep 17 00:00:00 2001 From: Niklas Yann Wettengel Date: Mon, 20 Mar 2017 20:56:39 +0100 Subject: install_monitoring: added ffmyk-influx --- .../templates/ffmyk-influx/dhcp.php.j2 | 23 ++++++++++ .../templates/ffmyk-influx/fastd.php.j2 | 35 ++++++++++++++ .../templates/ffmyk-influx/func.php.j2 | 17 +++++++ .../templates/ffmyk-influx/traffic.php.j2 | 53 ++++++++++++++++++++++ 4 files changed, 128 insertions(+) create mode 100644 roles/install_monitoring/templates/ffmyk-influx/dhcp.php.j2 create mode 100644 roles/install_monitoring/templates/ffmyk-influx/fastd.php.j2 create mode 100644 roles/install_monitoring/templates/ffmyk-influx/func.php.j2 create mode 100644 roles/install_monitoring/templates/ffmyk-influx/traffic.php.j2 (limited to 'roles/install_monitoring/templates/ffmyk-influx') diff --git a/roles/install_monitoring/templates/ffmyk-influx/dhcp.php.j2 b/roles/install_monitoring/templates/ffmyk-influx/dhcp.php.j2 new file mode 100644 index 0000000..66371ef --- /dev/null +++ b/roles/install_monitoring/templates/ffmyk-influx/dhcp.php.j2 @@ -0,0 +1,23 @@ + $dend) $clients++; + } + + $data = 'clients,host={{ ansible_hostname }},type=backend value='.$clients; + sendflux($data); + +?> diff --git a/roles/install_monitoring/templates/ffmyk-influx/fastd.php.j2 b/roles/install_monitoring/templates/ffmyk-influx/fastd.php.j2 new file mode 100644 index 0000000..985d7d3 --- /dev/null +++ b/roles/install_monitoring/templates/ffmyk-influx/fastd.php.j2 @@ -0,0 +1,35 @@ +peers as $peer) { + if($peer->connection != NULL) $peers++; + } + + return $peers; +} + +$fastd_1280 = fastdGetPeers('/run/ffmyk.socket'); + +$data = 'fastdclient,mtu=1280,host={{ ansible_hostname }},type=backend value='.$fastd_1280."\n"; + +sendflux($data); + +?> diff --git a/roles/install_monitoring/templates/ffmyk-influx/func.php.j2 b/roles/install_monitoring/templates/ffmyk-influx/func.php.j2 new file mode 100644 index 0000000..fd2c248 --- /dev/null +++ b/roles/install_monitoring/templates/ffmyk-influx/func.php.j2 @@ -0,0 +1,17 @@ + array( + 'header' => "Authorization: Basic " . base64_encode("{{ influx_user }}:{{ influx_password }}") ."\r\nContent-type: application/x-www-form-urlencoded\r\n", + 'method' => 'POST', + 'content' => $data, + ), + ); + + $context = stream_context_create($options); + $result = file_get_contents($url, false, $context); +} + +?> diff --git a/roles/install_monitoring/templates/ffmyk-influx/traffic.php.j2 b/roles/install_monitoring/templates/ffmyk-influx/traffic.php.j2 new file mode 100644 index 0000000..82674b9 --- /dev/null +++ b/roles/install_monitoring/templates/ffmyk-influx/traffic.php.j2 @@ -0,0 +1,53 @@ + $cache['rx']) $out['rx'] = ($rx - $cache['rx']) / $diff; + if($tx > $cache['tx']) $out['tx'] = ($tx - $cache['tx']) / $diff; + } + + file_put_contents($file, serialize(array("rx" => $rx, "tx" => $tx))); + + $data = 'rx,if='.$alias.',host={{ ansible_hostname }},type=backend value='.$out['rx']."\n"; + $data.= 'tx,if='.$alias.',host={{ ansible_hostname }},type=backend value='.$out['tx']; + + sendflux($data); + + $out['if'] = $iface; + + return $out; + } + + (traffic('ens3', 'eth0')); + (traffic('mullvad')); + (traffic('bat0')); + (traffic('ffmyk-mesh-vpn', 'ffmyk-mesh-vpnd')); + + +?> -- cgit v1.2.3-54-g00ecf