Back to Glances

Glances

glances.ipynb

4.5.4987 B
Original Source

Use Glances API in your Python code

Init the Glances API

python
from glances import api
python
gl = api.GlancesAPI()

Get plugins list

python
gl.plugins()

Get CPU stats

python
gl.cpu
python
gl.cpu.get('total')

Get MEMORY stats

python
gl.mem
python
gl.mem.get('available')

Display it in a user friendly way:

python
gl.auto_unit(gl.mem.get('available'))

Get NETWORK stats

python
gl.network

Get the list of networks interfaces:

python
gl.network.keys()

Get stats for a specific network interface:

python
gl.network.get('wlp0s20f3')
python
gl.network.get('wlp0s20f3').get('bytes_recv_rate_per_sec')

Additional information

Example for the LOAD plugin.

python
gl.load

Get the limit configured in the glances.conf:

python
gl.load.fields_description

Get field description and unit:

python
gl.load.get_limits()
python
gl.load.get_views()