Forums

Getting Available CPU

Is there a way of finding out my available CPU time remaining from within python or a bash shell, or would I have to scrape the PA website... or something more modern that I know not the wot of? If I would have to scrape the site is there a best way? Thanks.

We don't have a way to do that. It is a good idea, though. We'll give it some thought.

Thanks. For now I think I can use python time on my tasks to roughly calculate and keep track of how much I am using. Not a biggie for development but if I host my product on PA (which I would like to - Python Anywhere really rocks I wish I had discovered it years ago) then there could be unexpected CPU usage spikes that I would like to respond to in time to prevent or the instant I go over my allowance. BTW - off topic I started reading the PA blog from the beginning. Really inspiring stuff. Thanks.

Glad you like the blog! We now have a ticket on our to-do list "API: endpoint to get cpu usage details" -- I've made a note of this forum thread there so that we can post back here if and when we add it.

Any update on this? I have been using a scraper with selenium on the dashboard page - which basically generates JSON data about CPU available, that runs as an always-on task.

Here is an example of what it generates

{"seconds_per_day": 5000, "seconds_used": 7, "seconds_remaining": 4993, "hours_until_reset": 23, "time_now": 1567688182}

It does the job although it needs some attention sometimes - Sentry lets me know if it fails or I get a tarpit notification.

This is too critical to leave to a kludge like this though. There would be no notification if the dashboard page changed in a way that broke the scraper, never mind the failure points associated with running selenium headless, and so-on.

Please can "API: endpoint to get cpu usage details" be expedited?

Thanks.

+1

Ok. I have made a note of your upvotes.

Ok. I'll be more specific.

Any timeframe on this?

probably no

@nverse Soon. We will let you know.

Thanks :)

Here it is:

/api/v0/user/{username}/cpu/

GET Returns information about cpu usage in json format:

{
    "daily_cpu_limit_seconds": <int>,
    "next_reset_time": <isoformat>,
    "daily_cpu_total_usage_seconds": <float>
}

see the new blog post.

Thank you. Tested. Works great! :)

Excellent, thanks for confirming!