Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
| Total | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 15 |
| DockerStats | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 15 |
| run | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 15 |
|||
| 1 | <?php |
| 2 | |
| 3 | namespace Qmp\Laravel\DockerScale\Retriever\Providers; |
| 4 | |
| 5 | use Qmp\Laravel\DockerScale\Models\DockerStat; |
| 6 | |
| 7 | class DockerStats extends DockerAbstract |
| 8 | { |
| 9 | protected $model = DockerStat::class; |
| 10 | |
| 11 | protected $cmd = 'docker stats --no-stream --no-trunc --format "{{.ID}}|{{.Name}}|{{.Container}}|{{.CPUPerc}}|{{.MemUsage}}|{{.MemPerc}}|{{.PIDs}}"'; |
| 12 | |
| 13 | public function run() |
| 14 | { |
| 15 | $this->removeOldData(); |
| 16 | $output = $this->exec($this->cmd); |
| 17 | return array_map(function($item) { |
| 18 | $name = explode('.', $item[1]); |
| 19 | $result = [ |
| 20 | 'stat_id' => $item[0], |
| 21 | 'service' => $name[0], |
| 22 | 'task' => $name[1], |
| 23 | 'name' => $item[1], |
| 24 | 'container' => $item[2], |
| 25 | 'cpu_perc' => $item[3], |
| 26 | 'memory' => $item[4], |
| 27 | 'memory_perc' => $item[5], |
| 28 | 'pids' => $item[6], |
| 29 | ]; |
| 30 | |
| 31 | return $this->save($result); |
| 32 | }, $output); |
| 33 | } |
| 34 | } |