📊 Fetch & monitor your server's resource usage through Lua

Overview

📊 gmsv_serverstat

Simple serverside binary module which can expose information about system resource usage to Lua.

Installation

Download the relevant module for your server's operating system and platform/Gmod branch from the releases section.

Drop the module into garrysmod/lua/bin/ in your server's files. If the bin folder doesn't exist, create it.

If you're not sure on what operating system/platform your server is running, run this in your server's console:

lua_run print((system.IsWindows()and"Windows"or system.IsLinux()and"Linux"or"Unsupported").." "..(jit.arch=="x64"and"x86-64"or"x86"))

Usage

To load the module, simply require it:

require("serverstat")

Blocking Functions

Some of these functions may block the main thread whilst acquiring information about the system & process. Make sure to call these functions sparingly.

Some functions will only block when they are called for the first time.

Some functions may also return default values (such as 0) when called for the first time.

-- Gets SRCDS' CPU usage
-- [float] 0..1
serverstat.ProcessCPUUsage()

-- Gets SRCDS' memory usage in MiB
-- [float] MiB
serverstat.ProcessMemoryUsage()

-- Gets the system's total CPU usage
-- [float] 0..1
serverstat.SystemCPUUsage()

-- Gets the system's current memory usage in MiB
-- [float] MiB
serverstat.SystemMemoryUsage()

-- Gets the system's total memory installed in MiB
-- [float] MiB
serverstat.SystemTotalMemory()

-- Gets the system's available memory in MiB
-- [float] MiB
serverstat.SystemAvailableMemory()

-- Gets the system's number of physical CPUs (cores)
-- [integer]
serverstat.PhysicalCPUs()

-- Gets the system's number of logical CPUs
-- Roughly equates to physical cores (CPUs) × threads per core
-- [integer]
serverstat.LogicalCPUs()

-- Fetches all resource usage information about the system and process as a table.
-- The table is keyed by the above function names and their respective return data as the value.
-- [table]
serverstat.All()

-- Fetches all SYSTEM resource usage information about the system and process as a table.
-- The table is keyed by the above function names and their respective return data as the value.
-- [table]
serverstat.AllSystem()

-- Fetches all SRCDS resource usage information about the system and process as a table.
-- The table is keyed by the above function names and their respective return data as the value.
-- [table]
serverstat.AllProcess()

Asynchronous Functions

Each blocking function has an asynchronous equivalent in the serverstat.async table which takes a single function callback argument.

Using the asynchronous functions will acquire the requested information on a separate thread.

The thread goes to sleep when unused and uses no system resources until needed again.

serverstat.async.ProcessCPUUsage(function(data) ... end)
serverstat.async.ProcessMemoryUsage(function(data) ... end)
serverstat.async.SystemCPUUsage(function(data) ... end)
serverstat.async.SystemMemoryUsage(function(data) ... end)
serverstat.async.SystemTotalMemory(function(data) ... end)
serverstat.async.SystemAvailableMemory(function(data) ... end)
serverstat.async.PhysicalCPUs(function(data) ... end)
serverstat.async.LogicalCPUs(function(data) ... end)
serverstat.async.All(function(data) ... end)
serverstat.async.AllSystem(function(data) ... end)
serverstat.async.AllProcess(function(data) ... end)

Realtime Functions

Additionally, serverstat provides a "realtime" data API.

This is to discourage multiple script authors from making what is essentially the same thing; an autorefreshing timer for the data this module provides.

These functions will return data that is updated roughly every 250ms. They are synchronous; updating the data is automatically done in a timer the module creates for you.

This timer will only be created if you start using these functions. It will persist until the server shuts down.

The realtime data API is deliberately missing functions such as LogicalCPUs and PhysicalCPUs, because these are constant values.

-- You don't need to call these functions; they are provided for convenience if you want to control the realtime updater timer yourself.
serverstat.realtime.Start()
serverstat.realtime.Stop()
serverstat.realtime.SetInterval(seconds)

