From 241f2d3249e989c900ab7b5225b6db94d0e2b21e Mon Sep 17 00:00:00 2001 From: Anantha Kalusivalingam <107127129+ananthakalusivalingam@users.noreply.github.com> Date: Mon, 29 Aug 2022 09:23:23 -0500 Subject: [PATCH 01/13] Update requestToUsage.sh Updated script will split the logs for GET and POST requests separately and store as a CSV file. New file DataUsageSummary.txt will provide the summary level information for every file. --- requestToUsage/requestToUsage.sh | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/requestToUsage/requestToUsage.sh b/requestToUsage/requestToUsage.sh index 1282a55..4021510 100755 --- a/requestToUsage/requestToUsage.sh +++ b/requestToUsage/requestToUsage.sh @@ -5,11 +5,12 @@ if [ ! -f $FILE ]; then fi PREFIX=$2 -OUTPUT=${PREFIX:+${PREFIX}-}$(head -c 8 $FILE).csv +OUTPUT=${PREFIX:+${PREFIX}-}$(head -c 10 $FILE)_POST_Requests_Only.csv -awk '!/0$/' $FILE > $OUTPUT -if sed --version +awk '/POST/' $FILE > $OUTPUT +if sed --version then sed "s/[|]/,/g" $OUTPUT -i +echo "I am in sed with out error" else echo "Please ignore the above error message from sed, switching to gsed." gsed "s/[|]/,/g" $OUTPUT -i @@ -17,11 +18,27 @@ fi echo "Successfully outputted to $OUTPUT" if date --version then echo 'date' -else +else echo "Please ignore the above error message from date, switching to gdate." echo 'gdate' fi +awk -v var=$OUTPUT -F',' '{sum+=$10;}END{print var "|" sum}' $OUTPUT >> DataUsageSummary.txt + +OUTPUT=${PREFIX:+${PREFIX}-}$(head -c 10 $FILE)_GET_Requests_Only.csv -echo "0,0,0,0,0,0,0,0,=SUM(I:I)/(1024^3),0,0" >> $OUTPUT -echo "Added calculation line." -echo "Open $OUTPUT in excel or a similar spreadsheet program" +awk '/GET/' $FILE > $OUTPUT +if sed --version +then sed "s/[|]/,/g" $OUTPUT -i +else + echo "Please ignore the above error message from sed, switching to gsed." + gsed "s/[|]/,/g" $OUTPUT -i +fi +echo "Successfully outputted to $OUTPUT" +if date --version +then echo 'date' +else + echo "Please ignore the above error message from date, switching to gdate." + echo 'gdate' +fi +awk -v var=$OUTPUT -F',' '{sum+=$10;}END{print var "|" sum}' $OUTPUT >> DataUsageSummary.txt +sleep 200 From 3968f35fc7e48216028740031bc0336c88b062dd Mon Sep 17 00:00:00 2001 From: Anantha Kalusivalingam <107127129+ananthakalusivalingam@users.noreply.github.com> Date: Mon, 29 Aug 2022 09:25:35 -0500 Subject: [PATCH 02/13] Update requestToUsage.sh remove sleep --- requestToUsage/requestToUsage.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/requestToUsage/requestToUsage.sh b/requestToUsage/requestToUsage.sh index 4021510..8d8fcdf 100755 --- a/requestToUsage/requestToUsage.sh +++ b/requestToUsage/requestToUsage.sh @@ -41,4 +41,3 @@ else echo 'gdate' fi awk -v var=$OUTPUT -F',' '{sum+=$10;}END{print var "|" sum}' $OUTPUT >> DataUsageSummary.txt -sleep 200 From 71d442abd81a438a4ee3839dc091be454b6fad85 Mon Sep 17 00:00:00 2001 From: Anantha Kalusivalingam <107127129+ananthakalusivalingam@users.noreply.github.com> Date: Mon, 29 Aug 2022 09:31:51 -0500 Subject: [PATCH 03/13] Add files via upload Updated script with a counter so that the counter can be part of the passing parameter to the called script. The counter will be part of the prefix in the called script which avoids the file overrides. --- requestToUsage/multiLogParseWithCounter.sh | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 requestToUsage/multiLogParseWithCounter.sh diff --git a/requestToUsage/multiLogParseWithCounter.sh b/requestToUsage/multiLogParseWithCounter.sh new file mode 100644 index 0000000..a13ff41 --- /dev/null +++ b/requestToUsage/multiLogParseWithCounter.sh @@ -0,0 +1,14 @@ +#!/bin/bash +LOC=$1 +${LOC:-"."} +if [ ! -d $LOC ]; then + echo "Usage is: ./multiLogParse.sh /path/to/logs/ " +else + echo "Using directory $LOC as LOC" +fi +COUNTER=1 +cd $LOC +for i in artifactory-request.*; do + .\requestToUsage.sh $LOC\\$i $COUNTER + COUNTER=$(( COUNTER + 1 )) +done From 1bbc9b68b8238ef836c4a34bade0d591460ec012 Mon Sep 17 00:00:00 2001 From: Anantha Kalusivalingam <107127129+ananthakalusivalingam@users.noreply.github.com> Date: Wed, 31 Aug 2022 19:33:57 +0000 Subject: [PATCH 04/13] Update requestToUsage.sh Update the file name --- requestToUsage/requestToUsage.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requestToUsage/requestToUsage.sh b/requestToUsage/requestToUsage.sh index 8d8fcdf..776d485 100755 --- a/requestToUsage/requestToUsage.sh +++ b/requestToUsage/requestToUsage.sh @@ -1,7 +1,7 @@ #!/bin/bash FILE=$1 if [ ! -f $FILE ]; then - echo "Correct usage is: requestToUsage.sh request.log [optional prefix string]" + echo "Correct usage is: requestToUsage.sh artifactory-request.log [optional prefix string]" fi PREFIX=$2 From e7c28365a5f1ea1f1f423f3e434f8ec7d5c5621a Mon Sep 17 00:00:00 2001 From: Anantha Kalusivalingam <107127129+ananthakalusivalingam@users.noreply.github.com> Date: Wed, 31 Aug 2022 19:39:48 +0000 Subject: [PATCH 05/13] Update README.md Update the ReadMe.md file --- requestToUsage/README.md | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/requestToUsage/README.md b/requestToUsage/README.md index fdf9400..852c8e8 100644 --- a/requestToUsage/README.md +++ b/requestToUsage/README.md @@ -1,9 +1,8 @@ #requestToUsage.sh This script is used with the syntax: -```request.sh request.log``` -(replace request.log with the name of your request log file) +```request.sh artifactory-request.log``` +(replace artifactory-request.log with the name of your request log file) -It outputs a file request.csv which you can open in excel. -The furthest right field is your overall usage in gigabytes over the period of the request log. You need to figure out the difference in the dates and turn it into a 30-day figure to get a monthly usage figure. - -TODO: Automate date difference calculation to monthly statistic +1.It consolodates the GET requests and generate a CSV file with the naming convention of {Date}_GET_Requests.CSV. +2.It consolodates the POST requests and generate a CSV file with the naming convention of {Date}_POST_Requests.CSV +3.It generates DataUsageSummary.txt which lists the individual files and their data usage size. From cb4bcb72736adba33894da146ea3997be39f8b26 Mon Sep 17 00:00:00 2001 From: Anantha Kalusivalingam <107127129+ananthakalusivalingam@users.noreply.github.com> Date: Wed, 31 Aug 2022 19:46:56 +0000 Subject: [PATCH 06/13] Update README.md Update the ReadMe doc --- requestToUsage/README.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/requestToUsage/README.md b/requestToUsage/README.md index 852c8e8..24dd643 100644 --- a/requestToUsage/README.md +++ b/requestToUsage/README.md @@ -6,3 +6,11 @@ This script is used with the syntax: 1.It consolodates the GET requests and generate a CSV file with the naming convention of {Date}_GET_Requests.CSV. 2.It consolodates the POST requests and generate a CSV file with the naming convention of {Date}_POST_Requests.CSV 3.It generates DataUsageSummary.txt which lists the individual files and their data usage size. + + +#multiLogParseWithCounter.sh +This script is used with the syntax: +```multiLogParseWithCounter.sh ../var/log/archived''' +This will recursively go behind all the artifactory-requet-*.log from the archived folder and summarizes the data usage in the DataUsageSummary.txt file. +Every log file will be split with ONE CSV file with GET requests and Second CSV file with POST requets. + From 97110732d9f4d5cb8390388f4a99e83ffb62c5c3 Mon Sep 17 00:00:00 2001 From: Anantha Kalusivalingam <107127129+ananthakalusivalingam@users.noreply.github.com> Date: Wed, 31 Aug 2022 19:48:39 +0000 Subject: [PATCH 07/13] Update README.md --- requestToUsage/README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/requestToUsage/README.md b/requestToUsage/README.md index 24dd643..38e08c4 100644 --- a/requestToUsage/README.md +++ b/requestToUsage/README.md @@ -7,10 +7,10 @@ This script is used with the syntax: 2.It consolodates the POST requests and generate a CSV file with the naming convention of {Date}_POST_Requests.CSV 3.It generates DataUsageSummary.txt which lists the individual files and their data usage size. - #multiLogParseWithCounter.sh This script is used with the syntax: ```multiLogParseWithCounter.sh ../var/log/archived''' -This will recursively go behind all the artifactory-requet-*.log from the archived folder and summarizes the data usage in the DataUsageSummary.txt file. -Every log file will be split with ONE CSV file with GET requests and Second CSV file with POST requets. +This will recursively go behind all the artifactory-requet-*.log from the archived folder and summarizes +the data usage in the DataUsageSummary.txt file. Every log file will be split with ONE CSV file with GET +requests and Second CSV file with POST requets. From bd234d205012192400c24b5994095ab8afba1572 Mon Sep 17 00:00:00 2001 From: Anantha Kalusivalingam <107127129+ananthakalusivalingam@users.noreply.github.com> Date: Wed, 31 Aug 2022 19:49:23 +0000 Subject: [PATCH 08/13] Update README.md --- requestToUsage/README.md | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/requestToUsage/README.md b/requestToUsage/README.md index 38e08c4..da3edba 100644 --- a/requestToUsage/README.md +++ b/requestToUsage/README.md @@ -3,9 +3,12 @@ This script is used with the syntax: ```request.sh artifactory-request.log``` (replace artifactory-request.log with the name of your request log file) -1.It consolodates the GET requests and generate a CSV file with the naming convention of {Date}_GET_Requests.CSV. -2.It consolodates the POST requests and generate a CSV file with the naming convention of {Date}_POST_Requests.CSV -3.It generates DataUsageSummary.txt which lists the individual files and their data usage size. +1.It consolodates the GET requests and generate a CSV file with the naming convention of +{Date}_GET_Requests.CSV. +2.It consolodates the POST requests and generate a CSV file with the naming convention of +{Date}_POST_Requests.CSV +3.It generates DataUsageSummary.txt which lists the individual files and their data +usage size. #multiLogParseWithCounter.sh This script is used with the syntax: From 4b4b7b3b5f871d6b28d202c5b584f9cb5b680406 Mon Sep 17 00:00:00 2001 From: Anantha Kalusivalingam <107127129+ananthakalusivalingam@users.noreply.github.com> Date: Tue, 6 Sep 2022 13:39:55 -0500 Subject: [PATCH 09/13] Update multiLogParseWithCounter.sh Update for the $Delimiter --- requestToUsage/multiLogParseWithCounter.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/requestToUsage/multiLogParseWithCounter.sh b/requestToUsage/multiLogParseWithCounter.sh index a13ff41..9c04e47 100644 --- a/requestToUsage/multiLogParseWithCounter.sh +++ b/requestToUsage/multiLogParseWithCounter.sh @@ -1,14 +1,15 @@ #!/bin/bash LOC=$1 +DELIMITER=$2 ${LOC:-"."} if [ ! -d $LOC ]; then - echo "Usage is: ./multiLogParse.sh /path/to/logs/ " + echo "Usage is: ./multiLogParseWithCounter.sh /path/to/logs/ " else echo "Using directory $LOC as LOC" fi COUNTER=1 cd $LOC for i in artifactory-request.*; do - .\requestToUsage.sh $LOC\\$i $COUNTER + .\requestToUsage.sh $LOC\\$i $DELIMITER $COUNTER COUNTER=$(( COUNTER + 1 )) done From 99e551de6657bf85aed06298b5bc6c7e7e67912f Mon Sep 17 00:00:00 2001 From: Anantha Kalusivalingam <107127129+ananthakalusivalingam@users.noreply.github.com> Date: Tue, 6 Sep 2022 13:40:41 -0500 Subject: [PATCH 10/13] Update requestToUsage.sh Update for the $delimiter --- requestToUsage/requestToUsage.sh | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/requestToUsage/requestToUsage.sh b/requestToUsage/requestToUsage.sh index 776d485..a916155 100755 --- a/requestToUsage/requestToUsage.sh +++ b/requestToUsage/requestToUsage.sh @@ -1,19 +1,26 @@ #!/bin/bash FILE=$1 if [ ! -f $FILE ]; then - echo "Correct usage is: requestToUsage.sh artifactory-request.log [optional prefix string]" + echo "Correct usage is: requestToUsage.sh request.log [optional delimiter] [optional prefix string]" fi -PREFIX=$2 +DELIMITER=$2 + +if [ -z "$2" ] + then + echo "No argument supplied for delimiter. Set comma as delimiter" + DELIMITER=',' +fi +PREFIX=$3 OUTPUT=${PREFIX:+${PREFIX}-}$(head -c 10 $FILE)_POST_Requests_Only.csv awk '/POST/' $FILE > $OUTPUT if sed --version -then sed "s/[|]/,/g" $OUTPUT -i +then sed "s/[$DELIMITER]/,/g" $OUTPUT -i echo "I am in sed with out error" else echo "Please ignore the above error message from sed, switching to gsed." - gsed "s/[|]/,/g" $OUTPUT -i + gsed "s/[$DELIMITER]/,/g" $OUTPUT -i fi echo "Successfully outputted to $OUTPUT" if date --version @@ -28,10 +35,10 @@ OUTPUT=${PREFIX:+${PREFIX}-}$(head -c 10 $FILE)_GET_Requests_Only.csv awk '/GET/' $FILE > $OUTPUT if sed --version -then sed "s/[|]/,/g" $OUTPUT -i +then sed "s/[$DELIMITER]/,/g" $OUTPUT -i else echo "Please ignore the above error message from sed, switching to gsed." - gsed "s/[|]/,/g" $OUTPUT -i + gsed "s/[$DELIMITER]/,/g" $OUTPUT -i fi echo "Successfully outputted to $OUTPUT" if date --version From ea441d35e964135be7e562296bac1b2ac41abc98 Mon Sep 17 00:00:00 2001 From: Anantha Kalusivalingam <107127129+ananthakalusivalingam@users.noreply.github.com> Date: Tue, 6 Sep 2022 13:42:48 -0500 Subject: [PATCH 11/13] Update README.md Update the comments --- requestToUsage/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/requestToUsage/README.md b/requestToUsage/README.md index da3edba..4613ef4 100644 --- a/requestToUsage/README.md +++ b/requestToUsage/README.md @@ -1,6 +1,6 @@ #requestToUsage.sh This script is used with the syntax: -```request.sh artifactory-request.log``` +```requestToUsage.sh artifactory-request.log $Delimiter $Prefix``` (replace artifactory-request.log with the name of your request log file) 1.It consolodates the GET requests and generate a CSV file with the naming convention of @@ -12,7 +12,7 @@ usage size. #multiLogParseWithCounter.sh This script is used with the syntax: -```multiLogParseWithCounter.sh ../var/log/archived''' +```multiLogParseWithCounter.sh ../var/log/archived $Delimiter``` This will recursively go behind all the artifactory-requet-*.log from the archived folder and summarizes the data usage in the DataUsageSummary.txt file. Every log file will be split with ONE CSV file with GET requests and Second CSV file with POST requets. From ce747aaf4a3fb5f891cd7dbaa209a679ab8f2932 Mon Sep 17 00:00:00 2001 From: Anantha Kalusivalingam <107127129+ananthakalusivalingam@users.noreply.github.com> Date: Tue, 6 Sep 2022 13:44:06 -0500 Subject: [PATCH 12/13] Update README.md Additional comment --- requestToUsage/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/requestToUsage/README.md b/requestToUsage/README.md index 4613ef4..30dd371 100644 --- a/requestToUsage/README.md +++ b/requestToUsage/README.md @@ -1,7 +1,7 @@ #requestToUsage.sh This script is used with the syntax: ```requestToUsage.sh artifactory-request.log $Delimiter $Prefix``` -(replace artifactory-request.log with the name of your request log file) +(replace artifactory-request.log with the name of your request log file. $Delimiter could be pipe or comma. Default is comma.) 1.It consolodates the GET requests and generate a CSV file with the naming convention of {Date}_GET_Requests.CSV. @@ -15,5 +15,5 @@ This script is used with the syntax: ```multiLogParseWithCounter.sh ../var/log/archived $Delimiter``` This will recursively go behind all the artifactory-requet-*.log from the archived folder and summarizes the data usage in the DataUsageSummary.txt file. Every log file will be split with ONE CSV file with GET -requests and Second CSV file with POST requets. +requests and Second CSV file with POST requets. $Delimiter could be pipe or comma. Default is comma. From 4fab3d5768600a8e62f4ab5dd2cf3526d344938a Mon Sep 17 00:00:00 2001 From: Anantha Kalusivalingam <107127129+ananthakalusivalingam@users.noreply.github.com> Date: Mon, 27 Feb 2023 20:10:23 -0600 Subject: [PATCH 13/13] Update requestToUsage.sh Fixed the Columns and the delimeter as pipe --- requestToUsage/requestToUsage.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/requestToUsage/requestToUsage.sh b/requestToUsage/requestToUsage.sh index a916155..87936d5 100755 --- a/requestToUsage/requestToUsage.sh +++ b/requestToUsage/requestToUsage.sh @@ -29,7 +29,7 @@ else echo "Please ignore the above error message from date, switching to gdate." echo 'gdate' fi -awk -v var=$OUTPUT -F',' '{sum+=$10;}END{print var "|" sum}' $OUTPUT >> DataUsageSummary.txt +awk -v var=$OUTPUT -F'|' '{sum+=$8;}END{print var "|" sum}' $OUTPUT >> DataUsageSummary.txt OUTPUT=${PREFIX:+${PREFIX}-}$(head -c 10 $FILE)_GET_Requests_Only.csv @@ -47,4 +47,4 @@ else echo "Please ignore the above error message from date, switching to gdate." echo 'gdate' fi -awk -v var=$OUTPUT -F',' '{sum+=$10;}END{print var "|" sum}' $OUTPUT >> DataUsageSummary.txt +awk -v var=$OUTPUT -F'|' '{sum+=$9;}END{print var "|" sum}' $OUTPUT >> DataUsageSummary.txt