{"id":15762406,"url":"https://github.com/williamvenner/gmsv_serverstat","last_synced_at":"2025-05-07T22:46:30.903Z","repository":{"id":41085791,"uuid":"386094505","full_name":"WilliamVenner/gmsv_serverstat","owner":"WilliamVenner","description":"📊 Fetch \u0026 monitor your server's resource usage through Lua","archived":false,"fork":false,"pushed_at":"2021-12-08T20:05:49.000Z","size":41,"stargazers_count":41,"open_issues_count":2,"forks_count":0,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-05-07T22:46:23.784Z","etag":null,"topics":["garrys-mod","garrysmod","gmod","gmod-module","gmod-modules","gmsv","monitor","monitoring","server","serverstat","serverstatus","srcds"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/WilliamVenner.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-07-14T22:44:14.000Z","updated_at":"2024-12-30T00:12:43.000Z","dependencies_parsed_at":"2022-09-06T21:40:48.875Z","dependency_job_id":null,"html_url":"https://github.com/WilliamVenner/gmsv_serverstat","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WilliamVenner%2Fgmsv_serverstat","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WilliamVenner%2Fgmsv_serverstat/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WilliamVenner%2Fgmsv_serverstat/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WilliamVenner%2Fgmsv_serverstat/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/WilliamVenner","download_url":"https://codeload.github.com/WilliamVenner/gmsv_serverstat/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252967982,"owners_count":21833247,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["garrys-mod","garrysmod","gmod","gmod-module","gmod-modules","gmsv","monitor","monitoring","server","serverstat","serverstatus","srcds"],"created_at":"2024-10-04T11:09:01.534Z","updated_at":"2025-05-07T22:46:30.879Z","avatar_url":"https://github.com/WilliamVenner.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 📊 gmsv_serverstat\r\n\r\nSimple serverside binary module which can expose information about system resource usage to Lua.\r\n\r\n# Installation\r\n\r\nDownload the relevant module for your server's operating system and platform/Gmod branch from the [releases section](https://github.com/WilliamVenner/gmsv_serverstat/releases).\r\n\r\nDrop the module into `garrysmod/lua/bin/` in your server's files. If the `bin` folder doesn't exist, create it.\r\n\r\nIf you're not sure on what operating system/platform your server is running, run this in your server's console:\r\n\r\n```lua\r\nlua_run print((system.IsWindows()and\"Windows\"or system.IsLinux()and\"Linux\"or\"Unsupported\")..\" \"..(jit.arch==\"x64\"and\"x86-64\"or\"x86\"))\r\n```\r\n\r\n# Usage\r\n\r\nTo load the module, simply [`require`](https://wiki.facepunch.com/gmod/Global.require) it:\r\n\r\n```lua\r\nrequire(\"serverstat\")\r\n```\r\n\r\n## Blocking Functions\r\n\r\nSome of these functions may block the main thread whilst acquiring information about the system \u0026 process. Make sure to call these functions sparingly.\r\n\r\nSome functions will only block when they are called for the first time.\r\n\r\nSome functions may also return default values (such as 0) when called for the first time.\r\n\r\n```lua\r\n-- Gets SRCDS' CPU usage\r\n-- [float] 0..1\r\nserverstat.ProcessCPUUsage()\r\n\r\n-- Gets SRCDS' memory usage in MiB\r\n-- [float] MiB\r\nserverstat.ProcessMemoryUsage()\r\n\r\n-- Gets the system's total CPU usage\r\n-- [float] 0..1\r\nserverstat.SystemCPUUsage()\r\n\r\n-- Gets the system's current memory usage in MiB\r\n-- [float] MiB\r\nserverstat.SystemMemoryUsage()\r\n\r\n-- Gets the system's total memory installed in MiB\r\n-- [float] MiB\r\nserverstat.SystemTotalMemory()\r\n\r\n-- Gets the system's available memory in MiB\r\n-- [float] MiB\r\nserverstat.SystemAvailableMemory()\r\n\r\n-- Gets the system's number of physical CPUs (cores)\r\n-- [integer]\r\nserverstat.PhysicalCPUs()\r\n\r\n-- Gets the system's number of logical CPUs\r\n-- Roughly equates to physical cores (CPUs) × threads per core\r\n-- [integer]\r\nserverstat.LogicalCPUs()\r\n\r\n-- Fetches all resource usage information about the system and process as a table.\r\n-- The table is keyed by the above function names and their respective return data as the value.\r\n-- [table]\r\nserverstat.All()\r\n\r\n-- Fetches all SYSTEM resource usage information about the system and process as a table.\r\n-- The table is keyed by the above function names and their respective return data as the value.\r\n-- [table]\r\nserverstat.AllSystem()\r\n\r\n-- Fetches all SRCDS resource usage information about the system and process as a table.\r\n-- The table is keyed by the above function names and their respective return data as the value.\r\n-- [table]\r\nserverstat.AllProcess()\r\n```\r\n\r\n## Asynchronous Functions\r\n\r\nEach blocking function has an asynchronous equivalent in the `serverstat.async` table which takes a single `function` callback argument.\r\n\r\nUsing the asynchronous functions will acquire the requested information on a separate thread.\r\n\r\nThe thread goes to sleep when unused and uses no system resources until needed again.\r\n\r\n```lua\r\nserverstat.async.ProcessCPUUsage(function(data) ... end)\r\nserverstat.async.ProcessMemoryUsage(function(data) ... end)\r\nserverstat.async.SystemCPUUsage(function(data) ... end)\r\nserverstat.async.SystemMemoryUsage(function(data) ... end)\r\nserverstat.async.SystemTotalMemory(function(data) ... end)\r\nserverstat.async.SystemAvailableMemory(function(data) ... end)\r\nserverstat.async.PhysicalCPUs(function(data) ... end)\r\nserverstat.async.LogicalCPUs(function(data) ... end)\r\nserverstat.async.All(function(data) ... end)\r\nserverstat.async.AllSystem(function(data) ... end)\r\nserverstat.async.AllProcess(function(data) ... end)\r\n```\r\n\r\n## Realtime Functions\r\n\r\nAdditionally, serverstat provides a \"realtime\" data API.\r\n\r\nThis is to discourage multiple script authors from making what is essentially the same thing; an autorefreshing timer for the data this module provides.\r\n\r\nThese 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.\r\n\r\nThis timer will only be created if you start using these functions. It will persist until the server shuts down.\r\n\r\n**The realtime data API is deliberately missing functions such as `LogicalCPUs` and `PhysicalCPUs`, because these are constant values.**\r\n\r\n```lua\r\n-- You don't need to call these functions; they are provided for convenience if you want to control the realtime updater timer yourself.\r\nserverstat.realtime.Start()\r\nserverstat.realtime.Stop()\r\nserverstat.realtime.SetInterval(seconds)\r\n\r\nserverstat.realtime.ProcessCPUUsage()\r\nserverstat.realtime.ProcessMemoryUsage()\r\n\r\nserverstat.realtime.SystemCPUUsage()\r\nserverstat.realtime.SystemMemoryUsage()\r\nserverstat.realtime.SystemAvailableMemory()\r\n\r\n-- These functions return a reference to the table that is shared\r\n-- with other addons. If you are going to be mutating this table,\r\n-- please use the Copy functions below instead.\r\nserverstat.realtime.All() -- { System = serverstat.realtime.AllSystem(), Process = serverstat.realtime.AllProcess() }\r\nserverstat.realtime.AllSystem() -- { CPUUsage = [float], MemoryUsage = [float] MIB, AvailableMemory = [float] MiB }\r\nserverstat.realtime.AllProcess() -- { CPUUsage = [float], MemoryUsage = [float] MIB }\r\n\r\n-- These functions return a copy of the table that is shared\r\n-- with other addons. If you aren't going to be mutating the table,\r\n-- you should just use the above functions instead.\r\nserverstat.realtime.AllCopy()\r\nserverstat.realtime.AllSystemCopy()\r\nserverstat.realtime.AllProcessCopy()\r\n```\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwilliamvenner%2Fgmsv_serverstat","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwilliamvenner%2Fgmsv_serverstat","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwilliamvenner%2Fgmsv_serverstat/lists"}