Ejemplo n.º 1
0
def get_count_stats():
    day_ago = datetime.datetime.now() - datetime.timedelta(hours=24)
    week_ago = datetime.datetime.now() - datetime.timedelta(days=7)
    month_ago = datetime.datetime.now() - datetime.timedelta(days=30)
    incoming = {
        "today": ReceiveStatistic.select().where(ReceiveStatistic.created_at >= day_ago).count(),
        "week": ReceiveStatistic.select().where(ReceiveStatistic.created_at >= week_ago).count(),
        "month": ReceiveStatistic.select().where(ReceiveStatistic.created_at >= month_ago).count(),
        "all_time": ReceiveStatistic.select().count(),
    }
    outgoing = {
        "today": WorkerReceiveStatistic.select().where(WorkerReceiveStatistic.created_at >= day_ago).count(),
        "week": WorkerReceiveStatistic.select().where(WorkerReceiveStatistic.created_at >= week_ago).count(),
        "month": WorkerReceiveStatistic.select().where(WorkerReceiveStatistic.created_at >= month_ago).count(),
        "all_time": WorkerReceiveStatistic.select().count(),
    }
    distinct_nodes = {
        "all": Node.select().count(),
        "https": Node.select().where(Node.https==True).count(),
    }
    processing = {
        "workers": get_worker_count(),
        "queue_jobs": len(public_queue),
    }
    return incoming, outgoing, distinct_nodes, processing
Ejemplo n.º 2
0
def get_count_stats():
    day_ago = datetime.datetime.now() - datetime.timedelta(hours=24)
    week_ago = datetime.datetime.now() - datetime.timedelta(days=7)
    month_ago = datetime.datetime.now() - datetime.timedelta(days=30)
    incoming = {
        "today":
        ReceiveStatistic.select().where(
            ReceiveStatistic.created_at >= day_ago).count(),
        "week":
        ReceiveStatistic.select().where(
            ReceiveStatistic.created_at >= week_ago).count(),
        "month":
        ReceiveStatistic.select().where(
            ReceiveStatistic.created_at >= month_ago).count(),
        "all_time":
        ReceiveStatistic.select().count(),
    }
    outgoing = {
        "today":
        WorkerReceiveStatistic.select().where(
            WorkerReceiveStatistic.created_at >= day_ago).count(),
        "week":
        WorkerReceiveStatistic.select().where(
            WorkerReceiveStatistic.created_at >= week_ago).count(),
        "month":
        WorkerReceiveStatistic.select().where(
            WorkerReceiveStatistic.created_at >= month_ago).count(),
        "all_time":
        WorkerReceiveStatistic.select().count(),
    }
    distinct_nodes = {
        "all": Node.select().count(),
    }
    processing = {
        "workers": get_worker_count(),
        "queue_jobs": len(public_queue),
    }
    profiles = {
        "all": Profile.select().count(),
    }
    return incoming, outgoing, distinct_nodes, processing, profiles
Ejemplo n.º 3
0
def log_receive_statistics(sender_host):
    """Add a ReceiveStatistic entry to the database."""
    ReceiveStatistic.create(sender_host=sender_host)
Ejemplo n.º 4
0
def log_receive_statistics(sender_host):
    """Add a ReceiveStatistic entry to the database."""
    ReceiveStatistic.create(sender_host=sender_host)
Ejemplo n.º 5
0
 def test_receive_statistics_logged(self):
     log_receive_statistics("example.com")
     assert ReceiveStatistic.select().count() == 1
     statistic = ReceiveStatistic.select().first()
     assert statistic.sender_host == "example.com"