Skip to content

Commit

Permalink
Changed parser methods
Browse files Browse the repository at this point in the history
  • Loading branch information
catttam committed Sep 10, 2024
1 parent e627956 commit 4423aa4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
7 changes: 5 additions & 2 deletions extract_goaccess_metrics.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ metrics(){
LOG_FILE=$1
filename=`basename "$LOG_FILE"`
geo_err=$( { goaccess "${LOG_FILE}" --log-format="${LOG_FORMAT}" -o "${OUTPUTS_PATH}/${filename}_full.json" --json-pretty-print; } 2>&1 )
python3 goaccess_metric_parser.py -f "${OUTPUTS_PATH}/${filename}_full.json" -g 0
if [[ $filename == "latest"* ]]; then
python3 goaccess_metric_parser.py -f "${OUTPUTS_PATH}/${filename}_full.json" -g 0
else
python3 goaccess_metric_parser.py -f "${OUTPUTS_PATH}/${filename}_full.json" -g 0 -u

status_codes=('200' '204' '404' '500')
init="t"
Expand Down Expand Up @@ -70,7 +73,7 @@ done
for logfile in "$LOCAL_LOGS_DIR/$log/controller/"*;
do
if [[ $logfile == *".log"* ]]; then
if [[ $logfile == *".log"]]; then
if [[ $logfile == *".log" ]]; then
cat $logfile | grep -a 'oscar-oscar' | grep -a '/job\|/run' | tee -a $LATEST_LOGS >/dev/null
metrics $LATEST_LOGS
else
Expand Down
17 changes: 9 additions & 8 deletions goaccess_metric_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@
> Countries reached
> Output format: {continent, country, total_visits, unique_visits, start_date, end_date}
"""
def parse_geolocation_info():
def parse_geolocation_info(write_type):

with open(f'{OUTPUT_PATH}/geolocation_metrics.csv', 'w', newline='') as gfile:
with open(f'{OUTPUT_PATH}/geolocation_metrics.csv', write_type, newline='') as gfile:
writer = csv.writer(gfile)
fields = ["continent", "country", "total_visits", "unique_visits", "start_metric_date", "end_metric_date"]
writer.writerow(fields)
Expand Down Expand Up @@ -111,13 +111,14 @@ def parse_requests_info(status_code, write_type):
sfile.close()


wr="w"
if args.use_existing:
wr="a"

if args.general:
parse_geolocation_info()
elif args.partial:
if args.use_existing:
parse_requests_info(args.status_code, "a")
else:
parse_requests_info(args.status_code, "w")
parse_geolocation_info(wr)
if args.partial:
parse_requests_info(args.status_code, wr)



Expand Down

0 comments on commit 4423aa4

Please sign in to comment.