<?php

require '../vendor/autoload.php';
include '../config.php';
$statsd = new League\StatsD\Client();
$statsd->configure(array('host' => isset($statsd_host) ? $statsd_host : '127.0.0.1', 'port' => isset($statsd_port) ? $statsd_port : 8125, 'namespace' => isset($statsd_namespace) ? $statsd_namespace : null));
if (isset($_SERVER['REQUEST_URI'])) {
    $filename = substr($_SERVER['REQUEST_URI'], 1);
    $noExt = str_replace('.gif', '', $filename);
    $parts = explode('_', $noExt);
    if (isset($parts[0]) && isset($parts[1]) && (strlen($parts[0]) == 3 || strlen($parts[0]) == 4) && strlen($parts[1]) >= 16) {
        $counters = array('cloudflare.errors', 'cloudflare.errors.' . $parts[0]);
        $statsd->increment($counters, 1, 1);
    }
}
$fp = fopen('../transparent.gif', 'rb');
header('Content-type: image/gif');
header('Cache-Control: no-cache, no-store, must-revalidate');
header('Pragma: no-cache');
header('Expires: 0');
fpassthru($fp);
exit;
<?php

require dirname(__FILE__) . '/../vendor/autoload.php';
include dirname(__FILE__) . '/../config.php';
$statsd = new League\StatsD\Client();
$statsd->configure(array('host' => isset($statsd_host) ? $statsd_host : '127.0.0.1', 'port' => isset($statsd_port) ? $statsd_port : 8125, 'namespace' => isset($statsd_namespace) ? $statsd_namespace : null));
$baseUrl = "https://insights-api.newrelic.com/v1/accounts/" . $nr_account_id . "/query?nrql=";
foreach ($queries as $query) {
    $fullUrl = $baseUrl . $query['encodedQuery'];
    $ch = curl_init($fullUrl);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('X-Query-Key: ' . $query['query_api_key']));
    $data = curl_exec($ch);
    $status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    curl_close($ch);
    $fetchedData = null;
    if ($status == 200) {
        $dataAr = json_decode($data, true);
        $indexInResult = isset($query['indexInResult']) ? $query['indexInResult'] : 0;
        if (isset($dataAr['results'][$indexInResult][$query['keyToFetch']])) {
            $fetchedData = $dataAr['results'][$indexInResult][$query['keyToFetch']];
        }
    }
    if ($fetchedData !== null && $fetchedData >= 0) {
        switch ($query['statsdMetricType']) {
            case 'gauge':
                $statsd->gauge($query['statsdKey'], $fetchedData);
                echo "Updating metric type 'gauge', key: " . $query['statsdKey'] . ", value: " . $fetchedData . PHP_EOL;
                break;
            case 'set':
                $statsd->set($query['statsdKey'], $fetchedData);