Add ctr metrics support for Windows/LCOW containers
Signed-off-by: Justin Terry (VM) <juterry@microsoft.com>
This commit is contained in:
parent
178469e2ae
commit
37b56cafc6
@ -25,6 +25,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"text/tabwriter"
|
"text/tabwriter"
|
||||||
|
|
||||||
|
wstats "github.com/Microsoft/hcsshim/cmd/containerd-shim-runhcs-v1/stats"
|
||||||
v1 "github.com/containerd/cgroups/stats/v1"
|
v1 "github.com/containerd/cgroups/stats/v1"
|
||||||
"github.com/containerd/containerd/cmd/ctr/commands"
|
"github.com/containerd/containerd/cmd/ctr/commands"
|
||||||
"github.com/containerd/typeurl"
|
"github.com/containerd/typeurl"
|
||||||
@ -77,9 +78,17 @@ var metricsCommand = cli.Command{
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
data, ok := anydata.(*v1.Metrics)
|
var (
|
||||||
if !ok {
|
data *v1.Metrics
|
||||||
return errors.New("cannot convert metric data to cgroups.Metrics")
|
windowsStats *wstats.Statistics
|
||||||
|
)
|
||||||
|
switch v := anydata.(type) {
|
||||||
|
case *v1.Metrics:
|
||||||
|
data = v
|
||||||
|
case *wstats.Statistics:
|
||||||
|
windowsStats = v
|
||||||
|
default:
|
||||||
|
return errors.New("cannot convert metric data to cgroups.Metrics or windows.Statistics")
|
||||||
}
|
}
|
||||||
|
|
||||||
switch context.String(formatFlag) {
|
switch context.String(formatFlag) {
|
||||||
@ -87,20 +96,18 @@ var metricsCommand = cli.Command{
|
|||||||
w := tabwriter.NewWriter(os.Stdout, 1, 8, 4, ' ', 0)
|
w := tabwriter.NewWriter(os.Stdout, 1, 8, 4, ' ', 0)
|
||||||
fmt.Fprintf(w, "ID\tTIMESTAMP\t\n")
|
fmt.Fprintf(w, "ID\tTIMESTAMP\t\n")
|
||||||
fmt.Fprintf(w, "%s\t%s\t\n\n", metric.ID, metric.Timestamp)
|
fmt.Fprintf(w, "%s\t%s\t\n\n", metric.ID, metric.Timestamp)
|
||||||
|
if data != nil {
|
||||||
fmt.Fprintf(w, "METRIC\tVALUE\t\n")
|
printCgroupMetricsTable(w, data)
|
||||||
if data.Memory != nil {
|
} else {
|
||||||
fmt.Fprintf(w, "memory.usage_in_bytes\t%d\t\n", data.Memory.Usage.Usage)
|
if windowsStats.GetLinux() != nil {
|
||||||
fmt.Fprintf(w, "memory.limit_in_bytes\t%d\t\n", data.Memory.Usage.Limit)
|
printCgroupMetricsTable(w, windowsStats.GetLinux())
|
||||||
fmt.Fprintf(w, "memory.stat.cache\t%d\t\n", data.Memory.TotalCache)
|
} else if windowsStats.GetWindows() != nil {
|
||||||
}
|
printWindowsContainerStatistics(w, windowsStats.GetWindows())
|
||||||
if data.CPU != nil {
|
}
|
||||||
fmt.Fprintf(w, "cpuacct.usage\t%d\t\n", data.CPU.Usage.Total)
|
// Print VM stats if its isolated
|
||||||
fmt.Fprintf(w, "cpuacct.usage_percpu\t%v\t\n", data.CPU.Usage.PerCPU)
|
if windowsStats.VM != nil {
|
||||||
}
|
printWindowsVMStatistics(w, windowsStats.VM)
|
||||||
if data.Pids != nil {
|
}
|
||||||
fmt.Fprintf(w, "pids.current\t%v\t\n", data.Pids.Current)
|
|
||||||
fmt.Fprintf(w, "pids.limit\t%v\t\n", data.Pids.Limit)
|
|
||||||
}
|
}
|
||||||
return w.Flush()
|
return w.Flush()
|
||||||
case formatJSON:
|
case formatJSON:
|
||||||
@ -115,3 +122,61 @@ var metricsCommand = cli.Command{
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func printCgroupMetricsTable(w *tabwriter.Writer, data *v1.Metrics) {
|
||||||
|
fmt.Fprintf(w, "METRIC\tVALUE\t\n")
|
||||||
|
if data.Memory != nil {
|
||||||
|
fmt.Fprintf(w, "memory.usage_in_bytes\t%d\t\n", data.Memory.Usage.Usage)
|
||||||
|
fmt.Fprintf(w, "memory.limit_in_bytes\t%d\t\n", data.Memory.Usage.Limit)
|
||||||
|
fmt.Fprintf(w, "memory.stat.cache\t%d\t\n", data.Memory.TotalCache)
|
||||||
|
}
|
||||||
|
if data.CPU != nil {
|
||||||
|
fmt.Fprintf(w, "cpuacct.usage\t%d\t\n", data.CPU.Usage.Total)
|
||||||
|
fmt.Fprintf(w, "cpuacct.usage_percpu\t%v\t\n", data.CPU.Usage.PerCPU)
|
||||||
|
}
|
||||||
|
if data.Pids != nil {
|
||||||
|
fmt.Fprintf(w, "pids.current\t%v\t\n", data.Pids.Current)
|
||||||
|
fmt.Fprintf(w, "pids.limit\t%v\t\n", data.Pids.Limit)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func printWindowsContainerStatistics(w *tabwriter.Writer, stats *wstats.WindowsContainerStatistics) {
|
||||||
|
fmt.Fprintf(w, "METRIC\tVALUE\t\n")
|
||||||
|
fmt.Fprintf(w, "timestamp\t%s\t\n", stats.Timestamp)
|
||||||
|
fmt.Fprintf(w, "start_time\t%s\t\n", stats.ContainerStartTime)
|
||||||
|
fmt.Fprintf(w, "uptime_ns\t%d\t\n", stats.UptimeNS)
|
||||||
|
if stats.Processor != nil {
|
||||||
|
fmt.Fprintf(w, "cpu.total_runtime_ns\t%d\t\n", stats.Processor.TotalRuntimeNS)
|
||||||
|
fmt.Fprintf(w, "cpu.runtime_user_ns\t%d\t\n", stats.Processor.RuntimeUserNS)
|
||||||
|
fmt.Fprintf(w, "cpu.runtime_kernel_ns\t%d\t\n", stats.Processor.RuntimeUserNS)
|
||||||
|
}
|
||||||
|
if stats.Memory != nil {
|
||||||
|
fmt.Fprintf(w, "memory.commit_bytes\t%d\t\n", stats.Memory.MemoryUsageCommitBytes)
|
||||||
|
fmt.Fprintf(w, "memory.commit_peak_bytes\t%d\t\n", stats.Memory.MemoryUsageCommitPeakBytes)
|
||||||
|
fmt.Fprintf(w, "memory.private_working_set_bytes\t%d\t\n", stats.Memory.MemoryUsagePrivateWorkingSetBytes)
|
||||||
|
}
|
||||||
|
if stats.Storage != nil {
|
||||||
|
fmt.Fprintf(w, "storage.read_count_normalized\t%d\t\n", stats.Storage.ReadCountNormalized)
|
||||||
|
fmt.Fprintf(w, "storage.read_size_bytes\t%d\t\n", stats.Storage.ReadSizeBytes)
|
||||||
|
fmt.Fprintf(w, "storage.write_count_normalized\t%d\t\n", stats.Storage.WriteCountNormalized)
|
||||||
|
fmt.Fprintf(w, "storage.write_size_bytes\t%d\t\n", stats.Storage.WriteSizeBytes)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func printWindowsVMStatistics(w *tabwriter.Writer, stats *wstats.VirtualMachineStatistics) {
|
||||||
|
fmt.Fprintf(w, "METRIC\tVALUE\t\n")
|
||||||
|
if stats.Processor != nil {
|
||||||
|
fmt.Fprintf(w, "vm.cpu.total_runtime_ns\t%d\t\n", stats.Processor.TotalRuntimeNS)
|
||||||
|
}
|
||||||
|
if stats.Memory != nil {
|
||||||
|
fmt.Fprintf(w, "vm.memory.working_set_bytes\t%d\t\n", stats.Memory.WorkingSetBytes)
|
||||||
|
fmt.Fprintf(w, "vm.memory.virtual_node_count\t%d\t\n", stats.Memory.VirtualNodeCount)
|
||||||
|
fmt.Fprintf(w, "vm.memory.available\t%d\t\n", stats.Memory.VmMemory.AvailableMemory)
|
||||||
|
fmt.Fprintf(w, "vm.memory.available_buffer\t%d\t\n", stats.Memory.VmMemory.AvailableMemoryBuffer)
|
||||||
|
fmt.Fprintf(w, "vm.memory.reserved\t%d\t\n", stats.Memory.VmMemory.ReservedMemory)
|
||||||
|
fmt.Fprintf(w, "vm.memory.assigned\t%d\t\n", stats.Memory.VmMemory.AssignedMemory)
|
||||||
|
fmt.Fprintf(w, "vm.memory.slp_active\t%t\t\n", stats.Memory.VmMemory.SlpActive)
|
||||||
|
fmt.Fprintf(w, "vm.memory.balancing_enabled\t%t\t\n", stats.Memory.VmMemory.BalancingEnabled)
|
||||||
|
fmt.Fprintf(w, "vm.memory.dm_operation_in_progress\t%t\t\n", stats.Memory.VmMemory.DmOperationInProgress)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
6
vendor/github.com/Microsoft/hcsshim/cmd/containerd-shim-runhcs-v1/stats/doc.go
generated
vendored
Normal file
6
vendor/github.com/Microsoft/hcsshim/cmd/containerd-shim-runhcs-v1/stats/doc.go
generated
vendored
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
package stats
|
||||||
|
|
||||||
|
import (
|
||||||
|
// go mod will not vendor without an import for metrics.proto
|
||||||
|
_ "github.com/containerd/cgroups/stats/v1"
|
||||||
|
)
|
2819
vendor/github.com/Microsoft/hcsshim/cmd/containerd-shim-runhcs-v1/stats/stats.pb.go
generated
vendored
Normal file
2819
vendor/github.com/Microsoft/hcsshim/cmd/containerd-shim-runhcs-v1/stats/stats.pb.go
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
70
vendor/github.com/Microsoft/hcsshim/cmd/containerd-shim-runhcs-v1/stats/stats.proto
generated
vendored
Normal file
70
vendor/github.com/Microsoft/hcsshim/cmd/containerd-shim-runhcs-v1/stats/stats.proto
generated
vendored
Normal file
@ -0,0 +1,70 @@
|
|||||||
|
syntax = "proto3";
|
||||||
|
|
||||||
|
package containerd.runhcs.stats.v1;
|
||||||
|
|
||||||
|
import weak "gogoproto/gogo.proto";
|
||||||
|
import "google/protobuf/timestamp.proto";
|
||||||
|
import "github.com/containerd/cgroups/stats/v1/metrics.proto";
|
||||||
|
|
||||||
|
option go_package = "github.com/Microsoft/hcsshim/cmd/containerd-shim-runhcs-v1/stats;stats";
|
||||||
|
|
||||||
|
message Statistics {
|
||||||
|
oneof container {
|
||||||
|
WindowsContainerStatistics windows = 1;
|
||||||
|
io.containerd.cgroups.v1.Metrics linux = 2;
|
||||||
|
}
|
||||||
|
VirtualMachineStatistics vm = 3 [(gogoproto.customname) = "VM"];
|
||||||
|
}
|
||||||
|
|
||||||
|
message WindowsContainerStatistics {
|
||||||
|
google.protobuf.Timestamp timestamp = 1 [(gogoproto.stdtime) = true, (gogoproto.nullable) = false];
|
||||||
|
google.protobuf.Timestamp container_start_time = 2 [(gogoproto.stdtime) = true, (gogoproto.nullable) = false];
|
||||||
|
uint64 uptime_ns = 3 [(gogoproto.customname) = "UptimeNS"];
|
||||||
|
WindowsContainerProcessorStatistics processor = 4;
|
||||||
|
WindowsContainerMemoryStatistics memory = 5;
|
||||||
|
WindowsContainerStorageStatistics storage = 6;
|
||||||
|
}
|
||||||
|
|
||||||
|
message WindowsContainerProcessorStatistics {
|
||||||
|
uint64 total_runtime_ns = 1 [(gogoproto.customname) = "TotalRuntimeNS"];
|
||||||
|
uint64 runtime_user_ns = 2 [(gogoproto.customname) = "RuntimeUserNS"];
|
||||||
|
uint64 runtime_kernel_ns = 3 [(gogoproto.customname) = "RuntimeKernelNS"];
|
||||||
|
}
|
||||||
|
|
||||||
|
message WindowsContainerMemoryStatistics {
|
||||||
|
uint64 memory_usage_commit_bytes = 1;
|
||||||
|
uint64 memory_usage_commit_peak_bytes = 2;
|
||||||
|
uint64 memory_usage_private_working_set_bytes = 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
message WindowsContainerStorageStatistics {
|
||||||
|
uint64 read_count_normalized = 1;
|
||||||
|
uint64 read_size_bytes = 2;
|
||||||
|
uint64 write_count_normalized = 3;
|
||||||
|
uint64 write_size_bytes = 4;
|
||||||
|
}
|
||||||
|
|
||||||
|
message VirtualMachineStatistics {
|
||||||
|
VirtualMachineProcessorStatistics processor = 1;
|
||||||
|
VirtualMachineMemoryStatistics memory = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
message VirtualMachineProcessorStatistics {
|
||||||
|
uint64 total_runtime_ns = 1 [(gogoproto.customname) = "TotalRuntimeNS"];
|
||||||
|
}
|
||||||
|
|
||||||
|
message VirtualMachineMemoryStatistics {
|
||||||
|
uint64 working_set_bytes = 1;
|
||||||
|
uint32 virtual_node_count = 2;
|
||||||
|
VirtualMachineMemory vm_memory = 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
message VirtualMachineMemory {
|
||||||
|
int32 available_memory = 1;
|
||||||
|
int32 available_memory_buffer = 2;
|
||||||
|
uint64 reserved_memory = 3;
|
||||||
|
uint64 assigned_memory = 4;
|
||||||
|
bool slp_active = 5;
|
||||||
|
bool balancing_enabled = 6;
|
||||||
|
bool dm_operation_in_progress = 7;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user