예제 #1
0
 /**
  * @param $backgroundJob
  */
 public function setBackgroundJob($backgroundJob)
 {
     $this->debug('Calling setBackgroundJob');
     if ($this->functionExists('newrelic_background_job')) {
         newrelic_background_job($backgroundJob);
     }
 }
예제 #2
0
 /**
  * @param \Nette\Application\Application $application
  * @param \Nette\Application\Request $request
  */
 public function __invoke(Application $application, Request $request)
 {
     if (PHP_SAPI === 'cli') {
         newrelic_background_job(TRUE);
     }
     $params = $request->getParameters();
     $action = $request->getPresenterName();
     if (isset($params[$this->actionKey])) {
         $action = sprintf('%s:%s', $action, $params[$this->actionKey]);
     }
     if (!empty($this->map)) {
         foreach ($this->map as $pattern => $appName) {
             if ($pattern === '*') {
                 continue;
             }
             if (Strings::endsWith($pattern, '*')) {
                 $pattern = Strings::substring($pattern, 0, -1);
             }
             if (Strings::startsWith($pattern, ':')) {
                 $pattern = Strings::substring($pattern, 1);
             }
             if (Strings::startsWith($action, $pattern)) {
                 \VrtakCZ\NewRelic\Tracy\Bootstrap::setup($appName, $this->license);
                 break;
             }
         }
     }
     newrelic_name_transaction($action);
     newrelic_disable_autorum();
 }
예제 #3
0
 /**
  * Execute the action
  * We will build the classname, require the class and call the execute method.
  */
 protected function execute()
 {
     if (extension_loaded('newrelic')) {
         newrelic_background_job();
     }
     $this->loadConfig();
     // build action-class-name
     $actionClass = 'Backend\\Modules\\' . $this->getModule() . '\\Cronjobs\\' . $this->getAction();
     if ($this->getModule() == 'Core') {
         $actionClass = 'Backend\\Core\\Cronjobs\\' . $this->getAction();
     }
     // validate if class exists (aka has correct name)
     if (!class_exists($actionClass)) {
         // set correct headers
         header('HTTP/1.1 500 Internal Server Error');
         // throw exception
         throw new Exception('The cronjobfile ' . $actionClass . ' could not be found.');
     }
     // create action-object
     $this->cronjob = new $actionClass($this->getKernel());
     $this->cronjob->setModule($this->getModule());
     $this->cronjob->setAction($this->getAction());
     if (extension_loaded('newrelic')) {
         newrelic_name_transaction('cronjob::' . $this->getModule() . '::' . $this->getAction());
     }
 }
예제 #4
0
 /**
  * Execute the action
  * We will build the classname, require the class and call the execute method.
  */
 protected function execute()
 {
     if (extension_loaded('newrelic')) {
         newrelic_background_job();
     }
     $this->loadConfig();
     // build action-class-name
     $actionClass = 'Backend\\Modules\\' . $this->getModule() . '\\Cronjobs\\' . $this->getAction();
     if ($this->getModule() == 'Core') {
         $actionClass = 'Backend\\Core\\Cronjobs\\' . $this->getAction();
     }
     // validate if class exists (aka has correct name)
     if (!class_exists($actionClass)) {
         // set correct headers
         \SpoonHTTP::setHeadersByCode(500);
         // throw exception
         throw new Exception('The cronjobfile is present, but the classname should be: ' . $actionClass . '.');
     }
     // create action-object
     $this->cronjob = new $actionClass($this->getKernel());
     $this->cronjob->setModule($this->getModule());
     $this->cronjob->setAction($this->getAction());
     if (extension_loaded('newrelic')) {
         newrelic_name_transaction('cronjob::' . $this->getModule() . '::' . $this->getAction());
     }
 }
예제 #5
0
파일: Newrelic.php 프로젝트: cargomedia/cm
 /**
  * @param bool|null $flag
  */
 public function setBackgroundJob($flag = null)
 {
     if (null === $flag) {
         $flag = true;
     }
     if ($this->getEnabled()) {
         newrelic_background_job($flag);
     }
 }
 /**
  * Constructor method.
  * Sets defaults -- no writing to memache, and a default search indexer instance
  */
 public function __construct()
 {
     parent::__construct();
     $this->service = new MediaWikiService();
     $this->service->setGlobal('AllowMemcacheWrites', false)->setGlobal('AppStripsHtml', true);
     if (function_exists('newrelic_disable_autorum')) {
         newrelic_disable_autorum();
     }
     if (function_exists('newrelic_background_job')) {
         newrelic_background_job(true);
     }
 }
 public function onRequest(Application $app, Request $request)
 {
     if (!extension_loaded('newrelic')) {
         return;
     }
     if (PHP_SAPI === 'cli') {
         newrelic_name_transaction('$ ' . basename($_SERVER['argv'][0]) . ' ' . implode(' ', array_slice($_SERVER['argv'], 1)));
         newrelic_background_job(TRUE);
         return;
     }
     $params = $request->getParameters();
     newrelic_name_transaction($request->getPresenterName() . (isset($params['action']) ? ':' . $params['action'] : ''));
 }
