-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
81da40a
commit 4e2de42
Showing
15 changed files
with
246 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
package app | ||
|
||
const ( | ||
Ver = "2.4.0" | ||
Ver = "2.5.0" | ||
Name = "docker-color-output" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,154 @@ | ||
package cmd | ||
|
||
import ( | ||
"strings" | ||
|
||
"github.com/devemio/docker-color-output/internal/layout" | ||
"github.com/devemio/docker-color-output/pkg/color" | ||
"github.com/devemio/docker-color-output/pkg/util/number" | ||
) | ||
|
||
const ( | ||
DockerStatsContainerID = "CONTAINER ID" | ||
DockerStatsName = "NAME" | ||
DockerStatsCPUPercent = "CPU %" | ||
DockerStatsMemUsage = "MEM USAGE / LIMIT" | ||
DockerStatsMemPercent = "MEM %" | ||
DockerStatsNetIO = "NET I/O" | ||
DockerStatsBlockIO = "BLOCK I/O" | ||
DockerStatsPIDs = "PIDS" | ||
) | ||
|
||
const ( | ||
cpuPercentThresholdMedium = 50 | ||
cpuPercentThresholdHigh = 90 | ||
|
||
memPercentThresholdMedium = 50 | ||
memPercentThresholdHigh = 90 | ||
|
||
netIOThresholdHigh = 10 | ||
|
||
blockIOThresholdHigh = 10 | ||
|
||
pidsThresholdHigh = 100 | ||
) | ||
|
||
type DockerStats struct{} | ||
|
||
func (c *DockerStats) Columns() []string { | ||
return []string{ | ||
DockerStatsContainerID, // | ||
DockerStatsName, // | ||
DockerStatsCPUPercent, // | ||
DockerStatsMemUsage, // | ||
DockerStatsMemPercent, // | ||
DockerStatsNetIO, // | ||
DockerStatsBlockIO, // | ||
DockerStatsPIDs, // | ||
} | ||
} | ||
|
||
func (c *DockerStats) Format(rows layout.Row, col layout.Column) string { | ||
v := string(rows[col]) | ||
|
||
switch col { | ||
case DockerStatsContainerID: | ||
return c.ContainerID(v) | ||
case DockerStatsName: | ||
return c.Name(v) | ||
case DockerStatsCPUPercent: | ||
return c.CPUPercent(v) | ||
case DockerStatsMemUsage: | ||
return c.MemUsage(v) | ||
case DockerStatsMemPercent: | ||
return c.MemPercent(v) | ||
case DockerStatsNetIO: | ||
return c.NetIO(v) | ||
case DockerStatsBlockIO: | ||
return c.BlockIO(v) | ||
case DockerStatsPIDs: | ||
return c.PIDs(v) | ||
default: | ||
return v | ||
} | ||
} | ||
|
||
func (*DockerStats) ContainerID(v string) string { | ||
return color.DarkGray(v) | ||
} | ||
|
||
func (c *DockerStats) Name(v string) string { | ||
return color.White(v) | ||
} | ||
|
||
func (c *DockerStats) CPUPercent(v string) string { | ||
percent := number.ParseFloat(v) | ||
|
||
switch { | ||
case percent >= cpuPercentThresholdHigh: | ||
return color.Red(v) | ||
case percent >= cpuPercentThresholdMedium: | ||
return color.Brown(v) | ||
default: | ||
return v | ||
} | ||
} | ||
|
||
func (c *DockerStats) MemUsage(v string) string { | ||
parts := strings.Split(v, "/") | ||
|
||
return parts[0] + color.DarkGray("/"+parts[1]) | ||
} | ||
|
||
func (c *DockerStats) MemPercent(v string) string { | ||
percent := number.ParseFloat(v) | ||
|
||
switch { | ||
case percent >= memPercentThresholdHigh: | ||
return color.Red(v) | ||
case percent >= memPercentThresholdMedium: | ||
return color.Brown(v) | ||
default: | ||
return v | ||
} | ||
} | ||
|
||
func (*DockerStats) NetIO(v string) string { | ||
parts := strings.Split(v, "/") | ||
|
||
for i := range parts { | ||
if strings.Contains(parts[i], "GB") { | ||
if number.ParseFloat(parts[i]) >= netIOThresholdHigh { | ||
parts[i] = color.Red(parts[i]) | ||
} else { | ||
parts[i] = color.Brown(parts[i]) | ||
} | ||
} | ||
} | ||
|
||
return parts[0] + color.DarkGray("/") + parts[1] | ||
} | ||
|
||
func (*DockerStats) BlockIO(v string) string { | ||
parts := strings.Split(v, "/") | ||
|
||
for i := range parts { | ||
if strings.Contains(parts[i], "GB") { | ||
if number.ParseFloat(parts[i]) >= blockIOThresholdHigh { | ||
parts[i] = color.Red(parts[i]) | ||
} else { | ||
parts[i] = color.Brown(parts[i]) | ||
} | ||
} | ||
} | ||
|
||
return parts[0] + color.DarkGray("/") + parts[1] | ||
} | ||
|
||
func (*DockerStats) PIDs(v string) string { | ||
if number.ParseFloat(v) >= pidsThresholdHigh { | ||
return color.Red(v) | ||
} | ||
|
||
return color.LightCyan(v) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
CONTAINER ID NAME CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS | ||
e39ba801c0e1 nginx 90.00% 13.53MiB / 7.657GiB 50.17% 10.8MB / 42.1GB 0B / 12.3kB 17 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[1;34mCONTAINER ID[0m [1;34mNAME[0m [1;34mCPU %[0m [1;34mMEM USAGE / LIMIT[0m [1;34mMEM %[0m [1;34mNET I/O[0m [1;34mBLOCK I/O[0m [1;34mPIDS[0m | ||
[1;30me39ba801c0e1[0m [1;37mnginx[0m [0;31m90.00%[0m 13.53MiB [1;30m/ 7.657GiB[0m [0;33m50.17%[0m 10.8MB [1;30m/[0m[0;31m 42.1GB[0m 0B [1;30m/[0m 12.3kB [1;36m17[0m |