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.
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.
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.
4. Add New Relic to your application by placing this piece of code in the first line of your Battlesnake main module:
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!
- Navigate to the New Relic Battlesnake quickstart, and select the + Install quickstart.
- Select Begin installation to create two dashboards: Performance and Server Status.
- Extra step: Add a
getAttributesfunction to your
moverequest 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?
The Battlesnake Server Status dashboard also shows you important server information like:
- Time consumed by transactions
- Moves per minute
- Network traffic
- Request by endpoint
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.
Interested in more? I have a GitHub repository that you can use to deploy an instrumented Battlesnake with Heroku with one click. It's in experimental mode, so feel free to add your contribution to that repo. Also, check out our <a href="https://newrelic.com/platform/infrastructure">New Relic Infrastructure</a> to learn about infrastructure monitoring.
I would love to see how you use the power of data and observability to make your snake a winner, so share your New Relic and Battlesnake project with us on Twitter!
Les opinions exprimées sur ce blog sont celles de l'auteur et ne reflètent pas nécessairement celles de New Relic. Toutes les solutions proposées par l'auteur sont spécifiques à l'environnement et ne font pas partie des solutions commerciales ou du support proposés par New Relic. Veuillez nous rejoindre exclusivement sur l'Explorers Hub (discuss.newrelic.com) pour toute question et assistance concernant cet article de blog. Ce blog peut contenir des liens vers du contenu de sites tiers. En fournissant de tels liens, New Relic n'adopte, ne garantit, n'approuve ou n'approuve pas les informations, vues ou produits disponibles sur ces sites.