예제 #8
0
 public function startup()
 {
     parent::startup();
     ini_set('memory_limit', '512M');
     if (extension_loaded('newrelic')) {
         newrelic_background_job();
     }
     $param = $this->presenter->context->httpRequest->getPost('param');
     if (!empty($param)) {
         $this->param = json_decode($param, true);
     } else {
         $this->param = null;
     }
 }
예제 #9
0
 public function startTransaction()
 {
     if ($this->started) {
         $this->endTransaction();
     }
     if (extension_loaded('newrelic')) {
         newrelic_start_transaction($this->appname);
         newrelic_background_job($this->background);
         if ($this->output) {
             echo "\nStarting transaction " . $this->appname . ' ' . ($this->background ? '(background)' : '(frontground)') . "\n";
         }
     }
     $this->started = true;
 }
 public function onRequest(Application $app, Request $request)
 {
     if (!extension_loaded('newrelic')) {
         return;
     }
     if (PHP_SAPI === 'cli') {
         // uložit v čitelném formátu
         newrelic_name_transaction('$ ' . basename($_SERVER['argv'][0]) . ' ' . implode(' ', array_slice($_SERVER['argv'], 1)));
         // označit jako proces na pozadí
         newrelic_background_job(TRUE);
         return;
     }
     // pojmenování požadavku podle presenteru a akce
     $params = $request->getParameters();
     newrelic_name_transaction($_SERVER['HTTP_HOST'] . " | " . $request->getPresenterName() . (isset($params['action']) ? ':' . $params['action'] : ''));
 }
예제 #11
0
 public function startup()
 {
     parent::startup();
     $this->cronRow = $this->logCron->getCronRow();
     if (!is_object($this->cronRow) || $this->cronRow->id < 1) {
         $e = new \Nette\InvalidArgumentException("Uknown cron detected!");
         $this->logCron->logError($e);
         $this->logCron->finishTask();
     } else {
         $this->logCronRow = $this->logCron->createLogFromCronId($this->cronRow->id);
     }
     $cronRow = $this->cronRow;
     if ($this->cronRow && isset($this->cronRow->running_flag) && $this->cronRow->running_flag == 1 && $this->context->parameters['productionMode']) {
         $now = new \DateTime();
         $diff = $now->diff($this->cronRow->upd_dt);
         // if cron was started more than 20 minutes ago, run again. There is big change, there was some error in cron which prevent finishing
         if ($diff->d > 0 || $diff->h > 0 || $diff->i > 20) {
             $this->cronRow->update(array('running_flag' => 0, 'upd_process_id' => 'BasePresenter::startup()'));
         } else {
             // if cron is requested when previous request is still running, do not allow to run again
             $this->logCron->setSkippedFlag(true);
             $this->logCron->finishTask();
         }
     }
     $this->cronRow->update(array('running_flag' => 1));
     // set NewRelic background Job
     // If no argument or true as an argument is given, mark the current transaction as a background job.
     // If false is passed as an argument, mark the transaction as a web transaction.
     if (extension_loaded('newrelic')) {
         newrelic_background_job(1);
     }
     // Check for same tasks in db in interval
     $dateCheck = new \DateTime();
     $dateCheck->add(\DateInterval::createFromDateString('-30 seconds'));
     $multipleCheck = $this->logCronEntity->getTable()->where("del_flag", 0)->where("cron_id", $this->cronRow->id)->where("ins_dt >= ?", $dateCheck)->count('*');
     // Same task run already in period, terminate()!
     $multipleCheck = 0;
     if ($multipleCheck > 0) {
         $this->logCron->setSkippedFlag(true);
         $this->logCron->finishTask();
     }
 }
예제 #12
0
 /**
  * {@inheritdoc}
  */
 public function process(Message $message, array $options)
 {
     if ($this->extensionLoaded) {
         newrelic_start_transaction($options['new_relic_app_name'], $options['new_relic_license']);
         newrelic_name_transaction($options['new_relic_transaction_name']);
         newrelic_background_job(true);
     }
     try {
         $result = $this->processor->process($message, $options);
     } catch (\Exception $e) {
         if ($this->extensionLoaded) {
             newrelic_notice_error(null, $e);
             newrelic_end_transaction();
         }
         throw $e;
     }
     if ($this->extensionLoaded) {
         newrelic_end_transaction();
     }
     return $result;
 }
 /**
  * {@inheritdoc}
  */
 public function disableBackgroundJob()
 {
     newrelic_background_job(false);
 }
