| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323 |
- <?php
- function netdataSettngsArray()
- {
- $array = array(
- 'name' => 'Netdata',
- 'enabled' => true,
- 'image' => 'plugins/images/tabs/netdata.png',
- 'category' => 'Monitor',
- 'settings' => array(
- 'Enable' => array(
- array(
- 'type' => 'switch',
- 'name' => 'homepageNetdataEnabled',
- 'label' => 'Enable',
- 'value' => $GLOBALS['homepageNetdataEnabled']
- ),
- array(
- 'type' => 'select',
- 'name' => 'homepageNetdataAuth',
- 'label' => 'Minimum Authentication',
- 'value' => $GLOBALS['homepageNetdataAuth'],
- 'options' => groupSelect()
- )
- ),
- 'Connection' => array(
- array(
- 'type' => 'html',
- 'override' => 12,
- 'label' => 'Info',
- 'html' => 'The URL needs to be on the same domain as your Organizr, and be proxied by subdomain. E.g. If Organizr is accessed at: https://domain.com, then your URL for netdata should be: https://netdata.domain.com'
- ),
- array(
- 'type' => 'input',
- 'name' => 'netdataURL',
- 'label' => 'URL',
- 'value' => $GLOBALS['netdataURL'],
- 'help' => 'Please enter the local IP:PORT of your netdata instance'
- ),
- array(
- 'type' => 'blank',
- 'label' => ''
- ),
- ),
- )
- );
- for($i = 1; $i <= 7; $i++) {
- $array['settings']['Chart '.$i] = array(
- array(
- 'type' => 'switch',
- 'name' => 'netdata'.$i.'Enabled',
- 'label' => 'Enable',
- 'value' => $GLOBALS['netdata'.$i.'Enabled']
- ),
- array(
- 'type' => 'blank',
- 'label' => ''
- ),
- array(
- 'type' => 'input',
- 'name' => 'netdata'.$i.'Title',
- 'label' => 'Title',
- 'value' => $GLOBALS['netdata'.$i.'Title'],
- 'help' => 'Title for the netdata graph'
- ),
- array(
- 'type' => 'select',
- 'name' => 'netdata'.$i.'Data',
- 'label' => 'Data',
- 'value' => $GLOBALS['netdata'.$i.'Data'],
- 'options' => netdataOptions(),
- ),
- array(
- 'type' => 'select',
- 'name' => 'netdata'.$i.'Chart',
- 'label' => 'Chart',
- 'value' => $GLOBALS['netdata'.$i.'Chart'],
- 'options' => netdataChartOptions(),
- ),
- array(
- 'type' => 'select',
- 'name' => 'netdata'.$i.'Colour',
- 'label' => 'Colour',
- 'value' => $GLOBALS['netdata'.$i.'Colour'],
- 'options' => netdataColourOptions(),
- ),
- array(
- 'type' => 'select',
- 'name' => 'netdata'.$i.'Size',
- 'label' => 'Size',
- 'value' => $GLOBALS['netdata'.$i.'Size'],
- 'options' => netdataSizeOptions(),
- ),
- array(
- 'type' => 'blank',
- 'label' => ''
- ),
- array(
- 'type' => 'switch',
- 'name' => 'netdata'.$i.'lg',
- 'label' => 'Show on large screens',
- 'value' => $GLOBALS['netdata'.$i.'lg']
- ),
- array(
- 'type' => 'switch',
- 'name' => 'netdata'.$i.'md',
- 'label' => 'Show on medium screens',
- 'value' => $GLOBALS['netdata'.$i.'md']
- ),
- array(
- 'type' => 'switch',
- 'name' => 'netdata'.$i.'sm',
- 'label' => 'Show on small screens',
- 'value' => $GLOBALS['netdata'.$i.'sm']
- ),
- );
- }
- $array['settings']['Options'] = array(
- array(
- 'type' => 'select',
- 'name' => 'homepageNetdataRefresh',
- 'label' => 'Refresh Seconds',
- 'value' => $GLOBALS['homepageNetdataRefresh'],
- 'options' => optionTime()
- ),
- );
- return $array;
- }
- function disk($dimension, $url)
- {
- $data = [];
- // Get Data
- $dataUrl = $url . '/api/v1/data?chart=system.io&dimensions='.$dimension.'&format=array&points=540&group=average>ime=0&options=absolute|jsonwrap|nonzero&after=-540';
- try {
- $response = Requests::get($dataUrl);
- if ($response->success) {
- $json = json_decode($response->body, true);
- $data['value'] = $json['latest_values'][0] / 1000;
- $data['percent'] = getPercent($json['latest_values'][0], $json['max']);
- $data['units'] = 'MiB/s';
- $data['max'] = $json['max'];
- }
- } catch (Requests_Exception $e) {
- writeLog('error', 'Netdata Connect Function - Error: ' . $e->getMessage(), 'SYSTEM');
- };
- return $data;
- }
- function diskSpace($dimension, $url)
- {
- $data = [];
- // Get Data
- $dataUrl = $url . '/api/v1/data?chart=disk_space._&format=json&points=509&group=average>ime=0&options=ms|jsonwrap|nonzero&after=-540&dimension='.$dimension;
- try {
- $response = Requests::get($dataUrl);
- if ($response->success) {
- $json = json_decode($response->body, true);
- $data['value'] = $json['result']['data'][0][1];
- $data['percent'] = $data['value'];
- $data['units'] = '%';
- $data['max'] = 100;
- }
- } catch (Requests_Exception $e) {
- writeLog('error', 'Netdata Connect Function - Error: ' . $e->getMessage(), 'SYSTEM');
- };
- return $data;
- }
- function net($dimension, $url)
- {
- $data = [];
- // Get Data
- $dataUrl = $url . '/api/v1/data?chart=system.net&dimensions='.$dimension.'&format=array&points=540&group=average>ime=0&options=absolute|jsonwrap|nonzero&after=-540';
- try {
- $response = Requests::get($dataUrl);
- if ($response->success) {
- $json = json_decode($response->body, true);
- $data['value'] = $json['latest_values'][0] / 1000;
- $data['percent'] = getPercent($json['latest_values'][0], $json['max']);
- $data['units'] = 'Mbit/s';
- $data['max'] = $json['max'];
- }
- } catch (Requests_Exception $e) {
- writeLog('error', 'Netdata Connect Function - Error: ' . $e->getMessage(), 'SYSTEM');
- };
- return $data;
- }
- function cpu($url)
- {
- $data = [];
- $dataUrl = $url . '/api/v1/data?chart=system.cpu&format=array';
- try {
- $response = Requests::get($dataUrl);
- if ($response->success) {
- $json = json_decode($response->body, true);
- $data['value'] = $json[0];
- $data['percent'] = $data['value'];
- $data['max'] = 100;
- $data['units'] = '%';
- }
- } catch (Requests_Exception $e) {
- writeLog('error', 'Netdata Connect Function - Error: ' . $e->getMessage(), 'SYSTEM');
- };
- return $data;
- }
- function ram($url)
- {
- $data = [];
- $dataUrl = $url . '/api/v1/data?chart=system.ram&format=array&points=540&group=average>ime=0&options=absolute|percentage|jsonwrap|nonzero&after=-540&dimensions=used|buffers|active|wired';
- try {
- $response = Requests::get($dataUrl);
- if ($response->success) {
- $json = json_decode($response->body, true);
- $data['value'] = $json['result'][0];
- $data['percent'] = $data['value'];
- $data['max'] = 100;
- $data['units'] = '%';
- }
- } catch (Requests_Exception $e) {
- writeLog('error', 'Netdata Connect Function - Error: ' . $e->getMessage(), 'SYSTEM');
- };
- return $data;
- }
- function swap($url)
- {
- $data = [];
- $dataUrl = $url . '/api/v1/data?chart=system.swap&format=array&points=540&group=average>ime=0&options=absolute|percentage|jsonwrap|nonzero&after=-540&dimensions=used';
- try {
- $response = Requests::get($dataUrl);
- if ($response->success) {
- $json = json_decode($response->body, true);
- $data['value'] = $json['result'][0];
- $data['percent'] = $data['value'];
- $data['max'] = 100;
- $data['units'] = '%';
- }
- } catch (Requests_Exception $e) {
- writeLog('error', 'Netdata Connect Function - Error: ' . $e->getMessage(), 'SYSTEM');
- };
- return $data;
- }
- function ipmiTemp($url, $unit)
- {
- $data = [];
- $dataUrl = $url . '/api/v1/data?chart=ipmi.temperatures_c&format=array&points=540&group=average>ime=0&options=absolute|jsonwrap|nonzero&after=-540';
- try {
- $response = Requests::get($dataUrl);
- if ($response->success) {
- $json = json_decode($response->body, true);
- $data['value'] = $json['result'][0];
- if($unit == 'c') {
- $data['percent'] = ($data['value'] / 50) * 100;
- $data['max'] = 50;
- } else if($unit == 'f') {
- $data['value'] = ($data['value'] * 9/5) + 32;
- $data['percent'] = ($data['value'] / 122) * 100;
- $data['max'] = 122;
- }
- $data['units'] = '°'.strtoupper($unit);
- }
- } catch (Requests_Exception $e) {
- writeLog('error', 'Netdata Connect Function - Error: ' . $e->getMessage(), 'SYSTEM');
- };
- return $data;
- }
- function getPercent($val, $max)
- {
- if($max == 0) {
- return 0;
- } else {
- return ( $val / $max ) * 100;
- }
- }
- function cpuTemp($url, $unit)
- {
- $data = [];
- $dataUrl = $url . '/api/v1/data?chart=sensors.coretemp-isa-0000_temperature&format=json&points=509&group=average>ime=0&options=ms|flip|jsonwrap|nonzero&after=-540';
- try {
- $response = Requests::get($dataUrl);
- if ($response->success) {
- $json = json_decode($response->body, true);
- $vals = $json['latest_values'];
- $vals = array_filter($vals);
- if(count($vals) > 0) {
- $data['value'] = array_sum($vals) / count($vals);
- } else {
- $data['value'] = 0;
- }
-
- if($unit == 'c') {
- $data['percent'] = ($data['value'] / 50) * 100;
- $data['max'] = 50;
- } else if($unit == 'f') {
- $data['value'] = ($data['value'] * 9/5) + 32;
- $data['percent'] = ($data['value'] / 122) * 100;
- $data['max'] = 122;
- }
- $data['units'] = '°'.strtoupper($unit);
- }
- } catch (Requests_Exception $e) {
- writeLog('error', 'Netdata Connect Function - Error: ' . $e->getMessage(), 'SYSTEM');
- };
- return $data;
- }
|