container: add start time, process count and page fault metrics (#2566)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Jan-Otto Kröpke <mail@jkroepke.de>
This commit is contained in:
Jan-Otto Kröpke
2026-10-09 01:48:17 +02:00
committed by GitHub
co-authored by Claude Opus 5.5
parent 301eef493b
commit 64046fb91f
9 changed files with 241 additions and 41 deletions
+6 -2
View File
@@ -23,6 +23,7 @@ import (
"net/http"
"strings"
"testing"
"time"
"github.com/stretchr/testify/require"
"golang.org/x/sys/windows"
@@ -69,7 +70,7 @@ func containersResponse() message {
message(4, message{}.string(1, "mcr.microsoft.com/windows/nanoserver")).
string(5, "sha256:1234").
varint(6, uint64(ContainerRunning)).
varint(7, 1700000000000000000)
varint(7, 1700000000123456789)
nanoserver = append(nanoserver, labels(8, "io.kubernetes.pod.name", "pod")...)
nanoserver = append(nanoserver, labels(9, "io.kubernetes.container.restartCount", "2")...)
@@ -100,9 +101,12 @@ func TestDecodeListContainersResponse(t *testing.T) {
containers, err := decodeListContainersResponse(containersResponse())
require.NoError(t, err)
require.Equal(t, []Container{
{ID: "abc", PodSandboxID: "sandbox-1", Name: "nanoserver", State: ContainerRunning},
{ID: "abc", PodSandboxID: "sandbox-1", Name: "nanoserver", State: ContainerRunning, CreatedAt: time.Unix(0, 1700000000123456789)},
{ID: "def", Name: "other", State: ContainerCreated},
}, containers)
require.Equal(t, int64(1700000000123456789), containers[0].CreatedAt.UnixNano())
require.True(t, containers[1].CreatedAt.IsZero())
}
func TestDecodeListPodSandboxResponse(t *testing.T) {
+8
View File
@@ -18,6 +18,8 @@
package cri
import (
"time"
"google.golang.org/protobuf/encoding/protowire"
)
@@ -54,6 +56,8 @@ type Container struct {
// Name is the container name from the Kubernetes pod spec.
Name string
State ContainerState
// CreatedAt is the creation time of the container. It is zero if the runtime did not set it.
CreatedAt time.Time
}
// PodSandbox is the subset of runtime.v1.PodSandbox used by the exporter.
@@ -170,6 +174,10 @@ func decodeContainer(b []byte) (Container, error) {
})
case f.is(6, protowire.VarintType):
container.State = ContainerState(f.value)
case f.is(7, protowire.VarintType): // created_at, int64 in nanoseconds since the Unix epoch
if f.value != 0 {
container.CreatedAt = time.Unix(0, int64(f.value))
}
}
return nil