dongnao6858 2018-08-26 19:36
浏览 324

如何通过client-go和golang检索kubernetes指标

I want to access metrics from kubernetes with golang. Something like cpu and memory per node as well as the same for pods and/or namespaces.

I am kind of lost here because the documentation is not as clear as it could be.

I have learned that there is heapster (which is deprecated according to the github repo). There is also metric server and a rest api.

Where can I find some examples to get started? I do not want to install another app, package or service in kubernetes. I'd like to get the information as native as possible. What is the preferred way to access these information with client-go and golang?

  • 写回答

3条回答 默认 最新

  • duanchigeng4313 2018-10-09 10:00
    关注

    Here's an example of using the REST API to query node metrics and return a []byte in JSON format. Replace "nodes" with "pods" to get pod/container metrics.

    data, err := clientset.RESTClient().Get().AbsPath("apis/metrics.k8s.io/v1beta1/nodes").DoRaw()
    
    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度