Ejemplo n.º 1
0
def main():
    usage = "norc_reporter [--executors] [--schedulers] [--queues]"
    
    def bad_args(message):
        print message
        print usage
        sys.exit(2)
    
    parser = OptionParser(usage)
    parser.add_option("-e", "--executors", action="store_true",
        help="Report on executors.")
    parser.add_option("-s", "--schedulers", action="store_true",
        help="Report on schedulers.")
    parser.add_option("-q", "--queues", action="store_true",
        help="Report on queues.")
    parser.add_option("-t", "--timeframe",
        help="Filter to only things in this timeframe (e.g. '10m').")
    parser.add_option("-n", "--number", default=20, type="int",
        help="The number of items to display.")
    
    (options, args) = parser.parse_args()
    since = parse_since(options.timeframe)
    
    if not any([options.executors, options.schedulers, options.queues]):
        options.executors = True
    
    print time.strftime('[%Y/%m/%d %H:%M:%S]'),
    if since:
        print 'from the last %s.' % options.timeframe,
    print ''
    
    def print_report(report):
        data_objects = report.get_all()
        data_objects = report.since_filter(data_objects, since)
        data_objects = report.order_by(data_objects, None)
        data_list = reports.generate(data_objects, report, dict(since=since))
        if options.number > 0:
            data_list = data_list[:options.number]
        if len(data_list) > 0:
            table = [report.headers] + [[str(o[untitle(h)])
                for h in report.headers] for o in data_list]
            pprint_table(sys.stdout, table)
        else:
            print 'None found.'

    if options.executors:
        print '\n## Executors ##'
        print_report(reports.executors)
    if options.schedulers:
        print '\n## Schedulers ##'
        print_report(reports.schedulers)
    if options.queues:
        print '\n## Queues ##'
        print_report(reports.queues)
Ejemplo n.º 2
0
def main():
    usage = "norc_reporter [--executors] [--schedulers] [--queues]"
    
    def bad_args(message):
        print message
        print usage
        sys.exit(2)
    
    parser = OptionParser(usage)
    parser.add_option("-e", "--executors", action="store_true",
        help="Report on executors.")
    parser.add_option("-s", "--schedulers", action="store_true",
        help="Report on schedulers.")
    parser.add_option("-q", "--queues", action="store_true",
        help="Report on queues.")
    parser.add_option("-t", "--timeframe",
        help="Filter to only things in this timeframe (e.g. '10m').")
    parser.add_option("-n", "--number", default=20, type="int",
        help="The number of items to display.")
    
    (options, args) = parser.parse_args()
    since = parse_since(options.timeframe)
    
    if not any([options.executors, options.schedulers, options.queues]):
        options.executors = True
    
    print time.strftime('[%Y/%m/%d %H:%M:%S]'),
    if since:
        print 'from the last %s.' % options.timeframe,
    print ''
    
    def print_report(report):
        data_objects = report.get_all()
        data_objects = report.since_filter(data_objects, since)
        data_objects = report.order_by(data_objects, None)
        data_list = reports.generate(data_objects, report, dict(since=since))
        if options.number > 0:
            data_list = data_list[:options.number]
        if len(data_list) > 0:
            table = [report.headers] + [[str(o[untitle(h)])
                for h in report.headers] for o in data_list]
            pprint_table(sys.stdout, table)
        else:
            print 'None found.'

    if options.executors:
        print '\n## Executors ##'
        print_report(reports.executors)
    if options.schedulers:
        print '\n## Schedulers ##'
        print_report(reports.schedulers)
    if options.queues:
        print '\n## Queues ##'
        print_report(reports.queues)
Ejemplo n.º 3
0
def get_data(request, content_type, content_id=None, detail_type=None):
    """Retrieves and structures data, then returns it as a JSON object.
    
    Returns a JSON object containing data on given content type.
    If content_id is provided, data on the details of the content_type
    object associated with that id will be returned.  The data is
    filtered by GET parameters in the request.
    
    """
    if not content_type in reports.all:
        raise ValueError("Invalid content type '%s'." % content_type)
    report = reports.all[content_type]
    params = {}
    for k, v in request.GET.iteritems():
        params[str(k)] = v
    params['since'] = parse_since(params.get('since'))
    if detail_type:
        if not detail_type in report.details:
            raise ValueError("Invalid detail type '%s'." % detail_type)
        data_key = detail_type
        data_set = report.details[data_key](content_id, **params)
    else:
        data_key = content_type
        data_set = report(content_id)
    report = reports.all[data_key]
    if isinstance(data_set, QuerySet):
        print data_key
        data_set = report.since_filter(data_set, params['since'])
        data_set = report.order_by(data_set, params.get('order'))
    page, page_data = paginate(request, data_set)
    json_data = {
        'data': reports.generate(page.object_list, report, params),
        'page': page_data,
    }
    json = simplejson.dumps(json_data, cls=JSONObjectEncoder)
    return http.HttpResponse(json, mimetype="json")
Ejemplo n.º 4
0
Archivo: reports.py Proyecto: tml/norc
def date_ended_since(query, since):
    if type(since) == str:
        since = parse_since(since)
    return query.exclude(ended__lt=since) if since else query
Ejemplo n.º 5
0
 def since(self, since):
     """Date ended since a certain time, or not ended."""
     if type(since) == str:
         since = parse_since(since)
     return self.exclude(ended__lt=since) if since else self
Ejemplo n.º 6
0
 def since(self, since):
     if type(since) == str:
         since = parse_since(since)
     return self.exclude(ended__lt=since) if since else self
Ejemplo n.º 7
0
 def since(self, since):
     """Date ended since a certain time, or not ended."""
     if type(since) == str:
         since = parse_since(since)
     return self.exclude(ended__lt=since) if since else self
Ejemplo n.º 8
0
def date_ended_since(query, since):
    if type(since) == str:
        since = parse_since(since)
    return query.exclude(ended__lt=since) if since else query