This repository contains my first laboratory work for the Programming Fundamentals course in C++.
The lab was completed during my first semester of the Software Engineering program at ITMO University. The project represents my early practical experience with C++ and basic programming concepts.
Below is the original laboratory assignment statement translated into English.
Check out my other C++ labs:
- First semester. Programming fundamentals in C++:
- Second semester. Programming in C++:
🇬🇧 English | 🇷🇺 Русский
Implement a utility that analyzes an access.log.
Based on this log, the utility must be able to:
-
Output requests that ended with an error status code (
5XX). -
Find the time interval during which the number of requests to the server was maximal.
The utility must support the following command-line arguments/options:
| Short argument | Long argument | Default value | Description |
|---|---|---|---|
-o path |
--output=path |
Path to the file where requests with errors will be written. If the file is not specified, analysis of error requests is not performed. | |
-p |
--print |
Duplicate the output of error requests to stdout (standard output stream / terminal). |
|
-s n |
--stats=n |
10 |
Output the n most frequent requests that ended with a 5XX status code, in descending order of frequency. |
-w t |
--window=t |
0 |
Find and output the time interval/window of length t seconds during which the number of requests was maximal. If t is equal to 0, the calculation is not performed. |
-f |
--from=time |
The smallest time in the log | Time in timestamp format, starting from which the data analysis is performed. |
-е |
--to=time |
The largest time in the log | Time in timestamp format, up to which the data analysis is performed, inclusive. |
The filename and options are passed to the program as command-line arguments in the following format:
AnalyzeLog [OPTIONS] logs_filenameAs an example log file, it is suggested to use the NASA server logs.
The logs are a text file where each line contains a server access event in the following format:
<remote_addr> - - [<local_time>] "<request>" <status> <bytes_send>
| Value | Description |
|---|---|
remote_addr |
The address from which the request was sent. |
local_time |
The time when the request was received. |
request |
The request URL. |
status |
The server response status code. |
bytes_send |
The number of bytes sent in the response. |
Examples of lines from the log file:
198.112.92.15 - - [03/Jul/2024:10:50:02 -0400] "GET /shuttle/countdown/HTTP/1.0" 200 3985
198.112.92.15 - - [03/Jul/2024:10:50:04 -0400] "GET /shuttle/nosuchpath/HTTP/1.0" 404 144
AnalyzeLog access.log --output=result.txtAnalyzeLog access.log --output=result.txt --print --stats 5AnalyzeLog --stats=2 --window=60 --from=805821284 --to=807117284 access.logAnalyzeLog -s 2 access.logAnalyzeLog -w 10 access.logAnalyzeLog access.log -w 10-
It is worth considering that the file size may be quite large and may significantly exceed the amount of available RAM. Therefore, memory consumption should not depend on the size of the file.
-
It is worth thinking about how the program can be divided into logical functions.
-
Do not forget about code style.
To implement the utility, you will need to use the standard input/output library. Usage example.
An example of how command-line argument parsing can be organized can be found here.
External libraries are forbidden. Only the standard C or C++ library may be used.
- 01.10.23 24:00 - 0.8
- 08.10.23 24:00 - 0.65
- 15.10.23 24:00 - 0.5