A battlesnake about to eat a red dot

Battlesnake players are always looking for fun and creative ways to make their slithery digital companions more competitive. But how well does your Battlesnake function? The strategy of “eat that food” works, but you can improve it. I’ll tell you how to monitor your Battlesnake performance, server, and web application in real-time with New Relic, so you can help your snake live its best life. I'll be working with Node.js but New Relic has great documentation about custom instrumentation to help you instrument your Battlesnake with a variety of languages and tools.

Instrumenting your Battlesnake

1. First, you need a New Relic account. If you already have one, log in. If you do not have an account yet, you can sign up for New Relic for free. There’s no trial period so you can keep using your account forever. Your free account includes 100 GB/month of free data ingest, one free full-access user, and unlimited free basic users.

2. Now you can begin to instrument your snakes! My snake’s example code is located at replit.com. On the New Relic home page, select the + Add more data button on the top right, and choose how you will be adding data. 

The add your data button within New Relic One

My snake is in JavaScript, so I select App Monitoring > Node.js, but when you're on this page you can see that you have a variety of options! Choose what's best for your Battlesnake and select Begin installation.

3. Follow the installation instructions (which are detailed in the Agent installation steps section). Within the Node.js agent option, you have four options, as this screen shot shows. This example uses the package manager options.

Four options for installing the Node.js agent

If you are using the Node.js agent for Docker, here's the documentation: Install the Node.js agent for Docker.

Agent installation steps

1. Name your application. To help you find it in the future, use a unique name that makes sense to you.

2. Install the agent by running this piece of code on your Battlesnake’s terminal:

npm install newrelic --save

3. Download the custom configuration file and put it on the root of your directory. 

Place the configuration files in the root of your directory.

4. Add New Relic to your application by placing this piece of code in the first line of your Battlesnake main module:  require('newrelic');

5. Now when you start your Battlesnake, it will start sending data to your New Relic. Go ahead and play a game to generate some data!

As simple as that your Battlesnake is instrumented and you are collecting its data! But, what to do with this data? Analyze your snake performance of course!

Battlesnake dashboards

  1. Navigate to the New Relic Battlesnake quickstart, and select the + Install quickstart
  2. Select Begin installation to create two dashboards: Performance and Server Status. 
  3. Extra step: Add a getAttributes function to your move request handler, so that data is sent to New Relic.

Now you have two dashboards that read your Battlesnake data and show you lots of cool information. 

In the Performance dashboard you can see:

  • Competitions Status: How is your snake doing against its opponents?
  • Survival: How many turns is it surviving?
  • Growth: How long was your longest snake?
Dashboards showing your BattleSnake's performance

The Battlesnake Server Status dashboard also shows you important server information like:

  • Time consumed by transactions
  • Moves per minute
  • Network traffic
  • Request by endpoint
See the server status for your BattleSnake

And these dashboards are customizable, so if you want to see more or less information, go ahead and customize it.

While these dashboards are fun to look at, you might be asking yourself why you would go through this effort for a couple of pretty screens? Great question! Here are the advantages:

  • Keeping your response time under the 500ms limit is a must for your Battlesnake, and you can check the performance to see where you can improve your code to make sure you never go above the time limit.
  • Watching your baby snake and your skills over time is the best feeling. You can use the dashboards to keep track of how the average snake length improves over time,
  • You can customize your dashboards to get more information on your opponents and find out which snake is defeating yours more often. Then you can replay the games to learn their tactics and build your counterattack.
  • Track your wins and losses, as well as your win percentage.

There are a ton of other things you can chart, so make the dashboard your own. At New Relic, we cover dashboard, but also integrations. Learn about our endless integrations, like <a href="https://newrelic.com/blog/how-to-relic/prometheus-metrics-new-relic">Prometheus</a>, Telegraf, Micrometer, NestJS, Veneur, and plenty of others.