-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #680 from wschidol/feature/statistics
Introduce processing statistics
- Loading branch information
Showing
6 changed files
with
102 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
#!/bin/sh | ||
/usr/bin/egrep '(GET|POST) /Utils/Process_cli.php' /var/log/apache2/access.log |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
function StatisticsView() { | ||
let instance = {}; | ||
|
||
let _state = { | ||
markdown: null, | ||
}; | ||
|
||
let _rootElementId; | ||
|
||
async function loadMarkdown() { | ||
_state.markdown = await Net.sendRequest({ | ||
method: "GET", | ||
uri: "./static/statistics-page.php", | ||
}); | ||
render(); | ||
} | ||
|
||
function generateContent() { | ||
if (!_state.markdown) return; | ||
return Tools.markdownToHtml(_state.markdown); | ||
} | ||
|
||
function render(rootElementId) { | ||
_rootElementId = rootElementId = rootElementId || _rootElementId; | ||
|
||
let aboutView = UI.createElement({ | ||
id: rootElementId, | ||
}); | ||
|
||
if (!_state.markdown) { | ||
loadMarkdown(); | ||
return; | ||
} | ||
|
||
let content = generateContent(); | ||
aboutView.appendChild(content); | ||
|
||
UI.replaceElement(_rootElementId, aboutView); | ||
} | ||
|
||
instance = { | ||
render, | ||
}; | ||
|
||
return instance; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
|
||
function entry($diff,$limit,$ip,&$table) { | ||
if ($diff < $limit) { | ||
$table[$ip] = isset($table[$ip]) ? $table[$ip]+1 : 1; | ||
} | ||
} | ||
|
||
// hold accesses in the last week, month, or quarter, keyed by IP address | ||
$ip_in_week = array(); | ||
$ip_in_month = array(); | ||
$ip_in_quarter = array(); | ||
|
||
$now = date_timestamp_get(date_create()); | ||
|
||
// parse the access log and get all lines referring to /Utils/Process_cli.php | ||
$output = `sudo /var/www/html/Conformance-Frontend/src/get-access.sh`; | ||
|
||
// now go through the log line by line, storing IP vs date | ||
foreach(preg_split("/((\r?\n)|(\r\n?))/", $output) as $line) { | ||
$ip = preg_replace("/^([^ ]*)\s.*$/", "$1", $line); | ||
$date = preg_replace("/^.*(\[[^ ]+ [^ ]+\]).*$/","$1", $line); // [16/Jun/2023:10:22:36 +0000] | ||
$timestamp = DateTime::createFromFormat( | ||
'[d/M/Y:H:i:s O]', | ||
$date, | ||
new DateTimeZone('EST') | ||
); | ||
|
||
if ($timestamp !== false) { | ||
$before = $now - $timestamp->getTimestamp(); | ||
|
||
define("SEC_IN_DAY",24*60*60); | ||
entry($before,7*SEC_IN_DAY,$ip,$ip_in_week); | ||
entry($before,31*SEC_IN_DAY,$ip,$ip_in_month); | ||
entry($before,(31+31+30)*SEC_IN_DAY,$ip,$ip_in_quarter); | ||
} | ||
} | ||
|
||
echo "<table><tr>accesses<th></th><th>per week</th><th>per month</th><th>per quarter</th></tr>"; | ||
echo "<tr><th>unique</th><td>",count($ip_in_week),"</td><td>",count($ip_in_month),"</td><td>",count($ip_in_quarter),"</td>"; | ||
echo "<tr><th>total</th><td>",array_sum($ip_in_week),"</td><td>",array_sum($ip_in_month),"</td><td>",array_sum($ip_in_quarter),"</td></table>"; | ||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters