Beispiel #1
0
$requestTypes = array('live', 'req_time');
$server->get('/{type}/{requestId}/{grouping}', function ($type, $requestId, $grouping) use($app, $requestTypes) {
    if (!in_array($type, $requestTypes)) {
        $app->abort(404, "Type {$type} not allowed. Allowed types: " . implode(', ', $requestTypes));
    }
    $date = null;
    if (stripos($requestId, '::') !== false) {
        list($requestId, $date) = explode('::', $requestId);
    }
    $request = getRequestById($app['db'], $type, $requestId, $date);
    if (!$request) {
        $app->abort(404, "Request #{$requestId} not found.");
    }
    Utils::checkUserAccess($app, $request['server_name']);
    $request['script_name'] = Utils::urlDecode($request['script_name']);
    $request = Utils::parseRequestTags($request);
    $request['timers'] = getTimers($app['db'], $type, $requestId, $date);
    $groupingTags = findGroupingTags($request['timers']);
    if (strlen($grouping)) {
        $grouping = preg_replace('/^grouping\\-/', '', $grouping);
    }
    if (empty($grouping)) {
        if (sizeof($groupingTags)) {
            if (in_array('group', $groupingTags)) {
                $grouping = 'group';
            } else {
                $grouping = $groupingTags[0];
            }
        } else {
            $grouping = null;
        }
Beispiel #2
0
<?php

use Doctrine\DBAL\Cache\QueryCacheProfile;
use Pinboard\Utils\IDNaConvert;
use Pinboard\Utils\Utils;
$index = $app['controllers_factory'];
$index->get('/', function () use($app) {
    $result = array();
    $params = array('created_at' => date('Y-m-d H:00:00', strtotime('-1 day')));
    $hostsRegexp = Utils::getUserAccessHostsRegexp($app);
    $hostsWhere = '';
    if ($hostsRegexp != '.*') {
        $hostsRegexp = is_array($hostsRegexp) ? $hostsRegexp : array($hostsRegexp);
        $hostsWhere = " AND (a.server_name REGEXP '" . implode("' OR a.server_name REGEXP '", $hostsRegexp) . "')";
    }
    $sql = '
        SELECT
            a.server_name,
            sum(a.req_count) as req_count,
            avg(a.req_per_sec) as req_per_sec,
            (
                SELECT
                    count(*)
                FROM
                    ipm_status_details b
                WHERE
                    a.server_name = b.server_name AND b.created_at > :created_at
            )
            as error_count
        FROM
            ipm_report_by_hostname_and_server a
Beispiel #3
0
function getLivePages($conn, $serverName, $hostName, $limit = 50, array $filter)
{
    $params = array('server_name' => $serverName);
    $hostCondition = '';
    $idCondition = '';
    if ($hostName != 'all') {
        $params['hostname'] = $hostName;
        $hostCondition .= ' AND hostname = :hostname';
    }
    if (isset($filter['last_id']) && $filter['last_id'] > 0) {
        $params['last_id'] = $filter['last_id'];
        $params['last_timestamp'] = $filter['last_timestamp'];
        $idCondition .= ' AND id <> :last_id AND timestamp >= :last_timestamp';
    }
    if (isset($filter['req_time']) && $filter['req_time']) {
        $params['req_time'] = $filter['req_time'] / 1000;
        $idCondition .= ' AND req_time >= :req_time';
    }
    $sql = '
        SELECT
            id, server_name, hostname, script_name, req_time, status, mem_peak_usage, ru_utime, timestamp
        FROM
            request
        WHERE
            server_name = :server_name
            ' . $hostCondition . '
            ' . $idCondition . '
        ORDER BY
            timestamp DESC, id DESC
        LIMIT
            ' . $limit . '
    ';
    $data = $conn->fetchAll($sql, $params);
    foreach ($data as $k => &$item) {
        if (isset($filter['last_id']) && $filter['last_id'] > 0) {
            if ($item['timestamp'] == $filter['last_timestamp'] && $item['id'] >= $filter['last_id'] - 10000) {
                unset($data[$k]);
                continue;
            }
        }
        $item['script_name'] = Utils::urlDecode($item['script_name']);
        $item['req_time'] = $item['req_time'] * 1000;
        $item['mem_peak_usage'] = $item['mem_peak_usage'];
        $item['req_time_format'] = number_format($item['req_time'], 0, '.', ',');
        $item['mem_peak_usage_format'] = number_format($item['mem_peak_usage'], 0, '.', ',');
        $item['timestamp_format'] = date('H:i:s', $item['timestamp']);
    }
    return $data;
}