<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Kal</title>
    <description>The latest articles on DEV Community by Kal (@kalvin807).</description>
    <link>https://dev.to/kalvin807</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F750370%2F4a15d9a8-2bc3-4c82-8389-db08accc716e.png</url>
      <title>DEV Community: Kal</title>
      <link>https://dev.to/kalvin807</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/kalvin807"/>
    <language>en</language>
    <item>
      <title>Hosting Minecraft Server + Grafana</title>
      <dc:creator>Kal</dc:creator>
      <pubDate>Wed, 14 Jun 2023 12:11:47 +0000</pubDate>
      <link>https://dev.to/kalvin807/hosting-minecraft-server-grafana-599d</link>
      <guid>https://dev.to/kalvin807/hosting-minecraft-server-grafana-599d</guid>
      <description>&lt;p&gt;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.&lt;/p&gt;

&lt;h3&gt;
  
  
  Requirements
&lt;/h3&gt;

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

&lt;h3&gt;
  
  
  Options
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Minecraft realm

&lt;ol&gt;
&lt;li&gt;👍 Easy&lt;/li&gt;
&lt;li&gt;👎 Very limited configuration&lt;/li&gt;
&lt;li&gt;👎 Not the cheapest option&lt;/li&gt;
&lt;/ol&gt;


&lt;/li&gt;
&lt;li&gt;Hosting on my desktop

&lt;ol&gt;
&lt;li&gt;👍 Free&lt;/li&gt;
&lt;li&gt;👎 Need my desktop to be online 24/7 (as my players will be spanning over several time zones)&lt;/li&gt;
&lt;/ol&gt;


&lt;/li&gt;
&lt;li&gt;Hosting on a VPS

&lt;ol&gt;
&lt;li&gt;👍 Sounds fun&lt;/li&gt;
&lt;li&gt;👍 Cheaper than realm (in theory)&lt;/li&gt;
&lt;li&gt;👎 Takes some time to set up&lt;/li&gt;
&lt;/ol&gt;


&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.oracle.com/hk/"&gt;Oracle Hong Kong SAR, PRC | Cloud Applications and Cloud Platform&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Creating a VPS instance on Oracle Cloud
&lt;/h1&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--9gktOJjd--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://storage.googleapis.com/zenn-user-upload/6bbb485d3994-20230613.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--9gktOJjd--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://storage.googleapis.com/zenn-user-upload/6bbb485d3994-20230613.png" alt="" width="800" height="379"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;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!!!&lt;/p&gt;

&lt;h1&gt;
  
  
  Setting up the server
&lt;/h1&gt;

&lt;h3&gt;
  
  
  Dependencies
&lt;/h3&gt;

&lt;p&gt;To create a basic Minecraft server, we just need the following:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;- Java
- Screen / tmux / zellij
- vi / vim / nvim
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Setting up Minecraft server
&lt;/h3&gt;

&lt;p&gt;I chose the &lt;a href="https://fabricmc.net/use/server/"&gt;fabric&lt;/a&gt; server this time because:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;It is closer to vanilla Minecraft&lt;/li&gt;
&lt;li&gt;There are many mods for server enhancement or even new content for future gameplay&lt;/li&gt;
&lt;li&gt;Create a folder at &lt;code&gt;$HOME&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;mkdir&lt;/span&gt; ~/mc-server
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Download the server JAR
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;curl &lt;span class="nt"&gt;-OJ&lt;/span&gt; &amp;lt;https://meta.fabricmc.net/v2/versions/loader/1.20.1/0.14.21/0.11.2/server/jar&amp;gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Create a &lt;code&gt;start.sh&lt;/code&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s1"&gt;'java -Xmx10G -jar fabric-server-mc.1.20.1-loader.0.14.21-launcher.0.11.2.jar nogui'&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; start.sh
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Give permission to &lt;code&gt;sh&lt;/code&gt; and then start
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;chmod&lt;/span&gt; +x start.sh
./start.sh
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;After accepting the EULA, the server should be started! 🎉&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Opening ports for public traffic
&lt;/h3&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Adding ingress rules at Oracle dashboard&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--LFHiDpDg--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://storage.googleapis.com/zenn-user-upload/78549a6eede9-20230613.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--LFHiDpDg--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://storage.googleapis.com/zenn-user-upload/78549a6eede9-20230613.png" alt="" width="800" height="34"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Opening ports at &lt;code&gt;ufw&lt;/code&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;ufw allow 25565
&lt;span class="nb"&gt;sudo &lt;/span&gt;ufw &lt;span class="nb"&gt;enable&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Server is up!
&lt;/h3&gt;

