/** * Combine and submit the total of the samples to the metric * * @param int $resolution Resolution (defaults to 30 seconds) */ public function submitTotals($resolution = self::SAMPLES_INTERVAL) { Assertion::greaterOrEqualThan($resolution, self::SAMPLES_INTERVAL, sprintf('The minimum resolution is %d seconds', self::SAMPLES_INTERVAL)); if (sizeof($this->samples) == 0) { return; } $totals = []; ksort($this->samples); foreach ($this->samples as $timestamp => $samples) { foreach ($samples as $sample) { $key = $timestamp - $timestamp % $resolution; if (!isset($totals[$key])) { $totals[$key] = 0; } $totals[$key] += $sample; } } // Submit resulting samples to the metric foreach ($totals as $timestamp => $value) { $this->endpoint->persist(Data::fromUnixTimestamp($timestamp, $value)); } $this->reset(); }
/** * Get an endpoint for submitting data about a specific metric * * @param MetricId $metricId * * @return DataEndpoint */ public function getMetricDataEndpoint(MetricId $metricId) { return DataEndpoint::fromMetric($this->driver, $metricId); }