Skip to content

Commit

Permalink
Add node or pod raw metric client show (#102)
Browse files Browse the repository at this point in the history
  • Loading branch information
caoyingjunz authored Sep 9, 2023
1 parent 20e1ca6 commit 84ac612
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions practise/k8s-practise/node-metrics.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package main

import (
"context"
"fmt"

"go-learning/practise/k8s-practise/app"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
resourceclient "k8s.io/metrics/pkg/client/clientset/versioned/typed/metrics/v1beta1"
)

func main() {
config, err := app.BuildClientConfig("")
if err != nil {
panic(err)
}

metricClient, err := resourceclient.NewForConfig(config)
if err != nil {
panic(err)
}
nodeMetrics, err := metricClient.NodeMetricses().List(context.TODO(), metav1.ListOptions{})
if err != nil {
panic(err)
}

for _, nodeMetric := range nodeMetrics.Items {
fmt.Println(nodeMetric)
}
}

0 comments on commit 84ac612

Please sign in to comment.