예제 #14
0
 public static function markAsBackground()
 {
     if (extension_loaded('newrelic')) {
         newrelic_background_job(true);
     }
 }
예제 #15
0
 public function index()
 {
     if (function_exists('newrelic_background_job')) {
         newrelic_background_job(true);
     }
     // Debug
     $debug = "";
     // Get all active scheduled items
     foreach (ORM::factory('scheduler')->where('scheduler_active', '1')->find_all() as $scheduler) {
         $scheduler_id = $scheduler->id;
         $scheduler_last = $scheduler->scheduler_last;
         // Next run time
         $scheduler_weekday = $scheduler->scheduler_weekday;
         // Day of the week
         $scheduler_day = $scheduler->scheduler_day;
         // Day of the month
         $scheduler_hour = $scheduler->scheduler_hour;
         // Hour
         $scheduler_minute = $scheduler->scheduler_minute;
         // Minute
         // Controller that performs action
         $scheduler_controller = $scheduler->scheduler_controller;
         if ($scheduler_day <= -1) {
             // Ran every day?
             $scheduler_day = "*";
         }
         if ($scheduler_weekday <= -1) {
             // Ran every day?
             $scheduler_weekday = "*";
         }
         if ($scheduler_hour <= -1) {
             // Ran every hour?
             $scheduler_hour = "*";
         }
         if ($scheduler_minute <= -1) {
             // Ran every minute?
             $scheduler_minute = "*";
         }
         $scheduler_cron = $scheduler_minute . " " . $scheduler_hour . " " . $scheduler_day . " * " . $scheduler_weekday;
         //Start new cron parser instance
         $cron = new CronParser();
         if (!$cron->calcLastRan($scheduler_cron)) {
             echo "Error parsing CRON";
         }
         $lastRan = $cron->getLastRan();
         //Array (0=minute, 1=hour, 2=dayOfMonth, 3=month, 4=week, 5=year)
         $cronRan = mktime($lastRan[1], $lastRan[0], 0, $lastRan[3], $lastRan[2], $lastRan[5]);
         if (isset($_GET['debug']) and $_GET['debug'] == 1) {
             $debug .= "~~~~~~~~~~~~~~~~~~~~~~~~~~~" . "<BR />~~~~~~~~~~~~~~~~~~~~~~~~~~~" . "<BR />RUNNING: " . $scheduler->scheduler_name . "<BR />~~~~~~~~~~~~~~~~~~~~~~~~~~~" . "<BR /> LAST RUN: " . date("r", $scheduler_last) . "<BR /> LAST DUE AT: " . date('r', $cron->getLastRanUnix()) . "<BR /> SCHEDULE: <a href=\"http://en.wikipedia.org/wiki/Cron\" target=\"_blank\">" . $scheduler_cron . "</a>";
         }
         if (!($scheduler_last > $cronRan) || $scheduler_last == 0) {
             $run = Dispatch::controller("{$scheduler_controller}", "scheduler/")->method('index', '');
             if ($run !== FALSE) {
                 // Set last time of last execution
                 $schedule_time = time();
                 $scheduler->scheduler_last = $schedule_time;
                 $scheduler->save();
                 // Record Action to Log
                 $scheduler_log = new Scheduler_Log_Model();
                 $scheduler_log->scheduler_id = $scheduler_id;
                 $scheduler_log->scheduler_name = $scheduler->scheduler_name;
                 $scheduler_log->scheduler_status = "200";
                 $scheduler_log->scheduler_date = $schedule_time;
                 $scheduler_log->save();
                 if (isset($_GET['debug']) and $_GET['debug'] == 1) {
                     $debug .= "<BR /> STATUS: {{ EXECUTED }}";
                 }
             } else {
                 if (isset($_GET['debug']) and $_GET['debug'] == 1) {
                     $debug .= "<BR /> STATUS: {{ SCHEDULER NOT FOUND! }}";
                 }
             }
         } else {
             if (isset($_GET['debug']) and $_GET['debug'] == 1) {
                 $debug .= "<BR /> STATUS: {{ NOT RUN }}";
             }
         }
         if (isset($_GET['debug']) and $_GET['debug'] == 1) {
             //$debug .= "<BR /><BR />CRON DEBUG:<BR \>".nl2br($cron->getDebug());
             $debug .= "<BR \\>~~~~~~~~~~~~~~~~~~~~~~~~~~~<BR />~~~~~~~~~~~~~~~~~~~~~~~~~~~<BR /><BR /><BR />";
         }
     }
     // If DEBUG is TRUE echo DEBUG info instead of transparent GIF
     if (isset($_GET['debug']) and $_GET['debug'] == 1) {
         echo $debug;
     } else {
         // Transparent GIF
         Header("Content-type: image/gif");
         Header("Expires: Wed, 11 Nov 1998 11:11:11 GMT");
         Header("Cache-Control: no-cache");
         Header("Cache-Control: must-revalidate");
         Header("Content-Length: 49");
         echo pack('H*', '47494638396101000100910000000000ffffffff' . 'ffff00000021f90405140002002c000000000100' . '01000002025401003b');
     }
 }
