Timmy's picture

Is there an API or way to expose an API to access the server information visible in the Dashboard page of the Webmin?

I'm writing a webapp to show health of my servers on network and would like to tap into that data already being collected.

Forum: 
Tags: 
Jeremy Davis's picture

Nope there's not - at least not that I'm aware of. Webmin just collects those metrics from the OS directly and graphs them, it doesn't expose the info anywhere (at least not that I'm aware of).

There are a myriad of monitoring tools around though that you could explore. AFAIK SNMP provides some minimal resource usage stats. It's primarily used for basic inventory and network monitoring, (e.g. via our Observium appliance) but I think it also provides some basic system monitoring metrics.

Depending on your requirements, another option would be to script something yourself. (assuming a bit of basic Linux CLI/bash experience) it should be fairly easy to create a service that could collect a few stats regularly! Could you elaborate on exactly what you're trying to do? Perhaps I have some more ideas?

Timmy's picture

I wanted to have a webpage I could visit and see all the running VMs quick data, rather than having to log into each one of them or their proxmox hypervisor (whose data like RAM usage isn't always the most accurate).

At first, it'd be a couple simple stats from each VM-

  • Total disk size, amount free (by disk)
  • General CPU load and Memory usage

I'm sure I'll think of other things to add later on. Such as adding this module to proxmox itself with an output of its zpool status.

I do have a small bit of CLI/Bash experience.

I've also started looking into hosting a small Flask server on the VM which exposes an API where I can have the webserver above query and use python's tools to query the system for that data.

Jeremy Davis's picture

That sounds like a cool project! :)

IMO, the first thing is to decide how you want to do it. One way would be to create some sort of agent which runs on each server, collects data and pushes it back to your app server. Perhaps run on a schedule, triggered by a cron job? Another option would be a more centralised model, essentially backend code on your app server that gathers the data from the servers itself.

A flask app server sounds great. If you're going to learn (or perhaps already know?) a bit of python, then there is a useful module called paramiko. It provides the ability to run commands on remote machines via ssh. You could use paramiko to gather the relevant data from each server on a schedule if you wanted to go the agentless route. The upside is that once you have key SSH authentication setup, it should work with any Linux host (assuming that the relevant tools are available). The downside is that it probably wouldn't scale as well as an agent running on each machine.

If you go the agent route, then you could use flask to also provide an API for the agents to report to. The agents wouldn't need to be too complex, just collect the relevant data and push it to the app server on a schedule. Or you could run (data collecting) scripts on each server via a cron job and just collect the info. Or seeing as you are writing a web app, you could write an API to accept the data and push it from each server (e.g. via a cron job again)?! Lot's of options! :)

Regarding actually collecting the stats, they're readily available. There are a myriad of cli tools available for the job. Or if you wanted to get really techy, the raw data is presented as files within the virtual /proc filesystem. That's the original source of all the data; Webmin either uses built-in tools, or probably more likely, reads directly from /proc. I won't go into reading data directly from /proc, but you should find info online if you're interested.

If you want to keep it a bit more simple, then a few tools to consider are:

  • 'free' (included by default) - RAM/swap status
  • 'df' (included by default) - filesystem usage stats
  • 'du' (included by default) - file and directory size info
  • 'vmstat' (included by default) - processes, memory, paging, block IO, traps, disks and cpu stats
  • 'mpstat' (from sysstat - in Debian) - CPU stats (CPUs individually and/or average)
  • 'iostat' (also from sysstat) - IO/disk stats

If you want more info about the commands, try running 'man COMMAND' (where COMMAND is the actual command).

Another way to go would be to use a more complete tool, such as nmon (in Debian). Nmon can write to a csv file - which you could collect (e.g. via paramiko) or push to your app server for processing.

Either way, you'll need to process the data at some point, to collect what you want. It's worth noting that some of the tools I mentioned can output json which makes life easier if you use python (if using bash, jq is the json tool you need). CSV is also easy to read (and another commonly supported output format). Even if it's plain text (e.g. output from a command), using Python (or bash) it should still be quite doable.

As you're likely aware, TurnKey is based on Debian (v16.x 10/Buster; v17.0 11/Bullseye), plus most of the tools you'll likely want will mostly be common Linux tools, so you should find plenty of resources online.

Anyway, sorry I got a bit carried away... Regardless, I'm fairly handy with python and bash, plus know Debian pretty well, and TurnKey intimately :) I have also had some limited experience with flask. Feel free to hit me up if you have specific problems, questions and/or are looking for feedback. I guarantee I'll have all the answers, but happy to put in my 2c.

Add new comment