mirror of
https://github.com/bcicen/ctop.git
synced 2025-12-06 15:16:41 +08:00
Added Ports information to the expanded view
This commit is contained in:
committed by
Kenan Rhoton
parent
d81d10ec27
commit
b2165b6a29
@@ -46,6 +46,7 @@ func (c *Docker) Start() {
|
||||
c.ReadCPU(s)
|
||||
c.ReadMem(s)
|
||||
c.ReadNet(s)
|
||||
c.ReadPorts()
|
||||
c.ReadIO(s)
|
||||
c.stream <- c.Metrics
|
||||
}
|
||||
@@ -89,6 +90,27 @@ func (c *Docker) ReadMem(stats *api.Stats) {
|
||||
c.MemPercent = round((float64(c.MemUsage) / float64(c.MemLimit)) * 100)
|
||||
}
|
||||
|
||||
func (c *Docker) ReadPorts() {
|
||||
containers, err := c.client.ListContainers(api.ListContainersOptions{All: true})
|
||||
if err != nil {
|
||||
log.Infof("Error gathering containers")
|
||||
return
|
||||
}
|
||||
for _, container := range containers {
|
||||
if container.ID == c.id {
|
||||
c.PortsOpen = [][]int64{}
|
||||
c.PortsExposed = []int64{}
|
||||
for _, port := range container.Ports {
|
||||
if port.PublicPort > 0 {
|
||||
c.PortsOpen = append(c.PortsOpen, []int64{port.PrivatePort, port.PublicPort})
|
||||
} else {
|
||||
c.PortsExposed = append(c.PortsExposed, port.PrivatePort)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Docker) ReadNet(stats *api.Stats) {
|
||||
var rx, tx int64
|
||||
for _, network := range stats.Networks {
|
||||
|
||||
@@ -18,18 +18,22 @@ type Metrics struct {
|
||||
IOBytesRead int64
|
||||
IOBytesWrite int64
|
||||
Pids int
|
||||
PortsExposed []int64
|
||||
PortsOpen [][]int64
|
||||
}
|
||||
|
||||
func NewMetrics() Metrics {
|
||||
return Metrics{
|
||||
CPUUtil: -1,
|
||||
NetTx: -1,
|
||||
NetRx: -1,
|
||||
MemUsage: -1,
|
||||
MemPercent: -1,
|
||||
IOBytesRead: -1,
|
||||
IOBytesWrite: -1,
|
||||
Pids: -1,
|
||||
CPUUtil: -1,
|
||||
NetTx: -1,
|
||||
NetRx: -1,
|
||||
MemUsage: -1,
|
||||
MemPercent: -1,
|
||||
IOBytesRead: -1,
|
||||
IOBytesWrite: -1,
|
||||
Pids: -1,
|
||||
PortsExposed: nil,
|
||||
PortsOpen: nil,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user