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 Integrations

StatsD StatsD

Last Updated: Oct. 20, 2022

What is StatsD

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. Originally, StatsD referred to a daemon written by Etsy in Node.

Installing 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 config you need to change your PRIVATE_KEY with Coralogix “Send your Logs” API key, you can find it in Data Flow -> API Keys

Also, you need to modify the <remote_write URL> value according to your Coralogix Account Cluster

Cluster (Region)Remote_write URL
EU (Ireland)https://prometheus-gateway.coralogix.com/prometheus/api/v1/write
EU2 (Sweden)https://prometheus-gateway.eu2.coralogix.com/prometheus/api/v1/write
UShttps://prometheus-gateway.coralogix.us/prometheus/api/v1/write
APAC1 (India)https://prometheus-gateway.coralogix.in/prometheus/api/v1/write
APAC2 (Singapore)https://prometheus-gateway.coralogixsg.com/prometheus/api/v1/write

Run StatsD

To run Statsd you just need to 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 
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" ]

Check if metrics arrived to Coralogix

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

If you have any questions or need additional guidance, our support team is available 24/7 via our in-app chat!

On this page