mirror of
https://github.com/lucaspalomodevelop/core.git
synced 2026-03-13 08:09:41 +00:00
reporting: style sweep
This commit is contained in:
parent
895e58ff25
commit
ecf987820d
@ -28,10 +28,11 @@
|
||||
|
||||
namespace OPNsense\RRD;
|
||||
|
||||
|
||||
use ReflectionClass;
|
||||
|
||||
class TypeNotFound extends \Exception { }
|
||||
class TypeNotFound extends \Exception
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* RRD Factory class, offers access to RRD types and statistics.
|
||||
@ -52,7 +53,7 @@ class Factory
|
||||
public function get(string $type, string $target)
|
||||
{
|
||||
try {
|
||||
$cls = new ReflectionClass('\\OPNsense\\RRD\\Types\\'. $type);
|
||||
$cls = new ReflectionClass('\\OPNsense\\RRD\\Types\\' . $type);
|
||||
if (!$cls->isInstantiable() || !$cls->isSubclassOf('OPNsense\\RRD\\Types\\Base')) {
|
||||
throw new TypeNotFound(sprintf("%s not found", $type));
|
||||
}
|
||||
@ -71,8 +72,8 @@ class Factory
|
||||
{
|
||||
$this->stats = [];
|
||||
foreach (glob(sprintf("%s/Stats/*.php", __DIR__)) as $filename) {
|
||||
$classname = substr(basename($filename),0, -4);
|
||||
$cls = new ReflectionClass('\\OPNsense\\RRD\\Stats\\'. $classname);
|
||||
$classname = substr(basename($filename), 0, -4);
|
||||
$cls = new ReflectionClass('\\OPNsense\\RRD\\Stats\\' . $classname);
|
||||
if ($cls->isInstantiable() && $cls->isSubclassOf('OPNsense\\RRD\\Stats\\Base')) {
|
||||
try {
|
||||
$start_time = microtime(true);
|
||||
@ -82,7 +83,7 @@ class Factory
|
||||
'data' => $tmp,
|
||||
'runtime' => microtime(true) - $start_time
|
||||
];
|
||||
} catch (\Error | \Exception $e) {
|
||||
} catch (\Error | \Exception $e) {
|
||||
echo $e;
|
||||
syslog(LOG_ERR, sprintf("Error collecting %s [%s]", $classname, $e));
|
||||
}
|
||||
@ -113,11 +114,11 @@ class Factory
|
||||
* update all registered RRD graphs
|
||||
* @return $this
|
||||
*/
|
||||
public function updateAll($debug=false)
|
||||
public function updateAll($debug = false)
|
||||
{
|
||||
foreach (glob(sprintf("%s/Types/*.php", __DIR__)) as $filename) {
|
||||
$classname = substr(basename($filename),0, -4);
|
||||
$fclassname = '\\OPNsense\\RRD\\Types\\'. $classname;
|
||||
$classname = substr(basename($filename), 0, -4);
|
||||
$fclassname = '\\OPNsense\\RRD\\Types\\' . $classname;
|
||||
try {
|
||||
$cls = new ReflectionClass($fclassname);
|
||||
if ($cls->isInstantiable() && $cls->isSubclassOf('OPNsense\\RRD\\Types\\Base')) {
|
||||
@ -142,7 +143,6 @@ class Factory
|
||||
$obj->create(); /* only creates when no target exists yet */
|
||||
$obj->update($data, $debug);
|
||||
}
|
||||
|
||||
}
|
||||
} catch (\Error | \Exception $e) {
|
||||
echo $e;
|
||||
@ -151,4 +151,4 @@ class Factory
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -102,4 +102,4 @@ abstract class Base
|
||||
{
|
||||
throw new \Exception("Need to implement run()");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -44,4 +44,4 @@ class Interfaces extends Base
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -49,6 +49,3 @@ class Mbuf extends Base
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@ -58,6 +58,3 @@ class Memory extends Base
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@ -58,6 +58,3 @@ class Ntp extends Base
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@ -51,6 +51,3 @@ class OpenVPN extends Base
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@ -41,12 +41,9 @@ class Processor extends Base
|
||||
'nice' => $tmp[1],
|
||||
'system' => $tmp[2],
|
||||
'interrupt' => $tmp[3],
|
||||
'processes' => count($ps)-1
|
||||
'processes' => count($ps) - 1
|
||||
];
|
||||
}
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@ -39,6 +39,3 @@ class States extends Base
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@ -41,9 +41,3 @@ class Temperature extends Base
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@ -103,10 +103,10 @@ abstract class Base
|
||||
public function addDataset(
|
||||
string $name,
|
||||
string $opp,
|
||||
?int $heartbeat=null,
|
||||
?int $min=null,
|
||||
?int $max=null
|
||||
){
|
||||
?int $heartbeat = null,
|
||||
?int $min = null,
|
||||
?int $max = null
|
||||
) {
|
||||
$this->datasets[] = [
|
||||
$name,
|
||||
$opp,
|
||||
@ -128,12 +128,12 @@ abstract class Base
|
||||
public function addDatasets(
|
||||
array $names,
|
||||
string $opp,
|
||||
?int $heartbeat=null,
|
||||
?int $min=null,
|
||||
?int $max=null
|
||||
){
|
||||
?int $heartbeat = null,
|
||||
?int $min = null,
|
||||
?int $max = null
|
||||
) {
|
||||
foreach ($names as $name) {
|
||||
$this->addDataset($name, $opp, $heartbeat, $min, $max);
|
||||
$this->addDataset($name, $opp, $heartbeat, $min, $max);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
@ -143,7 +143,7 @@ abstract class Base
|
||||
* @param bool $overwrite overwrite when file exists
|
||||
* @return $this
|
||||
*/
|
||||
public function create($overwrite=false)
|
||||
public function create($overwrite = false)
|
||||
{
|
||||
if (!$overwrite && file_exists($this->filename)) {
|
||||
return $this;
|
||||
@ -152,8 +152,7 @@ abstract class Base
|
||||
foreach ($this->datasets as $dataset) {
|
||||
$cmd_text .= 'DS:' . implode(':', $dataset) . ' ';
|
||||
}
|
||||
foreach ($this->round_robin_archives as $rra)
|
||||
{
|
||||
foreach ($this->round_robin_archives as $rra) {
|
||||
$cmd_text .= 'RRA:' . implode(':', $rra) . ' ';
|
||||
}
|
||||
$cmd_text .= ' 2>&1';
|
||||
@ -174,7 +173,7 @@ abstract class Base
|
||||
* @param bool $debug throw debug messages to stdout
|
||||
* @return $this
|
||||
*/
|
||||
public function update(array $dataset = [], bool $debug=false)
|
||||
public function update(array $dataset = [], bool $debug = false)
|
||||
{
|
||||
$values = [];
|
||||
$map_by_name = count($dataset) > 0 && !isset($dataset[0]);
|
||||
@ -205,4 +204,4 @@ abstract class Base
|
||||
$tmp = explode('\\', static::class);
|
||||
return array_pop($tmp);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -56,4 +56,4 @@ class GatewayQuality extends Base
|
||||
yield static::$basedir . sprintf(static::$stdfilename, $gw) => $data;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -60,4 +60,4 @@ class Mbuf extends Base
|
||||
['MAX', 0.5, 1440, 2284],
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -60,4 +60,4 @@ class Memory extends Base
|
||||
['MAX', 0.5, 1440, 2284],
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -61,4 +61,4 @@ class Ntp extends Base
|
||||
['MAX', 0.5, 1440, 2284],
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -57,4 +57,4 @@ class OpenVPN extends Base
|
||||
yield static::$basedir . sprintf(static::$stdfilename, $intf) => $data;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -77,4 +77,4 @@ class Packets extends Base
|
||||
yield static::$basedir . sprintf(static::$stdfilename, $intf) => $tmp;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -46,4 +46,4 @@ class Processor extends Base
|
||||
parent::__construct($filename);
|
||||
$this->addDatasets(['user', 'nice', 'system', 'interrupt', 'processes'], 'GAUGE');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -46,4 +46,4 @@ class States extends Base
|
||||
parent::__construct($filename);
|
||||
$this->addDatasets(['pfrate', 'pfstates', 'pfnat', 'srcip', 'dstip'], 'GAUGE');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -63,4 +63,4 @@ class Temperature extends Base
|
||||
['LAST', 0.5, 1440, 2284],
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -77,4 +77,4 @@ class Traffic extends Base
|
||||
yield static::$basedir . sprintf(static::$stdfilename, $intf) => $tmp;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -45,4 +45,4 @@ class Wireless extends Base
|
||||
parent::__construct($filename);
|
||||
$this->addDatasets(['snr','rate','channel'], 'GAUGE');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -53,7 +53,7 @@ if ($rrdcnf === null || !isset($rrdcnf->enable)) {
|
||||
exit(0);
|
||||
}
|
||||
|
||||
$start_time = microtime(True);
|
||||
$start_time = microtime(true);
|
||||
|
||||
if (!is_dir('/var/db/rrd')) {
|
||||
@mkdir('/var/db/rrd', 0775);
|
||||
@ -65,7 +65,7 @@ $rrd_factory->collect()->updateAll(isset($opts['d']));
|
||||
|
||||
if (isset($opts['d'])) {
|
||||
$collect_time = 0.0;
|
||||
echo sprintf("total runtime [seconds] \t: %0.2f\n", microtime(True) - $start_time);
|
||||
echo sprintf("total runtime [seconds] \t: %0.2f\n", microtime(true) - $start_time);
|
||||
foreach ($rrd_factory->getRawStats() as $name => $payload) {
|
||||
$collect_time += $payload['runtime'];
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user