Coder Social home page Coder Social logo

Comments (1)

DarkCat09 avatar DarkCat09 commented on June 27, 2024

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

from python-aternos.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.