Exemple #1
0
 /**
  * @param $name
  * @param $value
  *
  * @return bool
  */
 public function addCustomMetric($name, $value)
 {
     $this->debug('Calling addCustomMetric', array($name, $value));
     if ($this->functionExists('newrelic_custom_metric') == false) {
         return false;
     }
     newrelic_custom_metric($name, $value);
     return true;
 }
Exemple #2
0
 /**
  * Check if this transaction generated a bigger peak usage
  * then the previous transaction. If so, report it.
  */
 private function updatePeakMemoryUsage()
 {
     $memory = memory_get_peak_usage();
     if ($memory > $this->peakMemoryUsage) {
         $this->peakMemoryUsage = $memory;
         $this->setParameter('Memory/PeakMemoryUsage', $memory);
         if (extension_loaded('newrelic')) {
             newrelic_custom_metric('Custom/PeakMemoryUsage', $memory);
         }
     }
 }
Exemple #3
0
 /**
  * @param string $measurementName
  * @param float $time - in seconds
  */
 public function measureTime($measurementName, $time)
 {
     $fullMeasurementName = "Custom/{$measurementName}[seconds|call]";
     /*
      * We need to multiply time in seconds by 1000.
      * From newrelic_custom_metric documentation:
      * Adds a custom metric with the specified name and value, which is of type double. Values saved are assumed to be milliseconds, so "4" will be stored as ".004" in our system.
      */
     /** @noinspection PhpUndefinedFunctionInspection */
     newrelic_custom_metric($fullMeasurementName, $time * self::MILLISECONDS_IN_SECOND);
 }
Exemple #4
0
 public function customMetric($name, $value)
 {
     if (extension_loaded('newrelic')) {
         try {
             if (!is_numeric($value)) {
                 throw new Exception('Metric value must be numeric value');
             }
             $this->setAppName();
             return newrelic_custom_metric('Custom/' . $name, $value);
         } catch (Exception $e) {
             Mage::logException($e);
         }
     }
     return false;
 }
Exemple #5
0
 /**
  * {@inheritdoc}
  */
 public function addCustomMetric($name, $value)
 {
     if ($this->extensionLoaded()) {
         newrelic_custom_metric($name, $value);
     }
 }
Exemple #6
0
 /**
  * {@inheritdoc}
  */
 public function addCustomMetric($name, $value)
 {
     if (!$this->extensionLoaded()) {
         return $this;
     }
     newrelic_custom_metric($name, $value);
     return $this;
 }
Exemple #7
0
 /**
  * Track a custom metric
  *
  * @param  string $key
  * @param  integer|float $value
  * @return
  */
 public function metric($key, $value)
 {
     if (!$this->hasNewRelic()) {
         return;
     }
     if (!is_numeric($value)) {
         throw new CakeException('Value must be numeric');
     }
     newrelic_custom_metric($key, $value);
 }
Exemple #8
0
 /**
  * @param $category
  * @param $key
  * @param $value
  */
 public function setCustomMetric($category, $key, $value)
 {
     if (!extension_loaded('newrelic')) {
         return;
     }
     newrelic_custom_metric("Custom/" . $category . "/" . $key, $value);
 }
Exemple #9
0
 /**
  * Adds a custom metric with the specified name and value, which is of type double. These custom metrics can then
  * be used in custom views in the New Relic User Interface.
  *
  * @param string $metricName
  * @param mixed $value
  *
  * @return $this
  */
 public function addCustomMetric($metricName, $value)
 {
     if ($this->active) {
         if (strpos($metricName, 'Custom/') !== 0) {
             $metricName = 'Custom/' . $metricName;
         }
         newrelic_custom_metric($metricName, $value);
     }
     return $this;
 }
Exemple #10
0
 /**
  * Adds a cutom metric with specified name and value.
  * Note: Value to be stored is of type Double.
  *
  * @param string $metricName The name of the metric to store
  * @param double $value The value to store
  */
 public function customMetric($metricName, $value)
 {
     if ($this->skip()) {
         return;
     }
     newrelic_custom_metric($metricName, $value);
 }
Exemple #11
0
/**
 * Log a custom metric
 *
 * @param mixed $name name of the custom metric
 * @param mixed $value assumed to be in milliseconds (ms)
 */
