2

I'm migrating my py 2.7 existing repo to py 3.7 currently working on Google App Engine.

I found that a runtime library (Runtime Utilities API) which is extensively used in the project.

from google.appengine.api.runtime import runtime
import logging

logging.info(runtime.memory_usage())

This will output memory usage statistics, where the numbers are expressed in MB. For example:

current: 464.0859375
average1m: 464
average10m: 379.575

I'm trying to find its alternative library compatible with python 3.7 but don't found any from GAE. Can somebody please help with this. Is there any replacement from the Google side which I'm not aware of?

Jay Patel
  • 2,341
  • 2
  • 22
  • 43

2 Answers2

2

Unfortunately, the google.appengine.api.runtime.runtime module is deprecated since the version 1.8.1.

I also couldn't find any similar or equivalent official App Engine API for Python3.

As an alternative, you can try to implement these feature merely within your code. For instance, look at the answers of this question, which is relate on how to Get RAM & CPU stats with Python. Some of them include the use of the psutil library.

You can also consider to use a StackDriver Agent, that can transmit data for the metric types listed on this page to Stackdriver; such as CPU (load, usage, etc), Disk (bytes used, io_time, etc) and other metrics.

Kevin Quinzel
  • 1,430
  • 1
  • 13
  • 23
0

The following gets exactly the same values of memory usage that the dashboard shows:

def current():
    vm = psutil.virtual_memory()
    return (vm.active + vm.inactive + vm.buffers) / 1024 ** 2

If one wants to minimize the cost of transition, then the following can be put in a new module, and imported instead of the Google original interface:

import psutil
class MemoryUsage:
    def __init__(self):
        pass

    @staticmethod
    def current():
        vm = psutil.virtual_memory()
        return (vm.active + vm.inactive + vm.buffers) / 1024 ** 2

def memory_usage():
    return MemoryUsage()
Michael Veksler
  • 8,217
  • 1
  • 20
  • 33