Our next-gen architecture is built to help you make sense of your ever-growing data. Watch a 4-min demo video!

Back to All Docs

StatsD StatsD

Last Updated: Nov. 01, 2023

StatsD is an open-source standard and, by extension, a set of tools that can be used to send, collect, and aggregate custom metrics from any application.

This tutorial demonstrates how to install and run StatsD to send your metrics to Coralogix.

Install StatsD

Manual installation

  1. Install Node.js (All Current and LTS Node.js versions are supported.)
  2. Clone the project https://github.com/statsd/statsd
  3. Go into the directory statsd
  4. Install coralogix backend:
    npm i @coralogix/statsd-backend
  5. Create a config file named coralogixConfig.js from the following example:
module.exports = {
  deleteIdleStats: true,
  deleteGauges: true,
  deleteTimers: true,
  deleteCounters: true,
  port: 8125,
  backends: ["@coralogix/statsd-backend"],
  coralogix: {
    privateKey: "<PRIVATE_KEY>",
    apiHost: "<remote_write URL>",
    prefix: "host1",
    applicationName: "statsd",
    subsystemName: "statsd",
    mappings: {
      timer_test: {
        histogram_options: { buckets: [50, 100, 250, 500, 1000] },
        labels: { job: 'test_job' }
      },
      timer_test_2: {
        histogram_options: { buckets: [50, 100, 250, 500, 1000] }
      }
    }
  }
}

In this configuration, you need to:

Run StatsD

To run StatsD, execute it:

node stats.js coralogixConfig.js

Send Test Metrics

The basic line protocol expects metrics to be sent in the format:
<metricname>:<value>|<type>

So the simplest way to send in metrics from your command line if you have StatsD running with the default UDP server on localhost would be:

echo "foo:1|c" | nc -u -w0 127.0.0.1 8125
echo "timer_test:65|ms|#tag_1:value,tag_2:value_2" | /usr/bin/nc -u -w0 127.0.0.1 8125

Using Docker

To run inside a Docker container, just replace the provided Dockerfile in the repository with this one.

Then follow the Manual Install steps.

FROM node:14

RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app

# Install python
# RUN apk add --no-cache --update g++ gcc libgcc libstdc++ linux-headers make python

# Setup node envs
ARG NODE_ENV
ENV NODE_ENV $NODE_ENV

# Install dependencies
COPY package.json /usr/src/app/
RUN npm install 
RUN npm cache clean --force

# Copy required src (see .dockerignore)
COPY . /usr/src/app

COPY coralogixConfig.js config.js

# Expose required ports
RUN npm install @coralogix/statsd-backend 
EXPOSE 8125/udp
EXPOSE 8126

# Start statsd
ENTRYPOINT [ "node", "stats.js", "config.js" ]

Validation

You can go to Grafana in your account and browse metrics to see if they are arriving:

StatsD metrics integration Coralogix

Support

Need help?

Our world-class customer success team is available 24/7 to walk you through your setup and answer any questions that may come up.

Feel free to reach out to us via our in-app chat or by sending us an email at [email protected].

On this page