Пример #1
0
<?php

require_once dirname(__FILE__) . '/fixtures/cametrics.helper.php';
$logs = explode("\n", file_get_contents('fixtures/access.log'));
$max = 100;
for ($i = 1, $l = count($logs), $step = floor($l / $max); $i <= $l; $i += $step) {
    $line = $logs[$i];
    preg_match("/\\[([^\\]]+)\\] \"/", $line, $matches);
    if (!isset($matches[1])) {
        continue;
    }
    $datetime = date(Cametrics::DATETIME_FORMAT, strtotime(preg_replace("/[\\/:]/", ' ', substr($matches[1], 0, -6), 3)));
    Cametrics::measure('log.access', $datetime, 'datetime');
}
<?php

require_once dirname(__FILE__) . '/fixtures/cametrics.helper.php';
#Cametrics::initialize('agljYW1ldHJpY3NyEAsSCENhbXBhaWduGLv1AQw');
#foreach (range(0, 5) as $i){
#  Cametrics::measure('test');
#  Cametrics::measure('random', rand());
#}
#Cametrics::measure('namespace.value');
#Cametrics::measure('namespace.column.number', 10, 'number');
#Cametrics::measure('namespace.test', 12.125, 'number');
$plants = array('PoisonHemlock', 'YellowStarthistle', 'UnknownPlant', 'TerracinaSpurge', 'TerracinaSpurge', 'TerracinaSpurge', 'PerennialPepperweed', 'PerennialPepperweed', 'HardingGrass', 'HardingGrass', 'PhotoError');
foreach ($plants as $value) {
    Cametrics::measure('plant', $value, 'string');
}
#Cametrics::measure('namespace.column.string', 'string value', 'string');
#Cametrics::measure('namespace.column.string', 'string+value', 'string');
#Cametrics::measure('namespace.column.string', 1309509, 'string');
#Cametrics::measure('namespace.column.string', '', 'string');
#Cametrics::measure('namespace.column.string', null, 'string');
#Cametrics::measure('namespace.column.string', 356996016212614, 'string');
#Cametrics::measure('namespace.column.string', '356996016212614'."\n", 'string');
#Cametrics::measure('data.arrived', time(), 'timestamp');
#Cametrics::measure('data.arrived', date(Cametrics::DATETIME_FORMAT), 'date');
#Cametrics::measure('data.arrived', date(Cametrics::DATETIME_FORMAT), 'datetime');
#foreach (range(0,12) as $i){
#  Cametrics::measure('time', mktime(rand(0, 23), rand(0, 59), rand(0, 59), rand(0,12), rand(0,31), 2009), 'timestamp');
#}
#assert(Cametrics::prepare('123.4,12', 'location') == '123.4,12');
#assert(Cametrics::prepare(array('lat' => '1', 'longitude' => 0), 'location') == '0,1');
#assert(Cametrics::prepare(array('latitude' => '1', 'lng' => 0), 'location') == '0,1');