def push_banned_users(self): from app.models import UserProfile client = Client(server='http://holodeck.praekelt.com') ban_1 = UserProfile.objects.filter(banned=True, ban_duration=1).count() ban_3 = UserProfile.objects.filter(banned=True, ban_duration=3).count() banned = UserProfile.objects.filter(banned=True).count() client.send( samples=( ("Community Ban", ban_1), ("Moderator Ban", ban_3), ("Total", banned), ), api_key='43d20f761ec14355afc252ed9d7cb995', timestamp=datetime.now(), )
def push(self, datetime_obj): range_end = datetime_obj range_start = range_end - timedelta(days=1) client = Client(server='http://holodeck.praekelt.com') ga_service = utils.get_service() # Get uniques from GA print "Fetching uniques from GA" query = ga_service.data().ga().get( ids='ga:%d' % GA_PROFILE_ID, start_date=str(range_start.date()), end_date=str(range_end.date()), segment='gaid::-11', # mobile users only metrics='ga:visitors' ) unique_users = query.execute()['totalsForAllResults']['ga:visitors'] # Get pageviews from GA print "Fetching pageviews from GA" query = ga_service.data().ga().get( ids='ga:%d' % GA_PROFILE_ID, start_date=str(range_start.date()), end_date=str(range_end.date()), segment='gaid::-11', # mobile users only metrics='ga:pageviews' ) pageviews = query.execute()['totalsForAllResults']['ga:pageviews'] # Get mean response time print "Determining mean response time." p = subprocess.Popen(["ab", "-c", "10", "-n", "10", "http://askapp.mobi/"], stdout=subprocess.PIPE) out, err = p.communicate() mean_response_time = re.findall('Total:.*?\d+.*?(\d+)', out)[0] client.send( samples=( ("Pageviews", pageviews), ("Unique Users", unique_users), ("New Registrations", User.objects.filter(date_joined__range=(range_start, range_end)).count()), ("Response Time(ms)", mean_response_time), ), api_key='6378ed3021ea4073a26b4d00e26c75c6', timestamp=datetime_obj, )
def push_cumulative(self, datetime_obj): #Don't use stats older than Vlive launch date if datetime_obj < init_date: return client = Client(server='http://holodeck.praekelt.com') ga_service = utils.get_service() range_end = datetime_obj range_start_cumulative = datetime(2013, 1, 1) vlive_users = User.objects.extra( where=['last_login - date_joined>%s'], params=[timedelta(seconds=60)] ).filter(userprofile__origin='vlive') print "Pushing Mobi Users Cumulative" client.send( samples=( ("Unique Users", vlive_users.filter( date_joined__lte=range_end).count()), ("Registration", vlive_users.filter( date_joined__lte=range_end, userprofile__delivery_date__isnull=False).count()), ), api_key='1db783e1c9d344e7a39ca685f210633e', timestamp=datetime_obj, ) print "Pushing Mobi Pageviews Cumulative" query = ga_service.data().ga().get( ids='ga:%d' % GA_PROFILE_ID, start_date=str(range_start_cumulative.date()), end_date=str(range_end.date()), metrics='ga:pageviews', segment='gaid::-11', # mobile users only ) results = query.execute() client.send( samples=( ("Pageviews", results['totalsForAllResults']['ga:pageviews']), ), api_key='1a12d02a71734a1eaacc66f684261d76', timestamp=datetime_obj, )
def push_cumulative(self, datetime_obj): #Don't use stats older than Mxit launch date if datetime_obj < init_date: return client = Client(server='http://holodeck.praekelt.com') ga_service = utils.get_service() range_end = datetime_obj range_start_cumulative = datetime(2013, 1, 1) mxit_users = User.objects.filter(userprofile__origin='mxit') print "Pushing Mxit Users Cumulative" client.send( samples=( ("Unique Users", mxit_users.filter( date_joined__lte=range_end).count()), ("Registration", mxit_users.filter( date_joined__lte=range_end, userprofile__delivery_date__isnull=False).count()), ), api_key=HOLODECK_API_KEYS['users_cumulative'], timestamp=datetime_obj, ) print "Pushing Mxit Pageviews Cumulative" query = ga_service.data().ga().get( ids='ga:%d' % GA_PROFILE_ID, start_date=str(range_start_cumulative.date()), end_date=str(range_end.date()), metrics='ga:pageviews', segment='gaid::-11', # mobile users only ) results = query.execute() client.send( samples=( ("Pageviews", results['totalsForAllResults']['ga:pageviews']), ), api_key=HOLODECK_API_KEYS['pageviews_cumulative'], timestamp=datetime_obj, )
#!/usr/bin/env python from datetime import datetime import random import time from photon import Client client = Client( server="http://localhost:8000/", ) while True: # Push random data to a single line chart metric. client.send( samples=(("Indicator", random.randint(100, 999)),), api_key='1', timestamp=datetime.now(), ) # Push random data to a multi-line chart metric. client.send( samples=( ("Line 1", random.randint(100, 999)), ("Line 2", random.randint(100, 999)), ("Line 3", random.randint(100, 999)), ("Line 4", random.randint(100, 999)), ("Line 5", random.randint(100, 999)), ), api_key='2', timestamp=datetime.now(), )
def handle(self, *args, **options): users = User.objects.filter(is_active=True, is_staff=False) questionnaires = Questionnaire.objects.filter(active=True) client = Client(server=settings.HOLODECK_URL) now = datetime.datetime.now() for questionnaire in questionnaires: # check if we have holodeck keys for the questionnaire pending_key = self._get_holodeck_key( questionnaire, constants.QUESTIONNAIRE_PENDING) completed_key = self._get_holodeck_key( questionnaire, constants.QUESTIONNAIRE_COMPLETED) incomplete_key = self._get_holodeck_key( questionnaire, constants.QUESTIONNAIRE_INCOMPLETE) rejected_key = self._get_holodeck_key( questionnaire, constants.QUESTIONNAIRE_REJECTED) # collect the stats for the questionnaire if pending_key or completed_key or incomplete_key or rejected_key: pending = incomplete = completed = rejected = 0 for user in users: status = questionnaire.get_status(user) if status == constants.QUESTIONNAIRE_PENDING: pending += 1 elif status == constants.QUESTIONNAIRE_REJECTED: rejected += 1 elif status == constants.QUESTIONNAIRE_INCOMPLETE: incomplete += 1 elif status == constants.QUESTIONNAIRE_COMPLETED: completed += 1 # send the pending stats to holodeck if pending_key: try: client.send(samples=(("Total", pending), ), api_key=pending_key, timestamp=now) except HTTPError: logger.error("Could not connect to holodeck service") # send the incomplete stats to holodeck if incomplete_key: try: client.send(samples=(("Total", incomplete), ), api_key=incomplete_key, timestamp=now) except HTTPError: logger.error("Could not connect to holodeck service") # send the complete stats to holodeck if completed_key: try: client.send(samples=(("Total", completed), ), api_key=completed_key, timestamp=now) except HTTPError: logger.error("Could not connect to holodeck service") # send the rejected stats to holodeck if rejected_key: try: client.send(samples=(("Total", rejected), ), api_key=rejected_key, timestamp=now) except HTTPError: logger.error("Could not connect to holodeck service")
#!/usr/bin/env python import os os.environ.setdefault("DJANGO_SETTINGS_MODULE", "sentry_conf") from datetime import datetime from photon import Client from sentry.models import Event from sentry.models import Project client = Client(server="http://holodeck.praekelt.com", ) client.send( samples=(('Mom Connect Daily Errors', Event.objects.filter(project__slug='mom-connect').count())), api_key='3bc93b5e0f8d4c30936ad5786b185007', timestamp=datetime.now(), ) client.send( samples=(('Central Daily Errors', Event.objects.filter(project__slug='praekelt-central').count())), api_key='160d43a54e244ee59d5486cc384cade0', timestamp=datetime.now(), ) client.send( samples=(('Ummeli Daily Errors', Event.objects.filter(project__slug='ummeli').count())), api_key='e54bb71a19c34f29aafdf18dcbf12941',
def push(self, datetime_obj): range_end = datetime_obj range_start = range_end - timedelta(days=7) #Don't use stats older than Mxit launch date if datetime_obj < init_date: return client = Client(server='http://holodeck.praekelt.com') ga_service = utils.get_service() mxit_users = User.objects.filter(userprofile__origin='mxit') print "Pushing Mxit Weekly Users" client.send( samples=( ("Unique Users", mxit_users.filter( date_joined__range=(range_start, range_end)).count()), ("Registration", mxit_users.filter( date_joined__range=(range_start, range_end), userprofile__delivery_date__isnull=False).count()), ), api_key=HOLODECK_API_KEYS['users_weekly'], timestamp=datetime_obj, ) print "Pushing Mxit Weekly Pageviews" query = ga_service.data().ga().get( ids='ga:%d' % GA_PROFILE_ID, start_date=str(range_start.date()), end_date=str(range_end.date()), segment='gaid::-11', # mobile users only metrics='ga:pageviews' ) results = query.execute() client.send( samples=( ("Pageviews", results['totalsForAllResults']['ga:pageviews']), ), api_key=HOLODECK_API_KEYS['pageviews_weekly'], timestamp=datetime_obj, ) print "Pushing Mxit User Types" query = ga_service.data().ga().get( ids='ga:%d' % GA_PROFILE_ID, start_date=str(range_start.date()), end_date=str(range_end.date()), metrics='ga:visitors', dimensions='ga:visitorType', segment='gaid::-11', # mobile users only ) results = query.execute() if 'rows' in results: client.send( samples=[(row[0], int(row[1])) for row in results['rows']], api_key=HOLODECK_API_KEYS['visitor_types'], timestamp=datetime_obj, ) print "Pushing Mxit User Phase" mxit_userprofile = UserProfile.objects.filter(origin='mxit') client.send( samples=( ("Prenatal", mxit_userprofile.filter( delivery_date__gte=datetime_obj).count()), ("Postnatal", mxit_userprofile.filter( delivery_date__lt=datetime_obj).count()), ), api_key=HOLODECK_API_KEYS['user_phase'], timestamp=datetime_obj, )
#!/usr/bin/env python from datetime import datetime import random import time from photon import Client client = Client(server="http://localhost:8000/", ) while True: # Push random data to a single line chart metric. client.send( samples=(("Indicator", random.randint(100, 999)), ), api_key='1', timestamp=datetime.now(), ) # Push random data to a multi-line chart metric. client.send( samples=( ("Line 1", random.randint(100, 999)), ("Line 2", random.randint(100, 999)), ("Line 3", random.randint(100, 999)), ("Line 4", random.randint(100, 999)), ("Line 5", random.randint(100, 999)), ), api_key='2', timestamp=datetime.now(), ) # Push random data to a sample deviation metric. client.send(
#!/usr/bin/env python import os os.environ.setdefault("DJANGO_SETTINGS_MODULE", "sentry_conf") from datetime import datetime from photon import Client from sentry.models import Event from sentry.models import Project client = Client( server="http://holodeck.praekelt.com", ) client.send( samples=(('Mom Connect Daily Errors', Event.objects.filter(project__slug='mom-connect').count())), api_key='3bc93b5e0f8d4c30936ad5786b185007', timestamp=datetime.now(), ) client.send( samples=(('Central Daily Errors', Event.objects.filter(project__slug='praekelt-central').count())), api_key='160d43a54e244ee59d5486cc384cade0', timestamp=datetime.now(), ) client.send( samples=(('Ummeli Daily Errors', Event.objects.filter(project__slug='ummeli').count())), api_key='e54bb71a19c34f29aafdf18dcbf12941',
def push_cumulative(self, datetime_obj): # Don't use stats older than Unicore launch date if datetime_obj < init_date: return client = Client(server='http://holodeck.praekelt.com') ga_service = utils.get_service() range_end = datetime_obj range_start_cumulative = init_date unicore_users = User.objects.filter(userprofile__origin=PROFILE_ORIGIN) print "Pushing Zambia Users Cumulative" query = ga_service.data().ga().get( ids='ga:%d' % GA_PROFILE_ID, start_date=str(range_start_cumulative.date()), end_date=str(range_end.date()), metrics='ga:users', segment='gaid::-11', # mobile users only ) results = query.execute() client.send( samples=( ("GA Users", results['totalsForAllResults']['ga:users']), ("Registration", unicore_users.filter( date_joined__range=(range_start_cumulative, range_end)).count()), ), api_key=HOLODECK_API_KEYS['users_cumulative'], timestamp=datetime_obj, ) print "Pushing Zambia Pageviews Cumulative" query = ga_service.data().ga().get( ids='ga:%d' % GA_PROFILE_ID, start_date=str(range_start_cumulative.date()), end_date=str(range_end.date()), metrics='ga:pageviews', segment='gaid::-11', # mobile users only ) results = query.execute() client.send( samples=( ("Pageviews", results['totalsForAllResults']['ga:pageviews']), ), api_key=HOLODECK_API_KEYS['pageviews_cumulative'], timestamp=datetime_obj, ) print "Pushing Zambia Comments Cumulative" unicore_comments = Comment.objects.filter( user__userprofile__origin=PROFILE_ORIGIN) client.send( samples=( ("Mobi", unicore_comments.filter( submit_date__range=(range_start_cumulative, range_end)).count()), ), api_key=HOLODECK_API_KEYS['comments_cumulative'], timestamp=datetime_obj, )
def handle(self, *args, **options): users = User.objects.filter(is_active=True, is_staff=False) questionnaires = Questionnaire.objects.filter(active=True) client = Client(server=settings.HOLODECK_URL) now = datetime.datetime.now() for questionnaire in questionnaires: # check if we have holodeck keys for the questionnaire pending_key = self._get_holodeck_key( questionnaire, constants.QUESTIONNAIRE_PENDING) completed_key = self._get_holodeck_key( questionnaire, constants.QUESTIONNAIRE_COMPLETED) incomplete_key = self._get_holodeck_key( questionnaire, constants.QUESTIONNAIRE_INCOMPLETE) rejected_key = self._get_holodeck_key( questionnaire, constants.QUESTIONNAIRE_REJECTED) # collect the stats for the questionnaire if pending_key or completed_key or incomplete_key or rejected_key: pending = incomplete = completed = rejected = 0 for user in users: status = questionnaire.get_status(user) if status == constants.QUESTIONNAIRE_PENDING: pending += 1 elif status == constants.QUESTIONNAIRE_REJECTED: rejected += 1 elif status == constants.QUESTIONNAIRE_INCOMPLETE: incomplete += 1 elif status == constants.QUESTIONNAIRE_COMPLETED: completed += 1 # send the pending stats to holodeck if pending_key: try: client.send( samples=(("Total", pending),), api_key=pending_key, timestamp=now ) except HTTPError: logger.error("Could not connect to holodeck service") # send the incomplete stats to holodeck if incomplete_key: try: client.send( samples=(("Total", incomplete),), api_key=incomplete_key, timestamp=now ) except HTTPError: logger.error("Could not connect to holodeck service") # send the complete stats to holodeck if completed_key: try: client.send( samples=(("Total", completed),), api_key=completed_key, timestamp=now ) except HTTPError: logger.error("Could not connect to holodeck service") # send the rejected stats to holodeck if rejected_key: try: client.send( samples=(("Total", rejected),), api_key=rejected_key, timestamp=now ) except HTTPError: logger.error("Could not connect to holodeck service")
def push(self, datetime_obj): range_end = datetime_obj range_start = range_end - timedelta(days=7) #Don't use stats older than Vlive launch date if datetime_obj < init_date: return client = Client(server='http://holodeck.praekelt.com') ga_service = utils.get_service() vlive_users = User.objects.extra( where=['last_login - date_joined>%s'], params=[timedelta(seconds=60)] ).filter(userprofile__origin='vlive') print "Pushing Vlive Weekly Users" client.send( samples=( ("Unique Users", vlive_users.filter( date_joined__range=(range_start, range_end)).count()), ("Registration", vlive_users.filter( date_joined__range=(range_start, range_end), userprofile__delivery_date__isnull=False).count()), ), api_key='fb14e8498e564872b05ceda5fc0e5400', timestamp=datetime_obj, ) print "Pushing Vlive Weekly Pageviews" query = ga_service.data().ga().get( ids='ga:%d' % GA_PROFILE_ID, start_date=str(range_start.date()), end_date=str(range_end.date()), segment='gaid::-11', # mobile users only metrics='ga:pageviews' ) results = query.execute() client.send( samples=( ("Pageviews", results['totalsForAllResults']['ga:pageviews']), ), api_key='bf0eabed2a7346bb99b93816c6964ffc', timestamp=datetime_obj, ) print "Pushing Vlive User Types" query = ga_service.data().ga().get( ids='ga:%d' % GA_PROFILE_ID, start_date=str(range_start.date()), end_date=str(range_end.date()), metrics='ga:visitors', dimensions='ga:visitorType', segment='gaid::-11', # mobile users only ) results = query.execute() if 'rows' in results: client.send( samples=[(row[0], int(row[1])) for row in results['rows']], api_key='f1351ed05c2d4208a843be585928a878', timestamp=datetime_obj, ) print "Pushing Mobi User Phase" vlive_userprofile = UserProfile.objects.filter(origin='vlive') client.send( samples=( ("Prenatal", vlive_userprofile.filter( delivery_date__gte=datetime_obj).count()), ("Postnatal", vlive_userprofile.filter( delivery_date__lt=datetime_obj).count()), ), api_key='db14a155cb9c49a2b6c2185246b9cf10', timestamp=datetime_obj, )