Beispiel #1
0
def cmd_hours_metrics():
    days = {}
    for account in CONFIG.accounts:
        info(account.email, ':')
        imap = connectIMAP(account)
        try:
            hoursMetricsAccount(imap, days)
        finally:
            imap.logout()
        # open readonly b/c otherwise messages will be marked as read '\\Seen'
    metrics = []
    for day in days.keys():
        counter = days[day]
        tstamp = datetime.strptime(day, '%Y-%m-%d')
        tstamp += timedelta(hours=12)  # midday
        tstamp = int(tstamp.strftime('%s'))
        info('day %s/%d' % (day, tstamp))
        for h in range(24):
            info('%d: %d' % (h, counter[h]))
            metrics.append(('daily.by_hour.%d.count' % h, counter[h], tstamp))
    if CONFIG.graphiteHost is not None:
        gc = GraphiteClient(prefix='spam',
                            graphite_server=CONFIG.graphiteHost,
                            graphite_port=CONFIG.graphitePort,
                            system_name='')
        gc.send_list(metrics)
Beispiel #2
0
def recordSpamMetrics(messages):
    if CONFIG.graphiteHost is not None:
        gc = GraphiteClient(prefix='spam',
                            graphite_server=CONFIG.graphiteHost,
                            graphite_port=CONFIG.graphitePort,
                            system_name='')
        durations = []
        for m in messages:
            if m.date:
                durations.append(('duration.detect_minutes', m.ageMinutes()))
                gc.send('daily.by_hour.%d.count' % m.date.hour, 1)
        gc.send_list(durations)
Beispiel #3
0
def write_player_data(url, players):
    """ Writes a bunch of player data to the time-series database.

    players is a list of dicts with the key "name" for the player's
    username and another key for each stat we are tracking.

    url is the url for the graphite instance to write to.
    """
    timestamp = int(time.time())
    points = []
    for player in players:
        for stat in player:
            if stat != 'name':
                points.append(
                    ('grid.{}.{}'.format(stat, player['name']), player[stat]))
    host, port = url.split(':')
    port = int(port)
    client = GraphiteClient(host, port, formatter=TemplateFormatter("{name}"))
    client.send_list(points, timestamp=timestamp)
Beispiel #4
0
def recordDailyMetrics(emailLog, counts):
    msg = '\nspam-rescore moves for the last 24 hours:\n'
    total = 0
    metrics = []
    for email in counts.keys():
        msg += '%s: %d message(s)\n' % (email, counts[email])
        metrics.append(
            ('daily.by_email.' + email.replace('@', '_').replace('.', '_'),
             counts[email]))
        total += counts[email]

    if CONFIG.emailDailySummary:
        emailLog.info(msg)
    metrics.append(('daily.total', total))

    if CONFIG.graphiteHost is not None:
        gc = GraphiteClient(prefix='spam',
                            graphite_server=CONFIG.graphiteHost,
                            graphite_port=CONFIG.graphitePort,
                            system_name='')
        gc.send_list(metrics)