From dc789a7ac9ecbb8265f52deeb26e0bda2043c593 Mon Sep 17 00:00:00 2001 From: Ciaran Gultnieks Date: Thu, 23 May 2013 11:04:57 +0100 Subject: [PATCH] Option to push stats to graphite --- config.sample.py | 5 +++++ fdroidserver/stats.py | 18 ++++++++++++++++-- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/config.sample.py b/config.sample.py index f8cedc23..63bdb5d7 100644 --- a/config.sample.py +++ b/config.sample.py @@ -76,6 +76,11 @@ wiki_password = "1234" #machine. update_stats = False +#Use the following to push stats to a Carbon instance: +stats_to_carbon = False +carbon_host = '0.0.0.0' +carbon_port = 2003 + #Set this to true to always use a build server. This saves specifying the #--server option on dedicated secure build server hosts. diff --git a/fdroidserver/stats.py b/fdroidserver/stats.py index 8f57b202..f59d7a2c 100644 --- a/fdroidserver/stats.py +++ b/fdroidserver/stats.py @@ -29,12 +29,24 @@ from optparse import OptionParser import HTMLParser import paramiko import common +import socket + + +carbon_socket = None +def carbon_send(key, value): + global carbon_socket + if not carbon_socket: + carbon_socket = socket.socket() + carbon_socket = carbon_socket.connect((carbon_host, carbon_port)) + msg = '%s %d 42 %d\n' % (key, value, int(time.time())) + carbon_socket.sendall(msg) def main(): # Read configuration... - global update_stats + global update_stats, stats_to_carbon update_stats = False + stats_to_carbon = False execfile('config.py', globals()) if not update_stats: @@ -74,7 +86,7 @@ def main(): ssh.connect('f-droid.org', username='fdroid', timeout=10, key_filename=webserver_keyfile) ftp = ssh.open_sftp() - ftp.get_channel().settimeout(15) + ftp.get_channel().settimeout(60) print "...connected" ftp.chdir('logs') @@ -135,6 +147,8 @@ def main(): alldownloads = 0 for app, count in apps.iteritems(): lst.append(app + " " + str(count)) + if stats_to_carbon: + carbon_send('fdroid.download.' + app.replace('.', '_'), count) alldownloads += count lst.append("ALL " + str(alldownloads)) f = open('stats/total_downloads_app.txt', 'w')