DEV Community

Kal
Kal

Posted on

Hosting Minecraft Server + Grafana

As of yesterday, Minecraft 1.20 has been released, which has rekindled the builder spirit within me and my friend. So, why not host a Minecraft server for us? Without further ado, I have listed three possible options for a Minecraft server.

Requirements

  • Low cost
  • At least a single decent core CPU
  • 6GB or more (expecting up to 5 players online at most, ~4GB + 2 GB as buffer/for other resources)

Options

  1. Minecraft realm
    1. πŸ‘ Easy
    2. πŸ‘Ž Very limited configuration
    3. πŸ‘Ž Not the cheapest option
  2. Hosting on my desktop
    1. πŸ‘ Free
    2. πŸ‘Ž Need my desktop to be online 24/7 (as my players will be spanning over several time zones)
  3. Hosting on a VPS
    1. πŸ‘ Sounds fun
    2. πŸ‘ Cheaper than realm (in theory)
    3. πŸ‘Ž Takes some time to set up

In the end, I went with option 3 and looked for a good VPS provider. I ended up choosing Oracle, mostly due to its generous free tier (up to 24GB RAM on an ARM server 🀯), which is going to be crucial for a Minecraft server.

Oracle Hong Kong SAR, PRC | Cloud Applications and Cloud Platform

Creating a VPS instance on Oracle Cloud

The UI is quite straightforward, feeling like a mix of Azure and AWS. Nothing fancy, but I like how it estimates the monthly cost, giving me an idea of how much it's going to cost me every week. In the end, I picked a medium-sized free instance (2 CPUs + 12GB RAM), which is way better than what I expected, with only 300 yen monthly cost!!!

Setting up the server

Dependencies

To create a basic Minecraft server, we just need the following:

- Java
- Screen / tmux / zellij
- vi / vim / nvim
Enter fullscreen mode Exit fullscreen mode

Setting up Minecraft server

I chose the fabric server this time because:

  • It is closer to vanilla Minecraft
  • There are many mods for server enhancement or even new content for future gameplay
  • Create a folder at $HOME
mkdir ~/mc-server
Enter fullscreen mode Exit fullscreen mode
  1. Download the server JAR
curl -OJ <https://meta.fabricmc.net/v2/versions/loader/1.20.1/0.14.21/0.11.2/server/jar>

Enter fullscreen mode Exit fullscreen mode
  1. Create a start.sh
echo 'java -Xmx10G -jar fabric-server-mc.1.20.1-loader.0.14.21-launcher.0.11.2.jar nogui' > start.sh
Enter fullscreen mode Exit fullscreen mode
  1. Give permission to sh and then start
chmod +x start.sh
./start.sh
Enter fullscreen mode Exit fullscreen mode
  1. After accepting the EULA, the server should be started! πŸŽ‰

Opening ports for public traffic

At this point, although the server is now started, no one can access it yet because I haven't opened the port for public traffic. We need to tune the network setting at Oracle dashboard and Ubuntu firewall.

  1. Adding ingress rules at Oracle dashboard

  1. Opening ports at ufw
sudo ufw allow 25565
sudo ufw enable
Enter fullscreen mode Exit fullscreen mode

Server is up!

Now you should see your server online! Yay

Setting up Grafana

What if you want to know your server more? Or show some cool graphs to your friends? Then Grafana is here for you. Grafana also provides a generous free tier for us, so it costs nothing to make some shiny charts for our server ;)

πŸ’‘ Grafana and Prometheus are integral tools for metric visualization and monitoring. Prometheus, an open-source monitoring system with a robust query language, collects time-series data identified by metric name and key/value pairs. It efficiently scrapes and stores metrics from services, providing powerful queries and alerts. Grafana, an open-source visualization tool, integrates with Prometheus to present these complex metrics in easy-to-understand, customizable dashboards. Together, they provide real-time, data-driven insights into system performance, enabling informed decision-making for improvements, troubleshooting, and ensuring system reliability. Their tandem operation facilitates comprehensive monitoring and data exploration in a user-friendly manner.
- GPT-4 β€œGrafana & Prometheus in 100 words”

Connecting server to Grafana cloud

After opening a new Grafana cloud account, you will get a friendly guide guiding you to various features that Grafana can do. Despite Grafana being a very powerful tool, we are going to use it for two tasks:

  1. Showing general server metrics
  2. Showing Minecraft metrics

Scraping server condition via node_scraper

Following the guide at https://[your_domain].grafana.net/connections/add-new-connection/linux-node, you are essentially setting up a node_scraper for your server. It will collect various system data and then upload it to Grafana cloud for visualization.

If you followed the steps correctly, you will have a nice-looking dashboard like this:

!https://s3-us-west-2.amazonaws.com/secure.notion-static.com/d3b5934b-c2ba-4f79-92ba-23a43dbfa73d/Untitled.png

Minecraft Metrics on Grafana

Now we take one step further to show Minecraft-specific data on Grafana as well. We are going to use a fabric mod, Unified Metrics, to export all the sweets data to Grafana.

  1. Install Unified Metrics at your server's mods folder
wget <https://github.com/Cubxity/UnifiedMetrics/releases/download/v0.3.8/unifiedmetrics-platform-fabric-0.3.8.jar>
Enter fullscreen mode Exit fullscreen mode
  1. Configure /etc/grafana-agent.yml, insert the following to the correct place
metrics:
  configs:
  - name: integrations
    remote_write:
    - basic_auth:
        password: <PW>
        username: <USERNAME>
      url: <URL>
    scrape_configs:
      # Add here any snippet that belongs to the `metrics.configs.scrape_configs` section.
      # For a correct indentation, paste snippets copied from Grafana Cloud at the beginning of the line.
      - job_name: minecraft_scrape
        static_configs:
        # Put your server's IP here
        - targets: [ "localhost:9100" ]
        # Feel free to add any labels here
          labels:
            node: <>
Enter fullscreen mode Exit fullscreen mode
  1. Reload grafana-agent
sudo systemctl restart grafana-agent.service
Enter fullscreen mode Exit fullscreen mode
  1. Import dashboard

    We need a dashboard to display our collected data. The provided dashboard by Unified Metrics' author is a good starting point: https://grafana.com/grafana/dashboards/14756-unifiedmetrics-0-3-x-prometheus/

If everything is set up correctly, you will see data flowing in, and charts start updating in a few minutes. Now enjoy Minecraft and all the fancy visualizations!

Top comments (0)