Skip to content
This repository has been archived by the owner on Feb 15, 2024. It is now read-only.

Can't show the RAM usage #38

Closed
SHUBHAM1234A opened this issue Jul 16, 2022 · 1 comment
Closed

Can't show the RAM usage #38

SHUBHAM1234A opened this issue Jul 16, 2022 · 1 comment
Labels
documentation Improvements or additions to documentation websocket Questions related to ws

Comments

@SHUBHAM1234A
Copy link

When I use myserver._info, it sends out a big dictionary which has ram when it's offline and ram and maxram when online.
maxram is kind of self-explanatory but ram also works like maxram and does not give the actual RAM usage.

And now, how I use python-aternos. I use this in my node.js project by calling the python file through the terminal with a feature in node.js and I am an absolute newbie in python.

If anyone can tell me how to get RAM usage that'll be very appreciated or if the developer itself adds something to get RAM usage, that'll be very nice of them

@DarkCat09
Copy link
Owner

DarkCat09 commented Jul 24, 2022

server.ram (and server._info['ram']) returns data from the _info dictionary which is requested just one time - when AternosServer object is created.
You can update it manually calling server.fetch(), but if you send this request in a loop for auto-updates, Aternos might suspend your account, so you should use websocket streams.

When your Minecraft server is online, there is a used RAM indicator on the server panel page (aternos.org/panel) that is updated in real-time by a script which receives data from a websocket server at aternos.org/hermes. But we have to subscript to the "used RAM (heap)" stream, more about streams.

Here's how to do it in python-aternos:

import asyncio
from python_aternos import Client, atwss

at = Client.from_credentials('username', 'password')
srv = at.list_servers()[0]
socket = srv.wss()  # AternosWss object

# handler for used RAM stream
@socket.wssreceiver(atwss.Streams.ram)
async def ram(used):
  # used is int
  print('Current RAM usage:', used, 'bytes')

# starting minecraft server
srv.start()

# connecting to websocket
# this function also sends streams subscriptions
asyncio.run(socket.connect())

That's all. Run the script and you'll get output like: Current RAM usage: 879372712 bytes

@DarkCat09 DarkCat09 added documentation Improvements or additions to documentation websocket Questions related to ws labels Jul 24, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
documentation Improvements or additions to documentation websocket Questions related to ws
Projects
None yet
Development

No branches or pull requests

2 participants