Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to get pod monitoring information from SDK? #528

Closed
yokiy0828 opened this issue May 7, 2018 · 18 comments
Closed

How to get pod monitoring information from SDK? #528

yokiy0828 opened this issue May 7, 2018 · 18 comments
Labels
lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed.

Comments

@yokiy0828
Copy link

How to get pod monitoring information from SDK?

@tomplus
Copy link
Member

tomplus commented Jul 1, 2018

What kind of information do you need?

@yokiy0828
Copy link
Author

Pod's CPU, memory, hard disk usage and more.

@tomplus
Copy link
Member

tomplus commented Jul 2, 2018

There are not such things in standard API. Please take a look at projects: heapster (deprecated), metric-server, cAdvisor and kube-state-metrics.

@P6rguVyrst
Copy link

Does the Python API support raw queries to the Kubernetes API? If I have the metric-server installed and want to make a raw query to Kubernetes API like: get --raw /apis/metrics.k8s.io/v1beta1/pods/

Issue: metrics-server endpoint #474

@tomplus
Copy link
Member

tomplus commented Jul 3, 2018

@P6rguVyrst yes, it should be possible. Try to use something like this:

api_client = ApiClient()
response = api_client.call_api('/apis/metrics.k8s.io/v1beta1/pods/', 'GET', preaload_content=False)
print(response.text)  # raw HTTPResponse

https://github.com/kubernetes-client/python/blob/master/kubernetes/client/api_client.py#L278

@mward29
Copy link

mward29 commented Aug 9, 2018

minikube version: v0.28.2

Any chance I'm doing something wrong?

metrics_url = '/apis/metrics.k8s.io/v1beta1/namespaces/kube-system/pods/kube-controller-manager-minikube'
api_client.call_api(metrics_url, 'GET', _preload_content=True)
returns None

(None, 200, HTTPHeaderDict({'Content-Length': '434', 'Content-Type': 'application/json', 'Date': 'Fri, 10 Aug 2018 14:42:47 GMT'}))

when I make the same call via curl, it returns the expected data.
curl --cacert <redacted> --key <redacted> --cert <redacted> https://192.168.99.100:8443/apis/metrics.k8s.io/v1beta1/namespaces/kube-system/pods/kube-controller-manager-minikube

@mward29
Copy link

mward29 commented Aug 10, 2018

FYI,

I found: .request instead of .call_api
api_client.request('GET', metrics_url, headers=None, _preload_content=True)

This Works!

@Shinzu
Copy link

Shinzu commented Aug 10, 2018

@mward29 how did you include config parameters here, like the ones from config.load_incluster_config() ?

@mward29
Copy link

mward29 commented Aug 10, 2018

yes. config.load_kube_config()

@mward29
Copy link

mward29 commented Aug 10, 2018

FYI. I had to add the full url to make it work. Still unable to get .call_api to work.

metrics_url = 'https://192.168.99.100:8443/apis/metrics.k8s.io/v1beta1/namespaces/kube-system/pods/kube-controller-manager-minikube'

@Shinzu
Copy link

Shinzu commented Aug 10, 2018

@mward29 i think go get .call_api to work you have to define at least response_type , but i did not find any suitable type in https://github.com/kubernetes-client/python/tree/master/kubernetes/client/models

@Shinzu
Copy link

Shinzu commented Aug 10, 2018

with

ret= api_client.call_api('/apis/metrics.k8s.io/v1beta1/namespaces/default/pods', 'GET', auth_settings = ['BearerToken'], response_type='json', _preload_content=False)
print(ret)

i get

(<urllib3.response.HTTPResponse object at 0x7f1166713710>, 200, HTTPHeaderDict({'Content-Length': '446', 'Content-Type': 'application/json', 'Date': 'Fri, 10 Aug 2018 06:39:06 GMT'}))

@Shinzu
Copy link

Shinzu commented Aug 10, 2018

i do it now this way:

ret_metrics = api_client.call_api('/apis/metrics.k8s.io/v1beta1/namespaces/' + namespace.metadata.name + '/pods', 'GET', auth_settings = ['BearerToken'], response_type='json', _preload_content=False) 
response = ret_metrics[0].data.decode('utf-8')

@mward29
Copy link

mward29 commented Aug 19, 2018

Nice Shinzu

@fejta-bot
Copy link

Issues go stale after 90d of inactivity.
Mark the issue as fresh with /remove-lifecycle stale.
Stale issues rot after an additional 30d of inactivity and eventually close.

If this issue is safe to close now please do so with /close.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/lifecycle stale

@k8s-ci-robot k8s-ci-robot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Apr 25, 2019
@fejta-bot
Copy link

Stale issues rot after 30d of inactivity.
Mark the issue as fresh with /remove-lifecycle rotten.
Rotten issues close after an additional 30d of inactivity.

If this issue is safe to close now please do so with /close.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/lifecycle rotten

@k8s-ci-robot k8s-ci-robot added lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. and removed lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. labels May 25, 2019
@fejta-bot
Copy link

Rotten issues close after 30d of inactivity.
Reopen the issue with /reopen.
Mark the issue as fresh with /remove-lifecycle rotten.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/close

@k8s-ci-robot
Copy link
Contributor

@fejta-bot: Closing this issue.

In response to this:

Rotten issues close after 30d of inactivity.
Reopen the issue with /reopen.
Mark the issue as fresh with /remove-lifecycle rotten.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/close

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed.
Projects
None yet
Development

No branches or pull requests

7 participants