예제 #16
0
 /**
  * Mark a transaction as a background job.
  *
  * @link https://docs.newrelic.com/docs/agents/php-agent/configuration/php-agent-api#api-bg
  *
  * @param bool $flag
  */
 public function backgroundJob($flag = true)
 {
     if ($this->isLoaded()) {
         newrelic_background_job($flag);
     }
 }
예제 #17
0
 /**
  * Whether to mark as a background job or web application.
  *
  * @param boolean $flag true if background job, false if web application
  */
 public function backgroundJob($flag = true)
 {
     if ($this->skip()) {
         return;
     }
     newrelic_background_job($flag);
 }
    {
        $controller = get_class($this->owner);
        $this->transactionName = "{$controller}/{$action}";
    }
    function __destruct()
    {
        if ($this->transactionName) {
            //Debug::message("newrelic_name_transaction($this->transactionName)");
            if (extension_loaded('newrelic')) {
                newrelic_name_transaction($this->transactionName);
            }
            if ($memberID = Session::get('loggedInAs')) {
                //Debug::message("newrelic_add_custom_parameter('memberID', $memberID)");
                if (extension_loaded('newrelic')) {
                    newrelic_add_custom_parameter('memberID', $memberID);
                }
            }
        }
    }
}
// Set-up calls
if (extension_loaded('newrelic')) {
    //newrelic_add_custom_tracer("Director::direct,SSViewer::process");
    // Set the name to the vhost for client-side scripts
    // To do: get robust way of picking the canoncial hostname for www requests too
    if (Director::is_cli() && isset($_SERVER['HTTP_HOST'])) {
        newrelic_set_appname($_SERVER['HTTP_HOST']);
    }
    // Distinguish background from web requests more reliably
    newrelic_background_job(Director::is_cli());
}
<?php

define('SS_NR_BASE', basename(dirname(__FILE__)));
Config::inst()->update('NewRelicPerformanceReport', 'menu_icon', SS_NR_BASE . '/images/new-relic.png');
//Configure new relic monitoring
if (extension_loaded('newrelic')) {
    //Bind to the controller class
    Controller::add_extension('NewRelicControllerHook');
    //If we have an application name constant ensure New Relic knows what the name is
    if (defined('SS_NR_APPLICATION_NAME')) {
        newrelic_set_appname(SS_NR_APPLICATION_NAME);
    }
    //If we're in cli make sure New Relic is aware that we are
    if (Director::is_cli()) {
        newrelic_background_job(true);
    }
    //New Relic error binders
    if (Director::isLive() || defined('SS_NR_FORCE_ENABLE_LOGGING')) {
        SS_Log::add_writer(new NewRelicErrorLogger(), SS_Log::NOTICE);
        SS_Log::add_writer(new NewRelicErrorLogger(), SS_Log::WARN);
        SS_Log::add_writer(new NewRelicErrorLogger(), SS_Log::ERR);
    }
}
예제 #20
0
 public function markAsBackground()
 {
     return newrelic_background_job(true);
 }
예제 #21
0
 /**
  * If no argument or true as an argument is given, mark the current transaction as a background job. If false is
  * passed as an argument, mark the transaction as a web application.
  *
  * @param bool $flag
  *
  * @return $this
  */
 public function markAsBackgroundJob($flag = true)
 {
     if ($this->active) {
         newrelic_background_job((bool) $flag);
     }
     return $this;
 }
예제 #22
0
 /**
  * Listen to the cron event always
  *
  * @access public
  * @param Varien_Event_Observer $observer
  * @return $this
  */
 public function crontab($observer)
 {
     if (function_exists('newrelic_background_job')) {
         newrelic_background_job(true);
     }
 }
예제 #23
0
 /**
  * {@inheritdoc}
  */
 public function backgroundJob($flag = true)
 {
     if (!$this->extensionLoaded()) {
         return $this;
     }
     newrelic_background_job((bool) $flag);
     return $this;
 }
예제 #24
0
 /**
  * Mark transaction as background or web transaction
  *
  * @param string $name
  * @return null|void
  */
 public function setMetricClass($name)
 {
     if ($name == 'background') {
         newrelic_background_job(true);
     }
 }
예제 #25
0
 /**
  * {@inheritdoc}
  */
 public function backgroundJob($flag = true)
 {
     if ($this->extensionLoaded()) {
         newrelic_background_job((bool) $flag);
     }
 }