serverstat.realtime.ProcessCPUUsage()
serverstat.realtime.ProcessMemoryUsage()

serverstat.realtime.SystemCPUUsage()
serverstat.realtime.SystemMemoryUsage()
serverstat.realtime.SystemAvailableMemory()

-- These functions return a reference to the table that is shared
-- with other addons. If you are going to be mutating this table,
-- please use the Copy functions below instead.
serverstat.realtime.All() -- { System = serverstat.realtime.AllSystem(), Process = serverstat.realtime.AllProcess() }
serverstat.realtime.AllSystem() -- { CPUUsage = [float], MemoryUsage = [float] MIB, AvailableMemory = [float] MiB }
serverstat.realtime.AllProcess() -- { CPUUsage = [float], MemoryUsage = [float] MIB }

-- These functions return a copy of the table that is shared
-- with other addons. If you aren't going to be mutating the table,
-- you should just use the above functions instead.
serverstat.realtime.AllCopy()
serverstat.realtime.AllSystemCopy()
serverstat.realtime.AllProcessCopy()
You might also like...
A monitor (service) for your monitor (display). Intercepts window behaviour when monitor configuration changes.

Mon-Mon A monitor (service) for your monitor (display). Listens for changes to display configuration (e.g. plugging in an additional screen) and allow

A resource monitor in your browser, in Rust
A resource monitor in your browser, in Rust

axact A resource monitor in your browser, so you can view the state of a VM or some other remote host. Built with Rust & Preact, see the video: https:

Cross-platform GameMaker extension for getting system information and resource usage
Cross-platform GameMaker extension for getting system information and resource usage

GM Sysinfo Cross-platform GameMaker extension for getting system information and resource usage Table of Contents Table of Contents Examples Display m

Blaze is a Rust script that continuously monitors server resource usage and sends real-time summaries and alerts to a Discord channel via Webhook.
Blaze is a Rust script that continuously monitors server resource usage and sends real-time summaries and alerts to a Discord channel via Webhook.

Blaze Blaze is a Rust script designed to run 24/7 on a server, providing a summary of resource usage every 30 minutes (configurable) to a Discord chan

Lua bytecode parser written in Rust using nom, part of metaworm's lua decompiler

luac-parser (中文) lua字节码解析器, 目前支持 lua51, lua53, lua54 这是目前效果最好的lua反编译器 metaworm's luadec 的一部分 可以基于此代码定制你所需的lua字节码解析器,编译成WASM,让metaworm's luadec加载使用,来反编

Memory usage monitor for process trees

gotta-watch-em-all Executes a process with given arguments and monitors, logs when memory usage grows to a new peak. Example: cargo run -- cargo -- bu

Github mirror of codeberg repo. Monitor live bandwidth usage/ network speed on PC. Native version also available for Android, separately.
Github mirror of codeberg repo. Monitor live bandwidth usage/ network speed on PC. Native version also available for Android, separately.

Netspeed Monitor Netspeed is a cross-platform desktop application that shows the live upload speed, download speed and day's usage as an overlay. Feat

dua (- Disk Usage Analyzer) is a tool to conveniently learn about the usage of disk space of a given directory

dua (- Disk Usage Analyzer) is a tool to conveniently learn about the usage of disk space of a given directory. It's parallel by default and will max

Telegram bot to fetch images from Terceira Ponte and Rodosol into your Telegram chat.

rodosol-telegram-bot Add this bot to your contacts list This bot is a quick scraper that gets the pictures from the rodosol "De olho na via" feature a

Fetch all your fetches, but in rust
Fetch all your fetches, but in rust

