diff --git a/examples/config.py b/examples/config.py index 11c998a8..5f8dfdcf 100644 --- a/examples/config.py +++ b/examples/config.py @@ -165,6 +165,10 @@ wiki_password = "1234" # machine. update_stats = False +# When used with stats, this is a list of IP addresses that are ignored for +# calculation purposes. +stats_ignore = [] + # Use the following to push stats to a Carbon instance: stats_to_carbon = False carbon_host = '0.0.0.0' diff --git a/fdroidserver/common.py b/fdroidserver/common.py index faa1e767..aeb4e6da 100644 --- a/fdroidserver/common.py +++ b/fdroidserver/common.py @@ -49,6 +49,7 @@ def get_default_config(): 'gradle': 'gradle', 'sync_from_local_copy_dir': False, 'update_stats': False, + 'stats_ignore': [], 'stats_to_carbon': False, 'repo_maxage': 0, 'build_server_always': False, diff --git a/fdroidserver/stats.py b/fdroidserver/stats.py index 99534d5b..4c2a5eff 100644 --- a/fdroidserver/stats.py +++ b/fdroidserver/stats.py @@ -154,20 +154,26 @@ def main(): p = subprocess.Popen(["zcat", logfile], stdout=subprocess.PIPE) matches = (logsearch(line) for line in p.stdout) for match in matches: - if match and match.group('statuscode') == '200': - uri = match.group('uri') - if uri.endswith('.apk'): - _, apkname = os.path.split(uri) - app = knownapks.getapp(apkname) - if app: - appid, _ = app - today['apps'][appid] += 1 - # Strip the '.apk' from apkname - appver = apkname[:-4] - today['appsver'][appver] += 1 - else: - if apkname not in today['unknown']: - today['unknown'].append(apkname) + if not match: + continue + if match.group('statuscode') != '200': + continue + if match.group('ip') in config['stats_ignore']: + continue + uri = match.group('uri') + if not uri.endswith('.apk'): + continue + _, apkname = os.path.split(uri) + app = knownapks.getapp(apkname) + if app: + appid, _ = app + today['apps'][appid] += 1 + # Strip the '.apk' from apkname + appver = apkname[:-4] + today['appsver'][appver] += 1 + else: + if apkname not in today['unknown']: + today['unknown'].append(apkname) # Save calculated aggregate data for today to cache with open(agg_path, 'w') as f: