public function testGet()
 {
     $config = new \Zend\Config\Config(array('metrics' => array('rollingStatisticalWindowInMilliseconds' => 10000, 'rollingStatisticalWindowBuckets' => 10, 'healthSnapshotIntervalInMilliseconds' => 2000)));
     $factory = new CommandMetricsFactory(new ArrayStateStorage());
     $metrics = $factory->get('TestCommand', $config);
     $this->assertAttributeEquals(2000, 'healthSnapshotIntervalInMilliseconds', $metrics);
     $reflection = new \ReflectionClass('Odesk\\Phystrix\\CommandMetrics');
     $property = $reflection->getProperty('counter');
     $property->setAccessible(true);
     $counter = $property->getValue($metrics);
     $this->assertAttributeEquals('TestCommand', 'commandKey', $counter);
     $this->assertAttributeEquals(10000, 'rollingStatisticalWindowInMilliseconds', $counter);
     $this->assertAttributeEquals(10, 'rollingStatisticalWindowBuckets', $counter);
     $this->assertAttributeEquals(1000, 'bucketInMilliseconds', $counter);
     // 10000 / 10 = 1000
 }
Exemplo n.º 2
0
 /**
  * Finds all commands currently running (having any metrics recorded within the statistical rolling window).
  * For each command key prepares a set of statistic. Returns all sets.
  *
  * @return array
  */
 public function getStatsForCommandsRunning()
 {
     $stats = array();
     $commandKeys = $this->getCommandsRunning();
     foreach ($commandKeys as $commandKey) {
         $commandConfig = $this->getCommandConfig($commandKey);
         $commandMetrics = $this->commandMetricsFactory->get($commandKey, $commandConfig);
         $circuitBreaker = $this->circuitBreakerFactory->get($commandKey, $commandConfig, $commandMetrics);
         $healtCounts = $commandMetrics->getHealthCounts();
         $commandStats = array('type' => 'HystrixCommand', 'name' => $commandKey, 'group' => $commandKey, 'currentTime' => $this->getTimeInMilliseconds(), 'isCircuitBreakerOpen' => $circuitBreaker->isOpen(), 'errorPercentage' => $healtCounts->getErrorPercentage(), 'errorCount' => $healtCounts->getFailure(), 'requestCount' => $healtCounts->getTotal(), 'rollingCountCollapsedRequests' => 0, 'rollingCountExceptionsThrown' => $commandMetrics->getRollingCount(MetricsCounter::EXCEPTION_THROWN), 'rollingCountFailure' => $commandMetrics->getRollingCount(MetricsCounter::FAILURE), 'rollingCountFallbackFailure' => $commandMetrics->getRollingCount(MetricsCounter::FALLBACK_FAILURE), 'rollingCountFallbackRejection' => 0, 'rollingCountFallbackSuccess' => $commandMetrics->getRollingCount(MetricsCounter::FALLBACK_SUCCESS), 'rollingCountResponsesFromCache' => $commandMetrics->getRollingCount(MetricsCounter::RESPONSE_FROM_CACHE), 'rollingCountSemaphoreRejected' => 0, 'rollingCountShortCircuited' => $commandMetrics->getRollingCount(MetricsCounter::SHORT_CIRCUITED), 'rollingCountSuccess' => $commandMetrics->getRollingCount(MetricsCounter::SUCCESS), 'rollingCountThreadPoolRejected' => 0, 'rollingCountTimeout' => 0, 'currentConcurrentExecutionCount' => 0, 'latencyExecute_mean' => 0, 'latencyExecute' => array('0' => 0, '25' => 0, '50' => 0, '75' => 0, '90' => 0, '95' => 0, '99' => 0, '99.5' => 0, '100' => 0), 'latencyTotal_mean' => 15, 'latencyTotal' => array('0' => 0, '25' => 0, '50' => 0, '75' => 0, '90' => 0, '95' => 0, '99' => 0, '99.5' => 0, '100' => 0), 'propertyValue_circuitBreakerRequestVolumeThreshold' => $commandConfig->get('circuitBreaker')->get('requestVolumeThreshold'), 'propertyValue_circuitBreakerSleepWindowInMilliseconds' => $commandConfig->get('circuitBreaker')->get('sleepWindowInMilliseconds'), 'propertyValue_circuitBreakerErrorThresholdPercentage' => $commandConfig->get('circuitBreaker')->get('errorThresholdPercentage'), 'propertyValue_circuitBreakerForceOpen' => $commandConfig->get('circuitBreaker')->get('forceOpen'), 'propertyValue_circuitBreakerForceClosed' => $commandConfig->get('circuitBreaker')->get('forceClosed'), 'propertyValue_circuitBreakerEnabled' => $commandConfig->get('circuitBreaker')->get('enabled'), 'propertyValue_executionIsolationStrategy' => 'THREAD', 'propertyValue_executionIsolationThreadTimeoutInMilliseconds' => 0, 'propertyValue_executionIsolationThreadInterruptOnTimeout' => false, 'propertyValue_executionIsolationThreadPoolKeyOverride' => 'null', 'propertyValue_executionIsolationSemaphoreMaxConcurrentRequests' => 0, 'propertyValue_fallbackIsolationSemaphoreMaxConcurrentRequests' => 0, 'propertyValue_metricsRollingStatisticalWindowInMilliseconds' => $commandConfig->get('metrics')->get('rollingStatisticalWindowInMilliseconds'), 'propertyValue_requestCacheEnabled' => $commandConfig->get('requestCache')->get('enabled'), 'propertyValue_requestLogEnabled' => $commandConfig->get('requestLog')->get('enabled'), 'reportingHosts' => 1);
         $stats[] = $commandStats;
     }
     return $stats;
 }
Exemplo n.º 3
0
 /**
  * Command Metrics for this command key
  *
  * @return CommandMetrics
  */
 private function getMetrics()
 {
     return $this->commandMetricsFactory->get($this->getCommandKey(), $this->config);
 }