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', ], ]; } /** * 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' => __('Everything’s OK!'), 'class' => 'status-text', ], true ); } else { $image_status = html_print_image('images/status_error@svg.svg', true); $text = html_print_div( [ 'content' => __('Something’s wrong'), 'class' => 'status-text', ], true ); } $output = $image_status.$text; return html_print_div( [ 'content' => $output, 'class' => 'flex_center margin-top-5', 'id' => 'status-database', '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'; return html_print_div( [ 'content' => $value, 'class' => 'text-l', 'id' => 'data-records', 'style' => 'margin: 0px 10px 10px 10px;', ], true ); } /** * Returns the html of total events. * * @return string */ public function getEvents():string { $data = $this->valueMonitoring('last_events_24h'); $value = round($data[0]['datos']); return html_print_div( [ 'content' => $value, 'class' => 'text-l', 'id' => 'total-events', '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']); return html_print_div( [ 'content' => $value, 'class' => 'text-l', 'id' => 'total-records', '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']; } $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, ], ], 'elements' => [ 'point' => [ 'radius' => 0 ] ], ]; $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', 'style' => 'max-height: 83px;', ], true ); $total = html_print_div( [ 'content' => $total, 'class' => 'text-xl', ], true ); $output = html_print_div( [ 'content' => $total.$graph_area, 'id' => 'database-reads', ], true ); 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']; } $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, ], ], 'elements' => [ 'point' => [ 'radius' => 0 ] ], ]; $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', 'style' => 'max-height: 83px;', ], true ); $total = html_print_div( [ 'content' => $total, 'class' => 'text-xl', ], true ); $output = html_print_div( [ 'content' => $total.$graph_area, 'id' => 'database-writes', ], true ); return $output; } /** * Check if user can manage database * * @return boolean */ public function checkAcl():bool { global $config; $db_m = (bool) check_acl($config['id_user'], 0, 'DM'); return $db_m; } }