From 2add216157431ad4797043d63afe4df73308a728 Mon Sep 17 00:00:00 2001 From: David Bailey Date: Sat, 23 Dec 2023 10:50:33 +0100 Subject: [PATCH] feat: :sparkles: add line-format output for access counters --- www/mysql_adapter.php | 44 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/www/mysql_adapter.php b/www/mysql_adapter.php index 54603e3..68afc32 100644 --- a/www/mysql_adapter.php +++ b/www/mysql_adapter.php @@ -155,6 +155,50 @@ class MySQLAdapter { return $out_data; } + function get_post_access_counters_line() { + $qry = " + SELECT access_time, post_path, agent, referrer, path_access_count, path_processing_time + FROM path_access_counts + WHERE access_time < ( CURRENT_TIMESTAMP - INTERVAL 6 MINUTE ) + ORDER BY access_time DESC; + "; + + $this->raw->begin_transaction(); + $top_access_time = null; + + try { + $data = $this->_exec($qry, "")->fetch_all(MYSQLI_ASSOC); + + $data_prefix="access_metrics,host=" . $_SERVER['SERVER_NAME']; + + $out_data = ""; + + foreach($data AS $post_data) { + $top_access_time ??= $post_data['access_time']; + + $path = $post_data['post_path']; + if($path == '') { + $path = '/'; + } + $out_data .= $data_prefix . ",agent=".$post_data['agent'].",path=".$path.",referrer=".$post_data['referrer']; + + $out_data .= " access_sum=" . $post_data['path_access_count'] . ",time_sum=" . $post_data['path_processing_time']; + $out_data .= " " . strtotime($post_data['access_time']) . "000000000\n"; + } + + + $this->_exec("DELETE FROM path_access_counts WHERE access_time <= ?", "s", $top_access_time); + + $this->raw->commit(); + return $out_data; + + } catch (\Throwable $th) { + $this->raw->rollback(); + + throw $th; + } + } + function reset_post_settings_cache($post_path) { $post_path = $this->_sanitize_path($post_path);