feat: ✨ add line-format output for access counters
This commit is contained in:
parent
a4fe4c4489
commit
2add216157
1 changed files with 44 additions and 0 deletions
|
@ -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);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue