예제 #1
0
파일: app.py 프로젝트: douban/graph-index
def regex():
    global metrics, diamond
    errors = []
    if request.method == 'POST':
        search = request.forms.get('search')
        if not search.strip():
            errors.append('can not be none')
        else:
            return redirect('/regex/?' + urlencode({'search' : search}))
    elif request.method == 'GET':
        # url will be like '/regex/?search=...'
        search = request.query.get('search', '')
        if search.strip() in ['.*', '.*?']:
            errors.append('are you kidding me?')
        elif ':' in search: # search is started with prefix
            if search.startswith('plugin:'): # search == 'plugin:<plugin>:<server_regex>'
                _, plugin, server_regex = search.strip().split(':', 2)
                graphs = []
                data = do_plugin(diamond, plugin, server_regex)
                for server in sorted(data.keys()):
                    graph = Graph(data[server], title = server + ' ' + plugin)
                    graph.detail_url = '/server/%s/%s' % (server, plugin)
                    graphs.append(graph)
                body = template('templates/graph-list', **locals())
            elif search.startswith('merge:'): # search == 'merge:'
                _, regex = search.strip().split(':', 1)
                title = request.query.get('title')
                targets = search_metrics(metrics, regex)
                graph = Graph(targets, title = title or 'a merged graph')
                body = template('templates/graph', **locals())
            elif search.startswith('sum:'): # search == 'merge:'
                _, regex = search.strip().split(':', 1)
                targets = search_metrics(metrics, regex)
                graph = Graph(['sumSeries(%s)' % (','.join(targets)), ], title = 'a sum-ed graph')
                body = template('templates/graph', **locals())
        else: # search is common regex without any prefix
            match = groupby_re.match(search)
            if match:
                graphs = []
                for group, targets in do_groupby(metrics, **match.groupdict()):
                    graph = Graph(targets, title = group)
                    graph.detail_url = '/regex/?search=merge:^(%s)$&title=%s' % ('|'.join(graph.targets), group)
                    graph.detail_title = group
                    graphs.append(graph)
                body = template('templates/graph-list', **locals())
            else:
                data = search_metrics(metrics, search)
                if len(data) == 0:
                    errors.append('no metric is matched')
                graphs = []
                for metric in data:
                    graph = Graph(targets = [metric, ], title = metric)
                    graph.detail_url = '/metric/%s' % metric
                    graph.detail_title = metric
                    graph.auto_refresh = True
                    graphs.append(graph)
                body = template('templates/graph-list', **locals())
    if errors:
        body = template('templates/error', **locals())
    return render_page(body, search = search)
예제 #2
0
def server(server=''):
    global diamond
    graphs = []
    for plugin in sorted(diamond[server].keys()):
        graph = Graph(diamond[server][plugin], title=server + ' ' + plugin)
        graph.detail_url = '/server/%s/%s' % (server, plugin)
        graph.detail_title = plugin
        graphs.append(graph)
    body = template('templates/graph-list', **locals())
    return render_page(body)
예제 #3
0
파일: app.py 프로젝트: douban/graph-index
def server(server = ''):
    global diamond
    graphs = []
    for plugin in sorted(diamond[server].keys()):
        graph = Graph(diamond[server][plugin], title = server + ' ' + plugin)
        graph.detail_url = '/server/%s/%s' % (server, plugin)
        graph.detail_title = plugin
        graphs.append(graph)
    body = template('templates/graph-list', **locals())
    return render_page(body)
예제 #4
0
def regex():
    global metrics, diamond
    errors = []
    if request.method == 'POST':
        search = request.forms.get('search')
        if not search.strip():
            errors.append('can not be none')
        else:
            return redirect('/regex/?' + urlencode({'search': search}))
    elif request.method == 'GET':
        # url will be like '/regex/?search=...'
        search = request.query.get('search', '')
        if search.strip() in ['.*', '.*?']:
            errors.append('are you kidding me?')
        elif ':' in search:  # search is started with prefix
            if search.startswith(
                    'plugin:'):  # search == 'plugin:<plugin>:<server_regex>'
                _, plugin, server_regex = search.strip().split(':', 2)
                graphs = []
                data = do_plugin(diamond, plugin, server_regex)
                for server in sorted(data.keys()):
                    graph = Graph(data[server], title=server + ' ' + plugin)
                    graph.detail_url = '/server/%s/%s' % (server, plugin)
                    graphs.append(graph)
                body = template('templates/graph-list', **locals())
            elif search.startswith('merge:'):  # search == 'merge:'
                _, regex = search.strip().split(':', 1)
                title = request.query.get('title')
                targets = search_metrics(metrics, regex)
                graph = Graph(targets, title=title or 'a merged graph')
                body = template('templates/graph', **locals())
            elif search.startswith('sum:'):  # search == 'merge:'
                _, regex = search.strip().split(':', 1)
                targets = search_metrics(metrics, regex)
                graph = Graph([
                    'sumSeries(%s)' % (','.join(targets)),
                ],
                              title='a sum-ed graph')
                body = template('templates/graph', **locals())
        else:  # search is common regex without any prefix
            match = groupby_re.match(search)
            if match:
                graphs = []
                for group, targets in do_groupby(metrics, **match.groupdict()):
                    graph = Graph(targets, title=group)
                    graph.detail_url = '/regex/?search=merge:^(%s)$&title=%s' % (
                        '|'.join(graph.targets), group)
                    graph.detail_title = group
                    graphs.append(graph)
                body = template('templates/graph-list', **locals())
            else:
                data = search_metrics(metrics, search)
                if len(data) == 0:
                    errors.append('no metric is matched')
                graphs = []
                for metric in data:
                    graph = Graph(targets=[
                        metric,
                    ], title=metric)
                    graph.detail_url = '/metric/%s' % metric
                    graph.detail_title = metric
                    graph.auto_refresh = True
                    graphs.append(graph)
                body = template('templates/graph-list', **locals())
    if errors:
        body = template('templates/error', **locals())
    return render_page(body, search=search)