public function getDataFor($metric, $startTime, $endTime)
{
// when are we looking for?
$humanStartTime = date('Y-m-d H:i:s', $startTime);
$humanEndTime = date('Y-m-d H:i:s', $endTime);
// what are we doing?
$log = usingLog()->startAction("get raw data from graphite for '{$metric}' between '{$humanStartTime}' and '{$humanEndTime}'");
// find out where graphite is
$graphiteUrl = fromConfig()->getModuleSetting('graphite.url');
if (substr($graphiteUrl, -1, 1) !== '/') {
$graphiteUrl .= '/';
}
// get the requested data
$response = fromHttp()->get("{$graphiteUrl}render?format=json&target={$metric}&from={$startTime}&until={$endTime}");
// are there any stats in the response?
assertsArray($response->chunks)->isExpectedType();
assertsArray($response->chunks)->isNotEmpty();
// assemble the raw chunks into one string to decode
$rawStats = implode("", $response->chunks);
assertsString($rawStats)->isValidJson();
$stats = json_decode($rawStats);
// all done
$log->endAction();
return $stats;
}