# DDNet Server Statistics with ServerStatus, RRDtool and Nim

DevFeed: [DDNet Server Statistics with ServerStatus, RRDtool and Nim](<https://devfeed.tech/articles/ddnet-server-statistics-with-serverstatus-rrdtool-and-nim-30834.md>)

Original publisher: [Read original article](<https://hookrace.net/blog/server-statistics/>)

Published: 2016-05-13T22:00:00Z

Content type: tutorial

Language: en

Sources: [Dennis Felsing](<https://devfeed.tech/sources/dennis-felsing.md>)

Topics: [Server](<https://devfeed.tech/topics/server.md>), [Nim](<https://devfeed.tech/topics/nim.md>), [Statistics](<https://devfeed.tech/topics/statistics.md>), [Python](<https://devfeed.tech/topics/python.md>), [c/c++](<https://devfeed.tech/topics/c-c-plus-plus.md>), [JSON](<https://devfeed.tech/topics/json.md>), [Programming](<https://devfeed.tech/topics/programming.md>), [Linux](<https://devfeed.tech/topics/linux.md>), [JavaScript](<https://devfeed.tech/topics/javascript.md>)

Tags: [http](<https://devfeed.tech/tags/http.md>), [javascript](<https://devfeed.tech/tags/javascript.md>), [json](<https://devfeed.tech/tags/json.md>), [linux](<https://devfeed.tech/tags/linux.md>), [nim](<https://devfeed.tech/tags/nim.md>), [programming](<https://devfeed.tech/tags/programming.md>), [python](<https://devfeed.tech/tags/python.md>), [servers](<https://devfeed.tech/tags/servers.md>), [statistics](<https://devfeed.tech/tags/statistics.md>)

## AI overview

This article explains how DDNet monitors its official game servers using ServerStatus, RRDtool, and Nim while keeping resource usage low. It describes collecting server metrics with Python clients, transmitting them over TCP to a C/C++ server, aggregating them into JSON, displaying them through a JavaScript frontend, and recording CPU, network, and memory data in RRDtool.

## Source excerpt

About a month ago I set up statistics for the official DDNet servers. My motivations for this are: Monitor the servers more easily Get notified about server problems Have nice graphs to look at The choices for the software used are mainly made to keep resource usage low, a general principle used for DDNet since we run on cheap VPSes all around the world and are limited in CPU and memory resources. In the rest of this post we will explore the 3 major tools used, their purpose in our solution as well as their performance impact: ServerStatus: Gather live server statistics RRDtool: Record and graph data Nim: Favorite programming language for performance and readability Gathering live server statistics with ServerStatus We've been running BotoX's ServerStatus to get live server statistics for some time now. It works quite well to quickly notice major server problems like a high load or incoming (D)DoS attacks, provided that you keep an eye out for it. We use ServerStatus by running its simple Python client on each server to gather interesting information. The client transmits that data by TCP to the C/C++ server, which aggregates it into a JSON file. This JSON file is then fetched and displayed every two seconds by the JavaScript frontend of our Status page. On a regular Saturday morning the end result looks like this: On a quick glance you notice that the DDNet.tw server has high CPU usage (which is totally normal since it runs some hefty cron jobs every 20 minutes) and DDNet RUS is receiving a small DoS attack with just 1.6 MB/s (unfortunately also totally normal). Apart from that everything looks fine. ServerStatus footprint, calculated from Linux /proc statistics as follows (in Nim): import os, strutils, posix, strfmt # CPU and memory usage of process, based on PROC(5) and # http://stackoverflow.com/a/16736599 let pid = paramStr(1) # Clock ticks per second frequency = sysconf(SC_CLK_TCK) # Size of memory page in bytes pagesize = sysconf(SC_PAGESIZE) uptime = readFil