Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #1039 from internetarchive/fix-ipstats
fixing date str formatter to ref correct nginx log file
  • Loading branch information
mekarpeles committed Jul 28, 2018
2 parents 8a6eb82 + 9570d46 commit d70d3f9
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions scripts/ipstats.py
Expand Up @@ -22,7 +22,6 @@ def run_piped(cmds, stdin=None):
"""
prev_stdout = stdin
for cmd in cmds:
print(' '.join(cmd))
p = subprocess.Popen(cmd, stdin=prev_stdout, stdout=subprocess.PIPE)
prev_stdout = p.stdout
return prev_stdout
Expand Down Expand Up @@ -53,17 +52,16 @@ def count_unique_ips_for_day(day):
basedir = "/var/log/nginx/"

# Cat the logs we'll be processing
print(basedir)
log_file = basedir + "access.log"
zipped_log_file = log_file + day.strftime("-%Y%m%day.gz")
zipped_log_file = log_file + day.strftime("-%Y%m%d.gz")

if os.path.exists(zipped_log_file):
cat_log_cmd = ["zcat", zipped_log_file]
elif day > (datetime.today() - timedelta(days=5)):
# if recent day, then they haven't been compressed yet
cat_log_cmd = ["cat", log_file]
else:
raise IndexError("Cannot find log file for " + day.strftime("%Y-%m-%day"))
raise IndexError("Cannot find log file for " + day.strftime("%Y-%m-%d"))

out = run_piped([
cat_log_cmd, # cat the server logs
Expand All @@ -88,7 +86,6 @@ def main(config, start, end):

current = start
while current <= end:
print(current)
try:
count = count_unique_ips_for_day(current)
store_data(dict(visitors=count), current)
Expand Down

0 comments on commit d70d3f9

Please sign in to comment.