Skip to content

Instantly share code, notes, and snippets.

@egernst
Last active November 5, 2019 00:43
Show Gist options
  • Save egernst/c8edf639c422b3dd98e188d12adb098f to your computer and use it in GitHub Desktop.
Save egernst/c8edf639c422b3dd98e188d12adb098f to your computer and use it in GitHub Desktop.
scraping stuff
$ kubectl get --raw "/apis/metrics.k8s.io/v1beta1/namespaces/default/pods/busybox-two" | jq ' '
{
  "kind": "PodMetrics",
  "apiVersion": "metrics.k8s.io/v1beta1",
  "metadata": {
    "name": "busybox-two",
    "namespace": "default",
    "selfLink": "/apis/metrics.k8s.io/v1beta1/namespaces/default/pods/busybox-two",
    "creationTimestamp": "2019-11-05T00:40:41Z"
  },
  "timestamp": "2019-11-05T00:40:33Z",
  "window": "30s",
  "containers": [
    {
      "name": "busybox-1",
      "usage": {
        "cpu": "0",
        "memory": "684Ki"
      }
    },
    {
      "name": "busybox-2",
      "usage": {
        "cpu": "0",
        "memory": "620Ki"
      }
    }
  ]
}

Now, if I ask directly from the Kubelet,

$ curl -skL https://localhost:10250/stats/summary?only_cpu_and_memory=true | jq '.pods | .[] | select(.podRef.name=="busybox-two")'
{
  "podRef": {
    "name": "busybox-two",
    "namespace": "default",
    "uid": "fb3d9f35-d19a-4edb-ac5e-251cad1c7f27"
  },
  "startTime": "2019-11-05T00:31:47Z",
  "containers": [
    {
      "name": "busybox-1",
      "startTime": "2019-11-05T00:31:53Z",
      "cpu": {
        "time": "2019-11-05T00:42:37Z",
        "usageNanoCores": 0,
        "usageCoreNanoSeconds": 597624688
      },
      "memory": {
        "time": "2019-11-05T00:42:37Z",
        "workingSetBytes": 700416
      }
    },
    {
      "name": "busybox-2",
      "startTime": "2019-11-05T00:31:55Z",
      "cpu": {
        "time": "2019-11-05T00:42:37Z",
        "usageNanoCores": 0,
        "usageCoreNanoSeconds": 417343318
      },
      "memory": {
        "time": "2019-11-05T00:42:37Z",
        "workingSetBytes": 634880
      }
    }
  ],
  "cpu": {
    "time": "2019-11-05T00:42:23Z",
    "usageNanoCores": 11114629,
    "usageCoreNanoSeconds": 12932509507
  },
  "memory": {
    "time": "2019-11-05T00:42:23Z",
    "availableBytes": 65540096,
    "usageBytes": 147255296,
    "workingSetBytes": 144175104,
    "rssBytes": 139259904,
    "pageFaults": 0,
    "majorPageFaults": 0
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment