From 8204d7e9c185d464e935fd7977b26bdbbb0c53ab Mon Sep 17 00:00:00 2001 From: Borisov Ignat <90337398+Telezhka-the-First@users.noreply.github.com> Date: Sat, 27 Nov 2021 05:45:25 +0300 Subject: [PATCH 1/7] lab3 base --- Log_Analyzing.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 Log_Analyzing.c diff --git a/Log_Analyzing.c b/Log_Analyzing.c new file mode 100644 index 0000000..3b86fe7 --- /dev/null +++ b/Log_Analyzing.c @@ -0,0 +1,42 @@ +//Made in Visual Studio 2019 + +#ifdef _MSC_VER +#define _CRT_SECURE_NO_WARNINGS +#endif + +#include + +int main() +{ + char ref[54]; + char time_of_request[27]; + char data[2048]; + int result; + char data_weight[4]; + int ErrorCount = 0; + + FILE *foe = fopen("access_log_Jul95", "r"); + + if (!foe) + { + printf("%s", "File did not open."); + return 1; + } + + fseek(foe, 0, SEEK_SET); + + printf("Counting requests with 5xx error (server errors)...\n\n"); + + while (!feof(foe)) + { + fscanf(foe, "%s - - [%[^]]] \"%[^\"]\" %d %d", ref, time_of_request, data, &result, &data_weight); + if ((result / 100) == 5) + { + ErrorCount++; + printf("%2d) %s\n", ErrorCount, data); + } + } + + printf("\nQuantity of requests with 5xx error (server errors): %d\n", ErrorCount); + return 0; +} \ No newline at end of file From bae4f47f741d2d8e7261598e43911f067b4ecdf2 Mon Sep 17 00:00:00 2001 From: Borisov Ignat <90337398+Telezhka-the-First@users.noreply.github.com> Date: Sat, 27 Nov 2021 05:46:34 +0300 Subject: [PATCH 2/7] Lab3 Base --- lab3/Log_Analyzing.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 lab3/Log_Analyzing.c diff --git a/lab3/Log_Analyzing.c b/lab3/Log_Analyzing.c new file mode 100644 index 0000000..3b86fe7 --- /dev/null +++ b/lab3/Log_Analyzing.c @@ -0,0 +1,42 @@ +//Made in Visual Studio 2019 + +#ifdef _MSC_VER +#define _CRT_SECURE_NO_WARNINGS +#endif + +#include + +int main() +{ + char ref[54]; + char time_of_request[27]; + char data[2048]; + int result; + char data_weight[4]; + int ErrorCount = 0; + + FILE *foe = fopen("access_log_Jul95", "r"); + + if (!foe) + { + printf("%s", "File did not open."); + return 1; + } + + fseek(foe, 0, SEEK_SET); + + printf("Counting requests with 5xx error (server errors)...\n\n"); + + while (!feof(foe)) + { + fscanf(foe, "%s - - [%[^]]] \"%[^\"]\" %d %d", ref, time_of_request, data, &result, &data_weight); + if ((result / 100) == 5) + { + ErrorCount++; + printf("%2d) %s\n", ErrorCount, data); + } + } + + printf("\nQuantity of requests with 5xx error (server errors): %d\n", ErrorCount); + return 0; +} \ No newline at end of file From 11526d9d7cdb7a92a768d5db70b984a7ceda53bd Mon Sep 17 00:00:00 2001 From: Borisov Ignat <90337398+Telezhka-the-First@users.noreply.github.com> Date: Sat, 27 Nov 2021 05:47:04 +0300 Subject: [PATCH 3/7] Lab3 Base --- Log_Analyzing.c | 42 ------------------------------------------ 1 file changed, 42 deletions(-) delete mode 100644 Log_Analyzing.c diff --git a/Log_Analyzing.c b/Log_Analyzing.c deleted file mode 100644 index 3b86fe7..0000000 --- a/Log_Analyzing.c +++ /dev/null @@ -1,42 +0,0 @@ -//Made in Visual Studio 2019 - -#ifdef _MSC_VER -#define _CRT_SECURE_NO_WARNINGS -#endif - -#include - -int main() -{ - char ref[54]; - char time_of_request[27]; - char data[2048]; - int result; - char data_weight[4]; - int ErrorCount = 0; - - FILE *foe = fopen("access_log_Jul95", "r"); - - if (!foe) - { - printf("%s", "File did not open."); - return 1; - } - - fseek(foe, 0, SEEK_SET); - - printf("Counting requests with 5xx error (server errors)...\n\n"); - - while (!feof(foe)) - { - fscanf(foe, "%s - - [%[^]]] \"%[^\"]\" %d %d", ref, time_of_request, data, &result, &data_weight); - if ((result / 100) == 5) - { - ErrorCount++; - printf("%2d) %s\n", ErrorCount, data); - } - } - - printf("\nQuantity of requests with 5xx error (server errors): %d\n", ErrorCount); - return 0; -} \ No newline at end of file From 2f4768db7aa0b218deb97e3ff628fcc949513dc3 Mon Sep 17 00:00:00 2001 From: Borisov Ignat <90337398+Telezhka-the-First@users.noreply.github.com> Date: Sat, 19 Mar 2022 13:27:59 +0300 Subject: [PATCH 4/7] Added new version of lab3 --- lab3/main.c | 127 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 127 insertions(+) create mode 100644 lab3/main.c diff --git a/lab3/main.c b/lab3/main.c new file mode 100644 index 0000000..e8f3d87 --- /dev/null +++ b/lab3/main.c @@ -0,0 +1,127 @@ +#include +#include +#include +#include +#include + +int main() +{ + + struct tm time; + + char *filename = "access_log_Jul95"; + + long *line_time; + + char entire_line[4150]; + int line_count = 0; + + char ref[2049]; + char time_of_request[27]; + char data[2049]; + int result; + char data_weight[4]; + int ErrorCount = 0; + char month[3]; + char months[12][4] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Dec"}; + + long window; + + FILE *foe = fopen(filename, "r"); + + if (!foe) { + + printf("%s", "File did not open."); + + return 1; + } + + while (fgets(entire_line, 4150, foe) != NULL) line_count++; + + //printf("line_count = %d\n", line_count); + + printf("Enter time window\n"); + scanf("%lld", &window); + + printf("Counting requests with 5xx error (server errors)...\n\n"); + + int line = 0; + + line_time = malloc(sizeof(long) * line_count); + + //for (int i = 0; i < line_count; i++) line_time[line_count] = 0; + + fseek(foe, 0, SEEK_SET); + + while (!feof(foe)) { + + fscanf(foe, "%s - - [%[^]]] \"%[^\"]\" %d %d", ref, time_of_request, data, &result, &data_weight); + + if ((result / 100) == 5) { + + ErrorCount++; + + printf("%d) %s\n", ErrorCount, data); + } + + sscanf(time_of_request,"%d/%3s/%d:%d:%d:%d", &time.tm_mday, month, &time.tm_year, &time.tm_hour, &time.tm_min, &time.tm_sec); + + //printf("%d/%3s/%d:%d:%d:%d\n", time.tm_mday, month, time.tm_year, time.tm_hour, time.tm_min, time.tm_sec); + //getch(); + + time.tm_year -= 1900; + + int cur_month = 0; + + for (cur_month = 0; cur_month < 12; cur_month++) { + if (!strcmp(months[cur_month], month)) break; + } + + time.tm_mon = cur_month; + + //printf("%d/%3s/%d:%d:%d:%d\n", time.tm_mday, month, time.tm_year, time.tm_hour, time.tm_min, time.tm_sec); + //getch(); + + line_time[line] = (long)mktime(&time); + + //printf("%lld\n%lld\n", mktime(&time), line_time[line]); + //getch(); + + line++; + } + + long long left_bound = 0, right_bound = 0, maximum = 0, current_length = 0, left_bound_final = 0, right_bound_final = 0; + + while (1) { + if (line_time[right_bound] - line_time[left_bound] > window) { + left_bound++; + current_length = 0; + } else { + current_length++; + + if (current_length > maximum) { + left_bound_final = left_bound; + right_bound_final = right_bound; + maximum = current_length; + } + + right_bound++; + } + if (right_bound > line_count) break; + } + + struct tm *time_start; + struct tm *time_end; + + time_t left_bound_final_ll = line_time[left_bound_final]; + time_t right_bound_final_ll = line_time[right_bound_final]; + + time_start = localtime (&left_bound_final_ll); + time_end = localtime (&right_bound_final_ll); + + printf("\nQuantity of requests with 5xx error (server errors): %d\n", ErrorCount); + printf("\nMaximum quantity of requests in %ld second(s) window: %lld\nFrom %s to %s", window, maximum, asctime(time_start), asctime(time_end)); + + fclose(foe); + return 0; +} \ No newline at end of file From 6cd1d387983155049a9d13ecb19b2f3f57856ba5 Mon Sep 17 00:00:00 2001 From: Borisov Ignat <90337398+Telezhka-the-First@users.noreply.github.com> Date: Sat, 19 Mar 2022 14:08:58 +0300 Subject: [PATCH 5/7] Add files via upload --- lab3/main.c | 64 ++++++++++++++++++++++------------------------------- 1 file changed, 26 insertions(+), 38 deletions(-) diff --git a/lab3/main.c b/lab3/main.c index e8f3d87..b397cd7 100644 --- a/lab3/main.c +++ b/lab3/main.c @@ -2,7 +2,6 @@ #include #include #include -#include int main() { @@ -20,12 +19,12 @@ int main() char time_of_request[27]; char data[2049]; int result; - char data_weight[4]; + int data_weight; int ErrorCount = 0; char month[3]; char months[12][4] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Dec"}; - long window; + long long window; FILE *foe = fopen(filename, "r"); @@ -33,13 +32,11 @@ int main() printf("%s", "File did not open."); - return 1; + return -1; } while (fgets(entire_line, 4150, foe) != NULL) line_count++; - //printf("line_count = %d\n", line_count); - printf("Enter time window\n"); scanf("%lld", &window); @@ -49,8 +46,6 @@ int main() line_time = malloc(sizeof(long) * line_count); - //for (int i = 0; i < line_count; i++) line_time[line_count] = 0; - fseek(foe, 0, SEEK_SET); while (!feof(foe)) { @@ -66,11 +61,6 @@ int main() sscanf(time_of_request,"%d/%3s/%d:%d:%d:%d", &time.tm_mday, month, &time.tm_year, &time.tm_hour, &time.tm_min, &time.tm_sec); - //printf("%d/%3s/%d:%d:%d:%d\n", time.tm_mday, month, time.tm_year, time.tm_hour, time.tm_min, time.tm_sec); - //getch(); - - time.tm_year -= 1900; - int cur_month = 0; for (cur_month = 0; cur_month < 12; cur_month++) { @@ -78,49 +68,47 @@ int main() } time.tm_mon = cur_month; - - //printf("%d/%3s/%d:%d:%d:%d\n", time.tm_mday, month, time.tm_year, time.tm_hour, time.tm_min, time.tm_sec); - //getch(); + time.tm_year -= 1900; line_time[line] = (long)mktime(&time); - //printf("%lld\n%lld\n", mktime(&time), line_time[line]); - //getch(); - line++; } - long long left_bound = 0, right_bound = 0, maximum = 0, current_length = 0, left_bound_final = 0, right_bound_final = 0; + int difference = 0, current_length = 1, maximum = 0, j = 1, left_bound_final, right_bound_final; - while (1) { - if (line_time[right_bound] - line_time[left_bound] > window) { - left_bound++; - current_length = 0; - } else { - current_length++; + for (int i = 1; i < line_count; i++) { - if (current_length > maximum) { - left_bound_final = left_bound; - right_bound_final = right_bound; - maximum = current_length; - } + current_length++; + difference += line_time[i] - line_time[i - 1]; - right_bound++; + while ((difference > window) && (j + 1 < line_count)) { + difference -= (line_time[j] - line_time[j - 1]); + j++; + current_length--; + } + + if (current_length > maximum) { + maximum = current_length; + left_bound_final = j; + right_bound_final = i; } - if (right_bound > line_count) break; } struct tm *time_start; struct tm *time_end; + printf("\nQuantity of requests with 5xx error (server errors): %d\n", ErrorCount); + time_t left_bound_final_ll = line_time[left_bound_final]; - time_t right_bound_final_ll = line_time[right_bound_final]; + time_start = localtime(&left_bound_final_ll); - time_start = localtime (&left_bound_final_ll); - time_end = localtime (&right_bound_final_ll); + printf("\nMaximum quantity of requests in %ld second(s) window: %d\nFrom %s", window, maximum, asctime(time_start)); - printf("\nQuantity of requests with 5xx error (server errors): %d\n", ErrorCount); - printf("\nMaximum quantity of requests in %ld second(s) window: %lld\nFrom %s to %s", window, maximum, asctime(time_start), asctime(time_end)); + time_t right_bound_final_ll = line_time[right_bound_final]; + time_end = localtime(&right_bound_final_ll); + + printf(" to %s", asctime(time_end)); fclose(foe); return 0; From fd693d5c22527a8453ab7abeb087d5bd11650a63 Mon Sep 17 00:00:00 2001 From: Borisov Ignat <90337398+Telezhka-the-First@users.noreply.github.com> Date: Sat, 19 Mar 2022 14:09:22 +0300 Subject: [PATCH 6/7] Delete Log_Analyzing.c --- lab3/Log_Analyzing.c | 42 ------------------------------------------ 1 file changed, 42 deletions(-) delete mode 100644 lab3/Log_Analyzing.c diff --git a/lab3/Log_Analyzing.c b/lab3/Log_Analyzing.c deleted file mode 100644 index 3b86fe7..0000000 --- a/lab3/Log_Analyzing.c +++ /dev/null @@ -1,42 +0,0 @@ -//Made in Visual Studio 2019 - -#ifdef _MSC_VER -#define _CRT_SECURE_NO_WARNINGS -#endif - -#include - -int main() -{ - char ref[54]; - char time_of_request[27]; - char data[2048]; - int result; - char data_weight[4]; - int ErrorCount = 0; - - FILE *foe = fopen("access_log_Jul95", "r"); - - if (!foe) - { - printf("%s", "File did not open."); - return 1; - } - - fseek(foe, 0, SEEK_SET); - - printf("Counting requests with 5xx error (server errors)...\n\n"); - - while (!feof(foe)) - { - fscanf(foe, "%s - - [%[^]]] \"%[^\"]\" %d %d", ref, time_of_request, data, &result, &data_weight); - if ((result / 100) == 5) - { - ErrorCount++; - printf("%2d) %s\n", ErrorCount, data); - } - } - - printf("\nQuantity of requests with 5xx error (server errors): %d\n", ErrorCount); - return 0; -} \ No newline at end of file From f00cb7b84c583a01ca8dfbeca83c96cac6752d3e Mon Sep 17 00:00:00 2001 From: Borisov Ignat <90337398+Telezhka-the-First@users.noreply.github.com> Date: Sat, 19 Mar 2022 14:25:49 +0300 Subject: [PATCH 7/7] Add files via upload --- lab3/main.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/lab3/main.c b/lab3/main.c index b397cd7..6282afb 100644 --- a/lab3/main.c +++ b/lab3/main.c @@ -61,7 +61,7 @@ int main() sscanf(time_of_request,"%d/%3s/%d:%d:%d:%d", &time.tm_mday, month, &time.tm_year, &time.tm_hour, &time.tm_min, &time.tm_sec); - int cur_month = 0; + short cur_month; for (cur_month = 0; cur_month < 12; cur_month++) { if (!strcmp(months[cur_month], month)) break; @@ -75,23 +75,23 @@ int main() line++; } - int difference = 0, current_length = 1, maximum = 0, j = 1, left_bound_final, right_bound_final; + int difference = 0, current_length = 1, maximum = 0, position = 1, left_bound_final, right_bound_final; - for (int i = 1; i < line_count; i++) { + for (int cur_line = 1; cur_line < line_count; cur_line++) { current_length++; - difference += line_time[i] - line_time[i - 1]; + difference += line_time[cur_line] - line_time[cur_line - 1]; - while ((difference > window) && (j + 1 < line_count)) { - difference -= (line_time[j] - line_time[j - 1]); - j++; + while ((difference > window) && (position + 1 < line_count)) { + difference -= (line_time[position] - line_time[position - 1]); + position++; current_length--; } if (current_length > maximum) { maximum = current_length; - left_bound_final = j; - right_bound_final = i; + left_bound_final = position; + right_bound_final = cur_line; } } @@ -103,7 +103,7 @@ int main() time_t left_bound_final_ll = line_time[left_bound_final]; time_start = localtime(&left_bound_final_ll); - printf("\nMaximum quantity of requests in %ld second(s) window: %d\nFrom %s", window, maximum, asctime(time_start)); + printf("\nMaximum quantity of requests in %lld second(s) window: %d\nFrom %s", window, maximum, asctime(time_start)); time_t right_bound_final_ll = line_time[right_bound_final]; time_end = localtime(&right_bound_final_ll);