@@ -24,12 +24,15 @@ package org.powerapi.app
24
24
25
25
import java .lang .management .ManagementFactory
26
26
27
+ import com .spotify .docker .client .exceptions .{ContainerNotFoundException , DockerException }
28
+ import com .spotify .docker .client .messages .ContainerInfo
29
+ import com .spotify .docker .client .{DefaultDockerClient , DockerClient }
30
+
27
31
import scala .concurrent .Await
28
32
import scala .concurrent .duration .DurationInt
29
33
import scala .sys
30
34
import scala .sys .process .stringSeqToProcess
31
35
import scala .util .matching .Regex
32
-
33
36
import org .powerapi .core .power ._
34
37
import org .powerapi .core .target ._
35
38
import org .powerapi .module .cpu .dvfs .CpuDvfsModule
@@ -39,7 +42,7 @@ import org.powerapi.module.extpowermeter.g5komegawatt.G5kOmegaWattModule
39
42
import org .powerapi .module .extpowermeter .powerspy .PowerSpyModule
40
43
import org .powerapi .module .extpowermeter .rapl .RAPLModule
41
44
import org .powerapi .module .libpfm .{LibpfmCoreModule , LibpfmCoreProcessModule , LibpfmHelper , LibpfmModule , LibpfmProcessModule }
42
- import org .powerapi .reporter .{InfluxDisplay , ConsoleDisplay , FileDisplay , JFreeChartDisplay }
45
+ import org .powerapi .reporter .{ConsoleDisplay , FileDisplay , InfluxDisplay , JFreeChartDisplay }
43
46
import org .powerapi .{PowerDisplay , PowerMeter , PowerMonitoring }
44
47
45
48
/**
@@ -59,6 +62,8 @@ object PowerAPI extends App {
59
62
@ volatile var powerMeters = Seq [PowerMeter ]()
60
63
@ volatile var monitors = Seq [PowerMonitoring ]()
61
64
65
+ lazy val docker : DockerClient = new DefaultDockerClient (" unix:///var/run/docker.sock" )
66
+
62
67
val shutdownHookThread = scala.sys.ShutdownHookThread {
63
68
println(" PowerAPI is shutting down ..." )
64
69
monitors.foreach(monitor => monitor.cancel())
@@ -94,7 +99,7 @@ object PowerAPI extends App {
94
99
|usage: ./powerapi modules procfs-cpu-simple|sigar-cpu-simple|cpu-dvfs|libpfm|libpfm-process|libpfm-core|libpfm-core-process|powerspy|g5k-omegawatt|rapl|disk-simple (1, *) *--prefix [name]*
95
100
| monitor (1, *)
96
101
| --frequency $MILLISECONDS
97
- | --self (0, 1) --pids [pid, ...] (0, *) --apps [app, ...] (0, *) --containers [id , ...] (0, *) | all (0, 1)
102
+ | --self (0, 1) --pids [pid, ...] (0, *) --apps [app, ...] (0, *) --containers [name or ID , ...] (0, *) | all (0, 1)
98
103
| --agg max|min|mean|median|sum
99
104
| --console (0, 1) --file $FILEPATH (0, *) --chart (0, 1) --influx $HOST $PORT $USER $PWD $DB $MEASUREMENT (0, *)
100
105
| duration [s]
@@ -153,7 +158,22 @@ object PowerAPI extends App {
153
158
), tail)
154
159
case " --containers" :: value :: tail if validate(containersR, value) =>
155
160
cliMonitorsSubcommand(options, currentMonitor + (' targets ->
156
- (currentMonitor.getOrElse(' targets , Set [Any ]()).asInstanceOf [Set [Any ]] ++ value.split(" ," ).map(container => Container (container)))
161
+ (currentMonitor.getOrElse(' targets , Set [Any ]()).asInstanceOf [Set [Any ]] ++ value.split(" ," ).map {
162
+ container =>
163
+ try {
164
+ val targetInformation : ContainerInfo = docker.inspectContainer(container)
165
+ Container (targetInformation.id(), targetInformation.name())
166
+ }
167
+ catch {
168
+ case _ : ContainerNotFoundException =>
169
+ println(" Container '" + container + " ' does not exist" )
170
+ sys.exit(1 )
171
+
172
+ case _ : DockerException =>
173
+ println(" The Docker socket is unavailable, please check if Docker daemon is running and its socket exists at the following path : '/var/run/docker.sock'" )
174
+ sys.exit(1 )
175
+ }
176
+ })
157
177
), tail)
158
178
case " --all" :: tail =>
159
179
cliMonitorsSubcommand(options, currentMonitor + (' targets ->
0 commit comments