function apm_log_custom_metric($name, $value)
{
    if (extension_loaded('newrelic')) {
        // New Relic is installed on the server for monitoring.
        newrelic_custom_metric('Custom/' . $name, $value);
    }
}
 /**
  * @return mixed
  * @throws \Exception
  * @throws null
  *
  * Generic request
  */
 public function request()
 {
     if ($this->method == null || empty($this->method)) {
         throw new \Exception('METHOD is not defined');
     }
     if ($this->uri == null || empty($this->uri)) {
         throw new \Exception('URI is not defined');
     }
     // return debug information if debug is enabled
     if ($this->debug) {
         return $this->debugInfo();
     }
     try {
         // cache key
         $cacheKey = $this->generateCacheKey();
         // cache
         if ($this->useCache) {
             // if cached response is found, return it formatted
             if ($this->cache->hasItem($cacheKey)) {
                 $response = $this->cache->getItem($cacheKey);
                 return $this->formatResponseToReturn($response);
             }
         }
         // log time (START)
         $timeStart = microtime(true);
         // return seeds if present
         if ($seeds = $this->findSeeds()) {
             return $seeds;
         }
         $request = (new ArtaxRequest())->setUri($this->uri)->setMethod($this->method)->setAllHeaders($this->headers);
         if ($this->params != null) {
             $request->setBody(json_encode($this->params));
         }
         // make the request (first attempt)
         $ampResponse = $this->doRequest($request);
         // return response if it's not an ArtaxResponse (it could be a string cached in local file)
         if (!$ampResponse instanceof ArtaxResponse) {
             return $ampResponse;
         }
         // log time (END)
         $timeEnd = microtime(true);
         if ($this->config['newrelic'] === true && extension_loaded('newrelic')) {
             newrelic_custom_metric('Custom/Artax/Load_time', round($timeEnd - $timeStart));
         }
         // code and body
         $response['code'] = (int) $ampResponse->getStatus();
         $response['body'] = json_decode($ampResponse->getBody(), true);
         // optional headers
         foreach ($this->headersToReturn as $headerToReturn) {
             if ($ampResponse->hasHeader($headerToReturn)) {
                 $response['headers'][$headerToReturn] = $ampResponse->getHeader($headerToReturn)[0];
             }
         }
         // store response in cache
         if ($this->useCache) {
             $this->cache->setItem($cacheKey, $response);
             // TODO cache ttl (set timeout on specific cache key)
             if ($this->cacheTtl) {
             }
         }
         // seeds
         $this->writeSeeds($response);
         // reformat response
         return $this->formatResponseToReturn($response);
     } catch (\Exception $error) {
         throw new \Exception($error);
     }
 }
Exemple #13
0
 /**
  * @param string $name
  * @param float $value miliseconds
  */
 public static function addMetric($name, $value)
 {
     if (\VrtakCZ\NewRelic\Tracy\Bootstrap::isEnabled()) {
         newrelic_custom_metric('Custom/' . $name, $value);
     }
 }
 /**
  * {@inheritdoc}
  */
 public function addCustomMetric($name, $value)
 {
     newrelic_custom_metric((string) $name, $value);
 }
Exemple #15
0
 /**
  * Listen to the event model_delete_after
  *
  * @access public
  * @param Varien_Event_Observer $observer
  * @return $this
  */
 public function modelDeleteAfter($observer)
 {
     if (!$this->_isEnabled()) {
         return $this;
     }
     if (!function_exists('newrelic_custom_metric')) {
         return $this;
     }
     $object = $observer->getEvent()->getObject();
     newrelic_custom_metric('Magento/' . get_class($object) . '_Delete', (double) 1.0);
     return $this;
 }
Exemple #16
0
 /**
  * Add custom metric with the specified $name and $value, which is of type
  * double. Values saved are assumed to be milliseconds.
  *
  * @link https://docs.newrelic.com/docs/agents/php-agent/configuration/php-agent-api#api-custom-metric
  *
  * @param string $metric
  * @param float  $value
  *
  * @return bool
  */
 public function customMetric($metric, $value)
 {
     if (!$this->isLoaded()) {
         return false;
     }
     return newrelic_custom_metric($metric, $value);
 }
Exemple #17
0
 /**
  * Add custom metric
  * @param string $metricName
  * @param float $value
  * @return boolean true on success
  */
 public function addMetric($metricName, $value)
 {
     return newrelic_custom_metric($metricName, $value);
 }
Exemple #18
0
 /**
  * @param string $name
  * @param int    $milliseconds
  */
 public function setCustomMetric($name, $milliseconds)
 {
     $name = 'Custom/' . (string) $name;
     $milliseconds = (int) $milliseconds;
     if ($this->getEnabled()) {
         newrelic_custom_metric($name, $milliseconds);
     }
 }
Exemple #19
0
 public function setCustomMetric($name, $value)
 {
     newrelic_custom_metric($name, floatval($value));
 }