コード例 #1
0
ファイル: test_metrics.py プロジェクト: willhope/alerta
    def test_metrics(self):

        test_gauge = Gauge(group='test',
                           name='gauge',
                           title='Test gauge',
                           description='total time to process timed events')
        test_gauge.set(500)

        gauge = [g for g in Gauge.get_gauges() if g.title == 'Test gauge'][0]
        self.assertGreaterEqual(gauge.value, 500)

        test_timer = Timer(group='test',
                           name='timer',
                           title='Test timer',
                           description='total time to process timed events')
        recv_started = test_timer.start_timer()
        time.sleep(1)
        test_timer.stop_timer(recv_started)

        timer = [t for t in Timer.get_timers() if t.title == 'Test timer'][0]
        self.assertGreaterEqual(timer.count, 1)
        self.assertGreaterEqual(timer.total_time, 999)
コード例 #2
0
try:
    from urllib.parse import urljoin
except ImportError:
    from urlparse import urljoin

from alerta.app import app, db
from alerta.app.metrics import Counter, Timer
from alerta.plugins import Plugins, RejectException

LOG = app.logger

plugins = Plugins()

reject_counter = Counter('alerts', 'rejected', 'Rejected alerts', 'Number of rejected alerts')
error_counter = Counter('alerts', 'errored', 'Errored alerts', 'Number of errored alerts')
duplicate_timer = Timer('alerts', 'duplicate', 'Duplicate alerts', 'Total time to process number of duplicate alerts')
correlate_timer = Timer('alerts', 'correlate', 'Correlated alerts', 'Total time to process number of correlated alerts')
create_timer = Timer('alerts', 'create', 'Newly created alerts', 'Total time to process number of new alerts')
pre_plugin_timer = Timer('plugins', 'prereceive', 'Pre-receive plugins', 'Total number of pre-receive plugins')
post_plugin_timer = Timer('plugins', 'postreceive', 'Post-receive plugins', 'Total number of post-receive plugins')


def jsonp(func):
    """Wraps JSONified output for JSONP requests."""
    @wraps(func)
    def decorated(*args, **kwargs):
        callback = request.args.get('callback', False)
        if callback:
            data = str(func(*args, **kwargs).data)
            content = str(callback) + '(' + data + ')'
            mimetype = 'application/javascript'
コード例 #3
0
from alerta.app import app, db
from alerta.app.switch import Switch
from alerta.app.auth import permission, is_in_scope
from alerta.app.utils import absolute_url, jsonp, parse_fields, process_alert, process_status, add_remote_ip
from alerta.app.metrics import Timer
from alerta.app.alert import Alert
from alerta.app.exceptions import RejectException, RateLimit, BlackoutPeriod
from alerta.app.heartbeat import Heartbeat
from alerta.plugins import Plugins

LOG = app.logger

plugins = Plugins()

# Set-up metrics
gets_timer = Timer('alerts', 'queries', 'Alert queries',
                   'Total time to process number of alert queries')
receive_timer = Timer('alerts', 'received', 'Received alerts',
                      'Total time to process number of received alerts')
delete_timer = Timer('alerts', 'deleted', 'Deleted alerts',
                     'Total time to process number of deleted alerts')
status_timer = Timer('alerts', 'status', 'Alert status change',
                     'Total time and number of alerts with status changed')
tag_timer = Timer('alerts', 'tagged', 'Tagging alerts',
                  'Total time to tag number of alerts')
attrs_timer = Timer('alerts', 'attributes', 'Alert attributes change',
                    'Total time and number of alerts with attributes changed')
untag_timer = Timer('alerts', 'untagged', 'Removing tags from alerts',
                    'Total time to un-tag number of alerts')


@app.route('/_', methods=['OPTIONS', 'PUT', 'POST', 'DELETE', 'GET'])
コード例 #4
0
ファイル: views.py プロジェクト: hscale/alerta
import datetime

from copy import copy
from flask import request
from flask.ext.cors import cross_origin
from dateutil.parser import parse as parse_date

from alerta.app import app, db
from alerta.alert import Alert
from alerta.app.utils import absolute_url, jsonify, jsonp, process_alert
from alerta.app.metrics import Timer
from alerta.plugins import RejectException

LOG = app.logger

webhook_timer = Timer('alerts', 'webhook', 'Web hook alerts',
                      'Total time to process number of web hook alerts')
duplicate_timer = Timer('alerts', 'duplicate', 'Duplicate alerts',
                        'Total time to process number of duplicate alerts')
correlate_timer = Timer('alerts', 'correlate', 'Correlated alerts',
                        'Total time to process number of correlated alerts')
create_timer = Timer('alerts', 'create', 'Newly created alerts',
                     'Total time to process number of new alerts')


def cw_state_to_severity(state):

    if state == 'ALARM':
        return 'major'
    elif state == 'INSUFFICIENT_DATA':
        return 'warning'
    elif state == 'OK':
コード例 #5
0
ファイル: views.py プロジェクト: wangbodong/alerta
from alerta.app.metrics import Timer

from flask import request, render_template, jsonify
from flask_cors import cross_origin
from werkzeug import urls
from werkzeug.datastructures import ImmutableMultiDict

try:
    from urllib.parse import urlparse
except ImportError:
    from urlparse import urlparse


LOG = app.logger

oembed_timer = Timer('oEmbed', 'request', 'oEmbed request', 'Total time to process number of oEmbed requests')

@app.route('/oembed', defaults={'format':'json'}, methods=['OPTIONS', 'GET'])
@app.route('/oembed.<format>', methods=['OPTIONS', 'GET'])
@cross_origin()
@auth_required
@jsonp
def oembed(format):

    oembed_started = oembed_timer.start_timer()

    if format != 'json':
        oembed_timer.stop_timer(oembed_started)
        return jsonify(status="error", message="unsupported format: %s" % format), 400

    if 'url' not in request.args or 'maxwidth' not in request.args \