Пример #1
0
 function __construct($config)
 {
     parent::__construct();
     if (!isset($config['name'])) {
         throw new \Exception("Argument missing: \$config['name']");
     }
     $this->id = uniqid();
     $this->config = $config;
     $this->probes = new stdClass();
     if (isset($config['probes'])) {
         foreach ($config['probes'] as $name => $args) {
             if (gettype($args) !== 'array') {
                 $args = array('args' => $args);
             }
             $args['name'] = $name;
             $this->addProbe($args);
         }
     }
     $_this = $this;
     $this->addProbe(array('name' => '_probes', 'sampleThreshold' => 0, 'instant' => true, 'types' => array('object'), 'args' => function () use($_this) {
         $args_array = array();
         foreach ($_this->probes as $name => $probe) {
             $arg = array('name' => $name, 'types' => $probe->types, 'instant' => $probe->instant, 'sampleThreshold' => $probe->sampleThreshold);
             $args_array[] = array($arg);
         }
         return $args_array;
     }));
 }
Пример #2
0
 function __construct($config)
 {
     parent::__construct();
     $this->id = uniqid();
     // multiple consumers support
     $this->consumerTimers = array();
     // for interval sampling probes
     $this->disableDelay = null;
     if (gettype($config) === 'string') {
         $config = array('name' => $config, 'types' => array_slice(func_get_args(), 1));
     }
     $this->name = $config['name'];
     if (array_key_exists('types', $config) && count($config['types']) > 0) {
         $this->types = $config['types'];
     } else {
         $this->types = array('number');
     }
     $this->enabled = isset($config['enabled']) ? $config['enabled'] : false;
     $this->instant = isset($config['instant']) ? $config['instant'] : false;
     $this->sampleThreshold = isset($config['sampleThreshold']) ? $config['sampleThreshold'] : 1000;
     if (isset($config['args'])) {
         if (gettype($config['args'] === 'array')) {
             $this->args = $config['args'];
         } else {
             $this->args = array($config['args']);
         }
         if (gettype($this->args) === 'array' && count($this->args) === 1 && gettype($this->args[0]) === 'function reference') {
             $this->args = $this->args[0];
         }
     } else {
         $this->args = array_map(function ($type) {
             return $type === 'number' ? 0 : '';
         }, $this->types);
     }
     $this->hits = 0;
 }