mirror of https://github.com/MISP/MISP
chg: [cli] Show stats for access logs
parent
b3afa724f9
commit
50428e5c0b
|
@ -3,23 +3,27 @@
|
|||
/**
|
||||
* @property Log $Log
|
||||
* @property AuditLog $AuditLog
|
||||
* @property AccessLog $AccessLog
|
||||
* @property Server $Server
|
||||
*/
|
||||
class LogShell extends AppShell
|
||||
{
|
||||
public $uses = ['Log', 'AuditLog', 'Server'];
|
||||
public $uses = ['Log', 'AuditLog', 'AccessLog', 'Server'];
|
||||
|
||||
public function getOptionParser()
|
||||
{
|
||||
$parser = parent::getOptionParser();
|
||||
$parser->addSubcommand('auditStatistics', [
|
||||
'help' => __('Show statistics from audit logs.'),
|
||||
'help' => __('Show statistics for audit logs.'),
|
||||
]);
|
||||
$parser->addSubcommand('accessStatistics', [
|
||||
'help' => __('Show statistics for access logs.'),
|
||||
]);
|
||||
$parser->addSubcommand('statistics', [
|
||||
'help' => __('Show statistics from logs.'),
|
||||
'help' => __('Show statistics for application logs.'),
|
||||
]);
|
||||
$parser->addSubcommand('export', [
|
||||
'help' => __('Export logs to compressed file in JSON Lines format (one JSON encoded line per entry).'),
|
||||
'help' => __('Export application logs to compressed file in JSON Lines format (one JSON encoded line per entry).'),
|
||||
'parser' => array(
|
||||
'arguments' => array(
|
||||
'file' => ['help' => __('Path to output file'), 'required' => true],
|
||||
|
@ -77,7 +81,7 @@ class LogShell extends AppShell
|
|||
if ($log['id'] > $lastId) {
|
||||
$lastId = $log['id'];
|
||||
}
|
||||
$lines .= json_encode($log, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_THROW_ON_ERROR) . "\n";
|
||||
$lines .= JsonTool::encode($log) . "\n";
|
||||
}
|
||||
if (gzwrite($file, $lines) === false) {
|
||||
$this->error("Could not write data to $path");
|
||||
|
@ -147,4 +151,28 @@ class LogShell extends AppShell
|
|||
$this->out(str_pad(__('Uncompressed size:'), 20) . CakeNumber::toReadableSize($this->AuditLog->compressionStats['bytes_uncompressed']));
|
||||
$this->out(str_pad(__('Compressed size:'), 20) . CakeNumber::toReadableSize($this->AuditLog->compressionStats['bytes_compressed']));
|
||||
}
|
||||
|
||||
public function accessStatistics()
|
||||
{
|
||||
$count = $this->AccessLog->find('count');
|
||||
$first = $this->AccessLog->find('first', [
|
||||
'recursive' => -1,
|
||||
'fields' => ['created'],
|
||||
'order' => ['id ASC'],
|
||||
]);
|
||||
$last = $this->AccessLog->find('first', [
|
||||
'recursive' => -1,
|
||||
'fields' => ['created'],
|
||||
'order' => ['id DESC'],
|
||||
]);
|
||||
|
||||
$this->out(str_pad(__('Count:'), 20) . $count);
|
||||
$this->out(str_pad(__('First:'), 20) . $first['AccessLog']['created']);
|
||||
$this->out(str_pad(__('Last:'), 20) . $last['AccessLog']['created']);
|
||||
|
||||
$usage = $this->Server->dbSpaceUsage()['access_logs'];
|
||||
$this->out(str_pad(__('Data size:'), 20) . CakeNumber::toReadableSize($usage['data_in_bytes']));
|
||||
$this->out(str_pad(__('Index size:'), 20) . CakeNumber::toReadableSize($usage['index_in_bytes']));
|
||||
$this->out(str_pad(__('Reclaimable size:'), 20) . CakeNumber::toReadableSize($usage['reclaimable_in_bytes']), 2);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -61,7 +61,6 @@ class Log extends AppModel
|
|||
'registration',
|
||||
'registration_error',
|
||||
'remove_dead_workers',
|
||||
'request',
|
||||
'request_delegation',
|
||||
'reset_auth_key',
|
||||
'send_mail',
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<div class="logs index">
|
||||
<h2><?php echo __('Logs');?></h2>
|
||||
<h2><?php echo __('Application Logs');?></h2>
|
||||
<?php
|
||||
if ($isSearch == 1) {
|
||||
echo "<h4>" . __("Results for all log entries");
|
||||
|
|
Loading…
Reference in New Issue