fetchfetch, but in rust Fetch all of your fetches. written in go rust. Installation You can either download the latest release or build from source (r

An API for managing your servers

Intecture APIs Intecture is an API for managing your servers. Visit intecture.io. API docs can be found here: intecture.io/api/intecture_api/. Intectu

Managed game servers, matchmaking, and DDoS mitigation that lets you focus on building your game
Managed game servers, matchmaking, and DDoS mitigation that lets you focus on building your game

Managed game servers, matchmaking, and DDoS mitigation that lets you focus on building your game. Home - Docs - Twitter - Discord 👾 Features Everythi

A CLI app to set and organize your favorite DNS servers.

rdns A CLI app to set and organize your favorite DNS servers. Introduction rdns is a CLI utility that can set your system DNS, either directly or by m

FastSSH is a TUI that allows you to quickly connect to your services by navigating through your SSH config.
FastSSH is a TUI that allows you to quickly connect to your services by navigating through your SSH config.

Connect quickly to your services 🚀 FastSSH is a TUI that allows you to quickly connect to your services by navigating through your SSH config. Instal

A small program to feed the audio from your QRP-Labs QDX digital transceiver through to your computer's speakers

A small program to feed the audio from your QRP-Labs QDX digital transceiver through to your computer's speakers. Also gives you a small user interface in which you can see a signal-strength meter, control the output volume coming from your speakers, and to tune the QDX to a particular frequency (receive SSB and other signals!).

Alternative to *fetch, uwuifies all stats.
Alternative to *fetch, uwuifies all stats.

owofetch-rs Alternative to *fetch, uwuifies all stats. Installation: Arch: AUR Other Linux distros: Either compile the source with cargo build --relea

Fetch original quality URLs for images posted to a Twitter account

twitter-images Fetches the last tweets of a given account, then prints original quality URLs for all image tweets. Useful for archiving image content

🌳 A lightning-fast system fetch tool made with Rust.
🌳 A lightning-fast system fetch tool made with Rust.

🌳 treefetch A lightning-fast minimalist system fetch tool made in Rust. Even faster than neofetch and pfetch. Made to practice my new Rust skills 🦀

Create, share, fetch and model Atomic Data! This project consists of a graph database + server, a CLI and a rust library.

Create, share, fetch and model Atomic Data! This repo consists of three components: A library, a server and a CLI. atomic-server Status: Beta. Breakin

Comments
  •  Couldn't load module library! (/lib/i386-linux-gnu/libc.so.6: version `GLIBC_2.28' not found

    Couldn't load module library! (/lib/i386-linux-gnu/libc.so.6: version `GLIBC_2.28' not found

    lua_run require("serverstat")

    require("serverstat")...

    [ERROR] lua_run:1: Couldn't load module library! (/lib/i386-linux-gnu/libc.so.6: version `GLIBC_2.28' not found (required by /root/gmod/garrysmod/lua/bin/gmsv_serverstat_linux.dll))

    1. require - [C]:-1
    2. unknown - lua_run:1

    Ubuntu 18.04

    print((system.IsWindows()and"Windows"or system.IsLinux()and"Linux"or"Unsupported").." "..(jit.arch=="x64"and"x86-64"or"x86"))... Linux x86

    opened by LastPlayerTR 1
  • `ProcessCPUUsage` field values doesn't mean anything

    `ProcessCPUUsage` field values doesn't mean anything

    Recently, I switched from the old version of this module to the new one and I noticed that the ProcessCPUUsage field was giving completely ununderstandable values and didn't seem to make sense compared to the others.

    For example, here is the result I can get (it happens to me all the time and is not exceptional):

    > PrintTable(serverstat.All())...
    LogicalCPUs = 8
    PhysicalCPUs = 8
    ProcessCPUUsage = 40300 -- ???
    ProcessMemoryUsage = 572.24609375
    SystemAvailableMemory = 19969.983398438
    SystemCPUUsage = 41.920177459717
    SystemMemoryUsage = 49319.202148438
    SystemTotalMemory = 70362.319335938
    

    The same thing happens with the asynchronous function (but sometimes it returns 0 without any reason).

    > serverstat.async.All(function(data) PrintTable(data) end)...
    LogicalCPUs = 8
    PhysicalCPUs = 8
    ProcessCPUUsage = 0 -- ???
    ProcessMemoryUsage = 573.2109375
    SystemAvailableMemory = 20000.5234375
    SystemCPUUsage = 100 -- Why not
    SystemMemoryUsage = 49288.662109375
    SystemTotalMemory = 70362.319335938
    

    For information, my server is on a dedicated machine hosted by a game provider (so I don't have control of the machine to check the stats). AFAIK, the server is running under Debian 10 64-bit.

    ] version
    Protocol version 24
    Exe version 2021.06.09 (garrysmod)
    Exe build: 14:56:57 Jul 12 2021 (8283) (4000)
    GMod version 2021.07.12, branch: unknown
    Linux 32bit Dedicated Server
    

    And here is the script I use to get the information from the module.

    -- From : https://github.com/WilliamVenner/gmsv_serverstat/
    if not file.Exists("bin/gmsv_serverstat_*.dll", "LUA") then return end
    
    require("serverstat")
    
    concommand.Add("server-stats", function(ply)
    
        local data = serverstat.All()
        local phrase = "CPU Usage : %s (%s/%s)\nMemory Usage : %s (%s)"
    
        phrase = string.format(phrase,
    
            math.Round(data.ProcessCPUUsage, 2) .. "%",
    
            data.LogicalCPUs, data.PhysicalCPUs,
    
            string.NiceSize(data.ProcessMemoryUsage * 10 ^ 6),
    
            string.NiceSize(data.SystemTotalMemory * 10 ^ 6)
    
        )
    
        Raven.Server.SendChatMessage(ply, color_red, phrase)
    
    end)
    
    opened by FlorianLeChat 13
