|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Jabe\Engine\Impl\Metrics\Reporter; |
|
4
|
|
|
|
|
5
|
|
|
use Jabe\Engine\Impl\ProcessEngineLogger; |
|
6
|
|
|
use Jabe\Engine\Impl\Interceptor\CommandExecutorInterface; |
|
7
|
|
|
use Jabe\Engine\Impl\Metrics\{ |
|
8
|
|
|
Meter, |
|
9
|
|
|
MetricsLogger, |
|
10
|
|
|
MetricsRegistry |
|
11
|
|
|
}; |
|
12
|
|
|
use Jabe\Engine\Impl\Persistence\Entity\MeterLogEntity; |
|
13
|
|
|
use Jabe\Engine\Impl\Util\ClockUtil; |
|
14
|
|
|
use Jabe\Engine\Impl\Util\Concurrent\TimerTask; |
|
15
|
|
|
|
|
16
|
|
|
class MetricsCollectionTask extends TimerTask |
|
17
|
|
|
{ |
|
18
|
|
|
//private final static MetricsLogger LOG = ProcessEngineLogger.METRICS_LOGGER; |
|
19
|
|
|
protected $metricsRegistry; |
|
20
|
|
|
protected $commandExecutor; |
|
21
|
|
|
protected $reporterId = null; |
|
22
|
|
|
|
|
23
|
|
|
public function __construct(MetricsRegistry $metricsRegistry, CommandExecutorInterface $commandExecutor) |
|
24
|
|
|
{ |
|
25
|
|
|
$this->metricsRegistry = $metricsRegistry; |
|
26
|
|
|
$this->commandExecutor = $commandExecutor; |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
public function run(): void |
|
30
|
|
|
{ |
|
31
|
|
|
try { |
|
32
|
|
|
$this->collectMetrics(); |
|
33
|
|
|
} catch (\Exception $e) { |
|
34
|
|
|
try { |
|
35
|
|
|
//LOG.couldNotCollectAndLogMetrics(e); |
|
36
|
|
|
} catch (\Exception $ex) { |
|
|
|
|
|
|
37
|
|
|
// ignore if log can't be written |
|
38
|
|
|
} |
|
39
|
|
|
} |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
protected function collectMetrics(): void |
|
43
|
|
|
{ |
|
44
|
|
|
$logs = []; |
|
45
|
|
|
foreach (array_values($this->metricsRegistry->getDbMeters()) as $meter) { |
|
46
|
|
|
$logs[] = new MeterLogEntity( |
|
47
|
|
|
$meter->getName(), |
|
48
|
|
|
$this->reporterId, |
|
49
|
|
|
$meter->getAndClear(), |
|
50
|
|
|
ClockUtil::getCurrentTime()->format('c') |
|
51
|
|
|
); |
|
52
|
|
|
} |
|
53
|
|
|
$this->commandExecutor->execute(new MetricsCollectionCmd($logs)); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
public function getReporter(): ?string |
|
57
|
|
|
{ |
|
58
|
|
|
return $this->reporterId; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
public function setReporter(string $reporterId): void |
|
62
|
|
|
{ |
|
63
|
|
|
$this->reporterId = $reporterId; |
|
64
|
|
|
} |
|
65
|
|
|
} |
|
66
|
|
|
|
This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.
Unreachable code is most often the result of
return,dieorexitstatements that have been added for debug purposes.In the above example, the last
return falsewill never be executed, because a return statement has already been met in every possible execution path.