Skip to content

Analytics

Obter estatísticas de acesso a um domínio.

Os dados de transferência são retornados em KB, e o timestamp está no formato unix timestamp.

GET /v1/analytics/{dominio}?graph={graph}&interval={interval}&from={from}&to={to}&host={subdomain}

Exemplo de Request

$ curl -i "https://api.gocache.com.br/v1/analytics/seudominio.com.br?graph=custom&interval=1h&from=1546308000&to=1546315000&host=blog.seudominio.com.br" /
-H 'GoCache-Token:seu_token'
<?php

$ch = curl_init("https://api.gocache.com.br/v1/analytics/seudominio.com.br?graph=custom&interval=1h&from=1546308000&to=1546315000&host=blog.seudominio.com.br");

curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);

curl_setopt($ch, CURLOPT_HTTPHEADER, array("GoCache-Token: seu_token"));

$response = curl_exec($ch);
$statusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);

curl_close($ch);
?>

Paramêtros

Campo Tipo Opcional Descrição
graph String Valores permitidos: "custom", "current-month", "last-month"
interval String Intervalo dos dados de estatísticas de acesso, valores permitidos: "1min", "1h", "4h", "12h", "1d"
host String Permite filtro por subdomínio. O valor deve ser o subdomínio completo (ex: www.seudominio.com.br)
from Number Horário inicial dos dados de estatísticas de acesso (em formato unix timestamp)
to Number Horário final dos dados de estatísticas de acesso (em formato unix timestamp)

Exemplo de Sucesso:

HTTP/1.1 200 OK {
    "status_code": 1,
    "response": {
      "requests": {
       "status_group": {
        "3xx": {
          "total": [0,3]},
        "4xx": {
          "total": [0,0]},
        "5xx": {
          "total": [0,0]},
        "1xx": {
          "total": [3,4]},
        "2xx": {
         "total": [56,20]}
        },
       "ratelimit": {
        "challenge": {
         "total": [0,0]},
        "count": {
         "total": [0,0]},
        "simulate": {
         "total": [0,0]},
        "challenge_success": {
         "total": [0,0]},
        "challenge_failed": {
         "total": [0,0]},
        "block": {
         "total": [0,0]},
        "whitelist": {
         "total": [0,0]}
       },
       "status_code": {
        "404": {
         "total": [0,0]},
        "401": {
         "total": [0,0]},
        "503": {
         "total": [0,0]},
        "499": {
         "total": [0,0]},
        "400": {
         "total": [0,0]},
        "504": {
         "total": [0,0]},
        "502": {
         "total": [0,0]},
        "500": {
         "total": [0,0]},
        "301": {
         "total": [0,0]},
        "403": {
         "total": [0,0]},
        "302": {
         "total": [0,0]},
        "304": {
         "total": [0,3]}
        },
       "smartrule": {
        "challenge": {
         "total": [0,0]},
        "accept": {
         "total": [0,0]},
        "challenge_failed": {
         "total": [0,0]},
        "challenge_success": {
         "total": [0,0]},
        "block": {
         "total": [0,0]}
       },
       "waf": {
        "challenge": {
         "total": [0,0]},
        "challenge_success": {
         "total": [0,0]},
        "challenge_failed": {
         "total": [0,0]},
        "simulate": {
         "total": [0,0]},
       "block": {
         "total": [0,0]}
      },
      "firewall": {
       "accept": {
        "total": [0,0]},
       "block": {
        "total": [0,0]}
      }
      },
      "stats": {
       "status_group": {
        "3xx": 3,
        "4xx": 0,
        "5xx": 0,
        "others": 0,
        "1xx": 7,
        "2xx": 76
     },
     "req_per_sec": {
      "total": {
        "avg": 0.011944444444444,
        "max": 0.016388888888889
      }
     },
     "requests": {
      "total": 86,
      "user": 86,
      "3lcloud": 0,
      "optimized": 0
     },
     "firewall": {
      "accept": 0,
      "block": 0
     },
     "smartrule": {
      "challenge": 0,
      "accept": 0,
      "challenge_failed": 0,
      "challenge_success": 0,
      "block": 0
     },
     "cache_coverage": {
      "uncacheable": 10,
      "cached": 0,
      "uncached": 76
     },
     "avg_req_size": {
      "total": 3.0982807957849
     },
     "ratelimit": {
      "cdn": 0,
      "count": 0,
      "simulate": 0,
      "challenge_success": 0,
      "challenge_failed": 0,
      "block": 0,
      "user": 0,
      "challenge": 0,
      "whitelist": 0
     },
     "bandwidth": {
      "ratio": {
        "optimized": 0
      },
      "user": 266.4521484375,
      "optimized": 0,
      "unoptimized": 0,
      "3lcloud": 0,
      "total": 266.4521484375
     },
     "latency": {
      "html": 2.3808,
      "non_html": 0.30138271604938
     },
     "waf": {
      "challenge": 0,
      "challenge_success": 0,
      "challenge_failed": 0,
      "simulate": 0,
      "block": 0
     },
     "pageviews": {
      "user": 5,
      "3lcloud": 0,
      "total": 5
     }
     },
     "metadata": {
      "start_point": 1624046400,
      "end_point": 1624050000,
      "interval": 3600,
      "server_time": 1624052784.601
     },
     "traffic": {
     "bandwidth_per_sec": {
      "total": [0.052033333333333,0.55429333333333],
      "3lcloud": [0,0],
      "user": [0.052033333333333,0.55429333333333]
     },
     "req_per_sec": {
      "total": [0.016388888888889,0.0075],
      "3lcloud": [0,0],
      "user": [0.016388888888889,0.0075]
     },
     "requests": {
      "3lcloud": [0,0],
      "total": [59,27],
      "optimized": [0,0],
      "user": [59,27]
     },
     "bandwidth": {
      "total": [22.8662109375,243.5859375],
      "optimized": [0,0],
      "3lcloud": [0,0],
      "unoptimized": [0,0],
      "user": [22.8662109375,243.5859375]
     },
     "pageviews": {
      "total": [0,5],
      "3lcloud": [0,0],
      "user": [0,5]
     },
     "latency": {
      "html": [0,2.3808],
      "non_html": [0.31713559322034,0.25913636363636]
     },
     "avg_req_size": {
      "total": [0.38756289724576,9.0217013888889]
     }}}}
<?php

if( $statusCode == 200 ) {

    echo("Sucesso!\n");

    $obj = json_decode($response);

    echo("Requisicoes economizadas: " . sprintf("%.2f", 100.0 * ($obj->response->stats->requests->{"3lcloud"} / $obj->response->stats->requests->total)) . "%\n");

}
?>