Releases(v0.2.5)
Owner
William
aka Billy
William
A TUI system monitor written in Rust

NO LONGER MAINTAINED. For a similar program, check out https://github.com/ClementTsang/bottom. ytop Another TUI based system monitor, this time in Rus

Caleb Bassi 2.1k Jan 3, 2023
A customisable client for Discord rich presence using simple Lua configuration.

Installation | Usage | Configuration | Example Disco Disco is a customisable client for Discord rich presence using simple Lua configuration. Installa

KaitlynEthylia 5 Aug 7, 2023
Transform Linux Audit logs for SIEM usage

Linux Audit – Usable, Robust, Easy Logging TLDR: Instead of audit events that look like this… type=EXECVE msg=audit(1626611363.720:348501): argc=3 a0=

null 465 Jan 1, 2023
A faster way to navigate your filesystem

zoxide A faster way to navigate your filesystem Table of contents Introduction Examples Getting started Step 1: Install zoxide Step 2: Install fzf (op

Ajeet D'Souza 8.7k Jan 8, 2023
:stars: Manage your shell commands.

Pueue Pueue is a command-line task management tool for sequential and parallel execution of long-running tasks. Simply put, it's a tool that processes

Arne Beer 3.3k Jan 8, 2023
gt your desired path with minimal keystrokes

goto (gt) gt is a simple and user-friendly way to jump to your indexed directories. gt is short for "goto", which is basically what you want to do wit

Sylvester Chin 25 Nov 7, 2022
Count your code, quickly.

Tokei (時計) Tokei is a program that displays statistics about your code. Tokei will show the number of files, total lines within those files and code,

null 7.5k Jan 9, 2023
CLI utility to move (or rename) your files to a new location and redirect all of its symbolic links, to the new path

Move Links CLI utility to move (or rename) your files to a new location and redirect all of its symbolic links, to the new path (or name). Usage execu

Ben Mefteh 18 May 22, 2022
Your project’s nix-env [maintainer=@Profpatsch]

lorri https://github.com/nix-community/lorri lorri is a nix-shell replacement for project development. lorri is based around fast direnv integration f

Nix community projects 442 Jan 1, 2023
subd - a place to reward your subscribers from any platform

subd subd's goal is to create a link between the various ways viewers support you as a live content creator, and the interactions that can be triggere

TJ DeVries 37 Jul 6, 2023