Beispiel #1
0
def last_stats(req, service_id, cluster_id):

    return_data = {
        'rate': '(error)',
        'mean': '(error)',
        'mean_trend': '(error)',
        }

    try:
        start, stop = last_hour_start_stop(datetime.utcnow())
        response = req.zato.client.invoke('zato.stats.get-by-service', {'service_id': service_id, 'start':start, 'stop':stop})

        if response.has_data:
            for key in return_data:
                value = getattr(response.data, key) or ''

                if value and key.endswith('trend') and value != ZATO_NONE:
                    value = [int(float(elem)) for elem in value.split(',')]

                if value == '0.0':
                    value = '<0.1'

                return_data[key] = value if value != ZATO_NONE else '0'

    except Exception, e:
        msg = 'Caught an exception while invoking zato.service.get-by-service, e:[{}]'.format(format_exc(e))
        logger.error(msg)
Beispiel #2
0
def last_stats(req, service_id, cluster_id):

    return_data = {
        'rate': '(error)',
        'mean': '(error)',
        'mean_trend': '(error)',
    }

    try:
        start, stop = last_hour_start_stop(datetime.utcnow())
        response = req.zato.client.invoke('zato.stats.get-by-service', {
            'service_id': service_id,
            'start': start,
            'stop': stop
        })

        if response.has_data:
            for key in return_data:
                value = getattr(response.data, key) or ''

                if value and key.endswith('trend') and value != ZATO_NONE:
                    value = [int(float(elem)) for elem in value.split(',')]

                if value == '0.0':
                    value = '<0.1'

                return_data[key] = value if value != ZATO_NONE else '0'

    except Exception:
        msg = 'Caught an exception while invoking zato.service.get-by-service, e:`{}`'.format(
            format_exc())
        logger.error(msg)

    return HttpResponse(dumps(return_data),
                        content_type='application/javascript')
Beispiel #3
0
def last_stats(req, service_id, cluster_id):
    
    return_data = {
        'rate': '(error)',
        'mean': '(error)',
        'mean_trend': '(error)',
        }
    
    try:
        start, stop = last_hour_start_stop(datetime.utcnow())
        zato_message, _ = invoke_admin_service(req.zato.cluster, 
            'zato:stats.get-by-service', {'service_id': service_id, 'start':start, 'stop':stop})
        
        if zato_path('response.item').get_from(zato_message) is not None:
            item = zato_message.response.item
            for key in return_data:
                value = getattr(item, key).text or ''
                
                if value and key.endswith('trend') and value != ZATO_NONE:
                    value = [int(float(elem)) for elem in value.split(',')]

                if value == '0.0':
                    value = '<0.1'

                return_data[key] = value if value != ZATO_NONE else '0'

    except Exception, e:
        msg = 'Caught an exception while invoking zato:service.get-last-stats, e:[{}]'.format(format_exc(e))
        logger.error(msg)
Beispiel #4
0
def last_stats(req, service_id, cluster_id):

    return_data = {"rate": "(error)", "mean": "(error)", "mean_trend": "(error)"}

    try:
        start, stop = last_hour_start_stop(datetime.utcnow())
        response = req.zato.client.invoke(
            "zato.stats.get-by-service", {"service_id": service_id, "start": start, "stop": stop}
        )

        if response.has_data:
            for key in return_data:
                value = getattr(response.data, key) or ""

                if value and key.endswith("trend") and value != ZATO_NONE:
                    value = [int(float(elem)) for elem in value.split(",")]

                if value == "0.0":
                    value = "<0.1"

                return_data[key] = value if value != ZATO_NONE else "0"

    except Exception, e:
        msg = "Caught an exception while invoking zato.service.get-last-stats, e:[{}]".format(format_exc(e))
        logger.error(msg)