blob: 1da4a82ed65f74ac8f692864cd36a41012ac1f3c [file] [log] [blame]
Paul Hobbs29c37b32015-12-11 16:24:27 -08001#! /usr/bin/python
2
3# Copyright 2015 The Chromium OS Authors. All rights reserved.
4# Use of this source code is governed by a BSD-style license that can be
5# found in the LICENSE file.
6
7"""Counts the number of jobs created in the last 24 hours."""
8
9import argparse
Paul Hobbsebc34602015-12-16 14:52:48 -080010from datetime import datetime, timedelta
Paul Hobbs29c37b32015-12-11 16:24:27 -080011import sys
12
13import common
14from autotest_lib.frontend import setup_django_environment
15from autotest_lib.frontend.afe import models
16from autotest_lib.client.common_lib.cros.graphite import autotest_stats
17
18
19def number_of_jobs_since(delta):
20 """Returns the number of jobs kicked off in the last |duration| minutes.
21
22 @param delta: A timedelta which indicates the maximum age of the jobs to count
23 """
Paul Hobbsebc34602015-12-16 14:52:48 -080024 cutoff = datetime.now() - delta
Paul Hobbs29c37b32015-12-11 16:24:27 -080025 return models.Job.objects.filter(created_on__gt=cutoff).count()
26
27
28def main():
29 """Counts the number of AFE jobs in the last day, then pushes the count to statsd"""
30 parser = argparse.ArgumentParser(
31 description=('A script which records the number of afe jobs run in a time interval.'))
32 parser.parse_args(sys.argv[1:])
Paul Hobbsebc34602015-12-16 14:52:48 -080033 count = number_of_jobs_since(timedelta(days=1))
Paul Hobbs29c37b32015-12-11 16:24:27 -080034 autotest_stats.Gauge('jobs_rate').send('afe_daily_count', count)
35
36
37if __name__ == '__main__':
38 main()