&lt;p&gt;Now you should see your server online! Yay&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--fKegIIbM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://storage.googleapis.com/zenn-user-upload/7f61fd0827d2-20230613.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--fKegIIbM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://storage.googleapis.com/zenn-user-upload/7f61fd0827d2-20230613.png" alt="" width="800" height="555"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Setting up Grafana
&lt;/h2&gt;

&lt;p&gt;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 &lt;a href="https://grafana.com/products/cloud/?plcmt=footer"&gt;free tier&lt;/a&gt; for us, so it costs nothing to make some shiny charts for our server ;)&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;💡 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.&lt;br&gt;
&lt;em&gt;- GPT-4 “Grafana &amp;amp; Prometheus in 100 words”&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  Connecting server to Grafana cloud
&lt;/h3&gt;

&lt;p&gt;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:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Showing general server metrics&lt;/li&gt;
&lt;li&gt;Showing Minecraft metrics&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Scraping server condition via &lt;code&gt;node_scraper&lt;/code&gt;
&lt;/h3&gt;

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

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--JzNxz_Ms--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://storage.googleapis.com/zenn-user-upload/1ee33986696e-20230613.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--JzNxz_Ms--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://storage.googleapis.com/zenn-user-upload/1ee33986696e-20230613.png" alt="" width="800" height="350"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you followed the steps correctly, you will have a nice-looking dashboard like this:&lt;/p&gt;

&lt;p&gt;!&lt;a href="https://s3-us-west-2.amazonaws.com/secure.notion-static.com/d3b5934b-c2ba-4f79-92ba-23a43dbfa73d/Untitled.png"&gt;https://s3-us-west-2.amazonaws.com/secure.notion-static.com/d3b5934b-c2ba-4f79-92ba-23a43dbfa73d/Untitled.png&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Minecraft Metrics on Grafana
&lt;/h3&gt;

&lt;p&gt;Now we take one step further to show Minecraft-specific data on Grafana as well. We are going to use a fabric mod, &lt;a href="https://github.com/Cubxity/UnifiedMetrics"&gt;Unified Metrics&lt;/a&gt;, to export all the sweets data to Grafana.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--5Y214rE6--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://storage.googleapis.com/zenn-user-upload/47a39d02d0f3-20230613.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--5Y214rE6--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://storage.googleapis.com/zenn-user-upload/47a39d02d0f3-20230613.png" alt="" width="800" height="351"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Install Unified Metrics at your server's &lt;code&gt;mods&lt;/code&gt; folder
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;wget &amp;lt;https://github.com/Cubxity/UnifiedMetrics/releases/download/v0.3.8/unifiedmetrics-platform-fabric-0.3.8.jar&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Configure &lt;code&gt;/etc/grafana-agent.yml&lt;/code&gt;, insert the following to the correct place
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;metrics&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;configs&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;integrations&lt;/span&gt;
    &lt;span class="na"&gt;remote_write&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;basic_auth&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
        &lt;span class="na"&gt;password&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;&amp;lt;PW&amp;gt;&lt;/span&gt;
        &lt;span class="na"&gt;username&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;&amp;lt;USERNAME&amp;gt;&lt;/span&gt;
      &lt;span class="na"&gt;url&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;&amp;lt;URL&amp;gt;&lt;/span&gt;
    &lt;span class="na"&gt;scrape_configs&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="c1"&gt;# Add here any snippet that belongs to the `metrics.configs.scrape_configs` section.&lt;/span&gt;
      &lt;span class="c1"&gt;# For a correct indentation, paste snippets copied from Grafana Cloud at the beginning of the line.&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;job_name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;minecraft_scrape&lt;/span&gt;
        &lt;span class="na"&gt;static_configs&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
        &lt;span class="c1"&gt;# Put your server's IP here&lt;/span&gt;
        &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;targets&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;[&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;localhost:9100"&lt;/span&gt; &lt;span class="pi"&gt;]&lt;/span&gt;
        &lt;span class="c1"&gt;# Feel free to add any labels here&lt;/span&gt;
          &lt;span class="na"&gt;labels&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
            &lt;span class="na"&gt;node&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;&amp;lt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Reload &lt;code&gt;grafana-agent&lt;/code&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo systemctl restart grafana-agent.service
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Import dashboard&lt;/p&gt;

&lt;p&gt;We need a dashboard to display our collected data. The provided dashboard by Unified Metrics' author is a good starting point: &lt;a href="https://grafana.com/grafana/dashboards/14756-unifiedmetrics-0-3-x-prometheus/"&gt;https://grafana.com/grafana/dashboards/14756-unifiedmetrics-0-3-x-prometheus/&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;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!&lt;/p&gt;

</description>
      <category>minecraft</category>
      <category>grafana</category>
    </item>
  </channel>
</rss>
