pandorafms/pandora_console/include/lib/TacticalView/elements/Database.php

333 lines
8.9 KiB
PHP
Raw Normal View History

2023-09-25 13:52:28 +02:00
<?php
/**
* Database element for tactical view.
*
* @category General
* @package Pandora FMS
* @subpackage TacticalView
* @version 1.0.0
* @license See below
*
* ______ ___ _______ _______ ________
* | __ \.-----.--.--.--| |.-----.----.-----. | ___| | | __|
* | __/| _ | | _ || _ | _| _ | | ___| |__ |
* |___| |___._|__|__|_____||_____|__| |___._| |___| |__|_|__|_______|
*
* ============================================================================
* Copyright (c) 2007-2023 Artica Soluciones Tecnologicas, http://www.artica.es
* This code is NOT free software. This code is NOT licenced under GPL2 licence
* You cannnot redistribute it without written permission of copyright holder.
* ============================================================================
*/
use PandoraFMS\TacticalView\Element;
/**
* Database, this class contain all logic for this section.
*/
class Database extends Element
{
/**
* Constructor
*/
public function __construct()
{
2023-09-27 13:30:56 +02:00
parent::__construct();
2023-09-25 13:52:28 +02:00
$this->title = __('Database');
$this->ajaxMethods = [
'getStatus',
'getDataRecords',
'getEvents',
'getStringRecords',
'getReadsGraph',
'getWritesGraph',
];
$this->interval = 300000;
$this->refreshConfig = [
'status' => [
'id' => 'status-database',
'method' => 'getStatus',
],
'records' => [
'id' => 'data-records',
'method' => 'getDataRecords',
],
'events' => [
'id' => 'total-events',
'method' => 'getEvents',
],
'totalRecords' => [
'id' => 'total-records',
'method' => 'getStringRecords',
],
'reads' => [
'id' => 'database-reads',
'method' => 'getReadsGraph',
],
'writes' => [
'id' => 'database-writes',
'method' => 'getWritesGraph',
],
];
2023-09-25 13:52:28 +02:00
}
/**
* Returns the html status of database.
*
* @return string
*/
public function getStatus():string
{
// TODO connect to automonitorization.
$status = true;
if ($status === true) {
$image_status = html_print_image('images/status_check@svg.svg', true);
$text = html_print_div(
[
'content' => __('Everythings OK!'),
'class' => 'status-text',
],
true
);
} else {
$image_status = html_print_image('images/status_error@svg.svg', true);
$text = html_print_div(
[
'content' => __('Somethings wrong'),
'class' => 'status-text',
],
true
);
}
$output = $image_status.$text;
return html_print_div(
[
'content' => $output,
'class' => 'flex_center margin-top-5',
'id' => 'status-database',
2023-09-25 13:52:28 +02:00
'style' => 'margin: 0px 10px 10px 10px;',
],
true
);
}
/**
* Returns the html records data of database.
*
* @return string
*/
public function getDataRecords():string
{
$data = $this->valueMonitoring('mysql_size_of_data');
$value = round($data[0]['datos'], 2).' MB';
2023-09-25 13:52:28 +02:00
return html_print_div(
[
'content' => $value,
2023-09-25 13:52:28 +02:00
'class' => 'text-l',
'id' => 'data-records',
2023-09-25 13:52:28 +02:00
'style' => 'margin: 0px 10px 10px 10px;',
],
true
);
}
/**
* Returns the html of total events.
*
* @return string
*/
public function getEvents():string
{
// TODO connect to automonitorization.
return html_print_div(
[
'content' => '9.999.999',
'class' => 'text-l',
'id' => 'total-events',
2023-09-25 13:52:28 +02:00
'style' => 'margin: 0px 10px 10px 10px;',
],
true
);
}
/**
* Returns the html of total records.
*
* @return string
*/
public function getStringRecords():string
{
$data = $this->valueMonitoring('total_string_data');
$value = round($data[0]['datos']);
2023-09-25 13:52:28 +02:00
return html_print_div(
[
'content' => $value,
2023-09-25 13:52:28 +02:00
'class' => 'text-l',
'id' => 'total-records',
2023-09-25 13:52:28 +02:00
'style' => 'margin: 0px 10px 10px 10px;',
],
true
);
}
/**
* Returns the html of total reads database in a graph.
*
* @return string
*/
public function getReadsGraph():string
{
$dateInit = (time() - 86400);
$reads = $this->valueMonitoring('mysql_questions_reads', $dateInit, time());
$dates = [];
$string_reads = [];
$total = 0;
foreach ($reads as $key => $read) {
$dates[] = date('d-m-Y H:i:s', $read['utimestamp']);
$string_reads[] = $read['datos'];
$total += $read['datos'];
}
2023-09-25 13:52:28 +02:00
$options = [
'labels' => $dates,
'legend' => [ 'display' => false ],
'tooltips' => [ 'display' => false ],
'scales' => [
'y' => [
'grid' => ['display' => false],
'ticks' => ['display' => false],
'display' => false,
],
'x' => [
'grid' => ['display' => false],
'display' => false,
],
],
];
$data = [
[
'backgroundColor' => '#EC7176',
'borderColor' => '#EC7176',
'pointBackgroundColor' => '#EC7176',
'pointHoverBorderColor' => '#EC7176',
'data' => $string_reads,
],
];
$graph_area = html_print_div(
[
'content' => line_graph($data, $options),
'class' => 'w100p h100p',
2023-09-27 13:30:56 +02:00
'style' => 'max-height: 83px;',
2023-09-25 13:52:28 +02:00
],
true
);
$total = html_print_div(
[
'content' => $total,
'class' => 'text-xl',
],
true
);
$output = html_print_div(
[
'content' => $total.$graph_area,
'id' => 'database-reads',
],
true
);
2023-09-25 13:52:28 +02:00
return $output;
}
/**
* Returns the html of total writes database in a graph.
*
* @return string
*/
public function getWritesGraph():string
{
$dateInit = (time() - 86400);
$writes = $this->valueMonitoring('mysql_questions_writes', $dateInit, time());
$dates = [];
$string_writes = [];
$total = 0;
foreach ($writes as $key => $write) {
$dates[] = date('d-m-Y H:i:s', $write['utimestamp']);
$string_writes[] = $write['datos'];
$total += $write['datos'];
}
2023-09-25 13:52:28 +02:00
$options = [
'labels' => $dates,
'legend' => [ 'display' => false ],
'tooltips' => [ 'display' => false ],
'scales' => [
'y' => [
'grid' => ['display' => false],
'ticks' => ['display' => false],
'display' => false,
],
'x' => [
'grid' => ['display' => false],
'display' => false,
],
],
];
$data = [
[
'backgroundColor' => '#009D9E',
'borderColor' => '#009D9E',
'pointBackgroundColor' => '#009D9E',
'pointHoverBorderColor' => '#009D9E',
'data' => $string_writes,
],
];
$graph_area = html_print_div(
[
'content' => line_graph($data, $options),
'class' => 'w100p h100p',
2023-09-27 13:30:56 +02:00
'style' => 'max-height: 83px;',
2023-09-25 13:52:28 +02:00
],
true
);
$total = html_print_div(
[
'content' => $total,
'class' => 'text-xl',
],
true
);
$output = html_print_div(
[
'content' => $total.$graph_area,
'id' => 'database-writes',
],
true
);
2023-09-25 13:52:28 +02:00
return $output;
}
}