StatsD Gauges, Counters, and Timers on MetricFire

StatsD Gauges, Counters, and Timers on MetricFire

Table of Contents

Introduction

StatsD is a daemon that listens for counters, timers, and gauges of any function that you specify. For example, if you had an IoT device with a button, you could set a counter on that button to track how many times it has been pressed.

Normally, you would need to set up and configure the StatsD daemon on a server to get started. However, today we will be using MetricFire’s StatsD add-on, so we can get our stats up and running quickly.

To get started, sign up for the MetricFire free trial. The rest of this article will walk you through exactly how to send metrics to MetricFire with StatsD.

StatsD is normally set up by the user, where the user specifies a URL that acts as the StatsD endpoint. But by using MetricFire, all of that is already done for us. All we need to do is send the metrics to the given URL from MetricFire, and the information will be ready to display in Grafana.

  ‍

Key Takeaways

  1. StatsD is a daemon that tracks counters, timers, and gauges for various functions, such as monitoring button presses on IoT devices.
  2. Backend languages typically have libraries for sending StatsD metrics, which require specifying the URL, port, and prefix.
  3. The article demonstrates sending StatsD metrics to MetricFire using Python. It shows how to install the StatsD package and configure the StatsClient with the necessary parameters.
  4. The article explains how to create a Grafana dashboard and query the metric sent to MetricFire. It showcases the ability to visualize the data, making it useful for tracking user engagement or application usage.
  5. StatsD is a versatile tool that can be used for tracking various application metrics to enhance application performance.

 

How to send metrics

The chart below shows the general layout of how to send metrics to StatsD. Typically most backend languages have a library that helps send StatsD metrics to the URL, port, and prefix. Once you have installed the library for StatsD in the language that your app is written in, you can start adding code to track certain functions with counters, gauges, or timers. When using MetricFire, the URL, port, and prefix are given by the StatsD add-on in the MetricFire app.

 ‍

undefined

‍ 

Today, we will be using Python to send StatsD metrics to our MetricFire account. Let’s first get the StatsD package with:

 

sudo pip install statsd

‍ 

undefined

‍ 

Next, let’s get our URL, port, and prefix from our MetricFire account. Go to your Dashboard and Add-Ons > Add-Ons > StatsD.

‍ 

undefined

‍ 

Then there should be an Enable button. After enabling StatsD, you should see your URL, port, and prefix like below.

 ‍

undefined

‍ 

Now, with this information, we can start sending metrics to our MetricFire account. Make an executable Python file with this code in it:

‍ 

#!/usr/bin/env python3
import statsd
c = statsd.StatsClient("URL", PORT, prefix="PREFIX_KEY")
def button():
    c.incr("metric.button", 1)
    print("button has been pressed")
if __name__ == "__main__":
    for i in range(5):
        button()

‍  

undefined

‍ 

Sending metrics

Next, let’s test our counter metric. If we execute this file once, it will send metrics information to MetricFire. Specifically, the counter will count 5 button presses each time we execute the file, and send that value to MetricFire under the metric name "counters metric button count". Then we can import the value into Grafana by querying the metric name in a Grafana dashboard. Let's take a look at these steps below.

First let's execute our file:

‍ 

undefined

‍ 

Then, confirm that the metric has been sent to our metric treemap. The image below shows that MetricFire has received the metrics from our Python file.

‍ 

undefined

‍ 

Once you see it pop up on your metric treemap, we should be able to plot it on a graph in Grafana. Let’s create a new dashboard in Grafana.

 ‍

undefined

‍ 

And then we will query our metric called "counters metric button count". On the graph below, the cursor is hovering over a single dot. That query has a dot with 5.000 as a value on the graph. Which is correct, since our counter counted 5 button presses after our last execute of the Python file.

‍ 

undefined

‍ 

Let’s spam the Python file a little more to see what it looks like on the graph. The image below shows what a bunch of random executes of our Python file look like. You can also see the original 5-button presses at 14:28.

‍ 

undefined

‍ 

StatsD is useful for tracking how long a user spends time on your app, or how often something gets used. There are endless amounts of stats that you can track to help improve your application.

If you're interested in trying out StatsD in MetricFire, sign up for our free trial. Try out the StatsD add-on, and see if you can make some StatsD graphs in Grafana. You can also get us on the phone by booking a demo - feel free to talk to us directly about how MetricFire can help with your monitoring needs.

You might also like other posts...
metricfire Jul 08, 2025 · 5 min read

Introducing MetricFire Logging: Visualize Logs Alongside Metrics

By combining logs and metrics in MetricFire's Hosted Grafana, you can troubleshoot faster, spot... Continue Reading

metricfire Jul 01, 2025 · 3 min read

ログをメトリクスに変換: Loki、Python、Telegrafによるオープンソースの構築(前編)

ELKスタックを使用せず、最小限の労力で、軽量でオープンソースのセットアップを使用して、生のログを使用可能なメトリクスに変換する方法を紹介します。Loki、Python、Telegrafを使用して、ログをGraphiteメトリクスに変換し、簡単に監視やアラートを出すことができます。システム管理者、DevOps初心者、またはゼロからより革新的なモニタリングパイプラインを構築することに興味がある方に最適です。 Continue Reading

metricfire Jul 01, 2025 · 5 min read

OpenTelemetryを使用してSnowflakeの観測性を高める方法

このガイドでは、OpenTelemetry(contrib)をSnowflakeに統合して、クエリのパフォーマンス、実行時間、キューイング、ストレージの使用率、課金への影響を可視化する方法を説明します。SnowflakeメトリクスをスクレイピングするためのOpenTelemetry Collectorをセットアップし、データをエクスポートするためのエンドポイントを設定し、よくある落とし穴のトラブルシューティングを行います。最後には、クエリとリソースのパフォーマンスに関する実用的な洞察を提供する、Snowflake用のスケーラブルで自動化されたモニタリングの設定ができるようになります。 Continue Reading

header image

We strive for 99.999% uptime

Because our system is your system.

14-day trial 14-day trial
No Credit Card Required No Credit Card Required