Crates.io | x-server-stats |
lib.rs | x-server-stats |
version | 0.1.2 |
source | src |
created_at | 2022-09-28 21:25:47.341321 |
updated_at | 2022-10-15 14:31:36.154744 |
description | A simple web server to display server stats over HTTP and Websockets |
homepage | https://github.com/xamfy/x-server-stats |
repository | |
max_upload_size | |
id | 676078 |
size | 1,714,704 |
A simple web server(and library) to display server stats over HTTP and Websockets/SSE or stream it to other systems. x-server(in x-server-stats) is not to be confused with X Window System.
$ cargo install x-server-stats
You can also install x-server-stats via npm, the npm install command will install rust and the x-server-stats binary in your path.
This is useful if you want to get started quickly via npm. But we recommend to go with the cargo install command.
The npm package is called rust-x-server-stats
$ npm install -g rust-x-server-stats
You can install Rust by following the instructions from the rust lang website. The command to install rust using bash looks like below on the website, it's always advisable to follow the instructions on the official website. We don't recommend using the command below as it may not be the latest version and other repos can have malicious bash script as well.
# Just for reference, please always head over to the official website for the instructions.
$ curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
You can install PostgreSQL 14 by following the instructions from the PostgreSQL website. We use PostgreSQL 14 for the database, you can use any other databases as well, but we don't provide any support for other databases as of now(please raise an issue if you have a usecase for some other database).
# Just for reference, please always head over to the official homebrew/postgres website for the instructions for your OS.
$ brew install postgresql@14
You need to export below environment variables to run the server.
The environment variables prefixed with PG
are for PotsgreSQL database. Currently, only PostgreSQL is supported for storing stats.
export SERVER_ADDR=localhost:8082
export PG__USER=PG_USERNAME
export PG__PASSWORD=PG_PASSWORD
export PG__HOST=PG_HOST_URL
export PG__PORT=5432
export PG__DBNAME=PG_DB_NAME
export PG__POOL__MAX_SIZE=20
export BASE_ADDR=http://localhost:8082
Before running the application, you need to build it. You can do this by running the following command:
$ cargo build --release
Run the binary with the following command:
$ ./target/release/x-server-stats
You can run the application directly by running the following command:
$ cargo run --release
First copy the Dockerfile.example
file to Dockerfile
and fill in the environment variables. Then run the below commands to build and run the Docker image.
$ docker build -t x-server-stats .
$ docker run -p 8082:8082 x-server-stats
TODO - Need to work on this. The web page will be built using just HTML, CSS, JS with the whole page under 14KB gzipped and minified(due to initcwnd of TCP on linux servers).
x-server-stats uses actix-governor to throttle incoming requests based on IP address.
The config is present at src/main.rs
and can be changed accordingly.
Throttling is important if you don't want to overwhelm the server with too many requests by internal systems.
We plan to make this configurable in the future, so you don't have to build from source to change the config.