# StatsD

> This document describes the ways in which a user can send ship metrics via statsD to Last9.

Source: https://last9.io/docs/integrations/others/statsd/

[statsD](https://github.com/statsd/statsd) is one of the oldest and most common ways to ship your application or infra metrics to a backend time series database like Graphite, InfluxDB, etc.

statsD comprises 3 basic concepts:

1. client: usually a client library that instruments an application to send metrics e.g. [statsd-kafka](https://github.com/airbnb/kafka-statsd-metrics2)
2. server: the statsd daemon accepting metrics from the `client`
3. backend: TSDB accepting metrics from the `server`

## Pre-requisites

1. You have created a Last9 cluster by following [the getting started guide](/docs/onboard/) and have the following info:
   1. Remote write endpoint URL = `$LEVITATE_REMOTE_WRITE_URL`
   2. Remote write username = `$LEVITATE_REMOTE_WRITE_USERNAME`
   3. Remote write password = `$LEVITATE_REMOTE_WRITE_PASSWORD`
2. Clone [last9-integrations](https://github.com/last9/last9-integrations/) GitHub repo which contains the sample code

## statsD graphite backend method (recommended)

![statsd Graphite backend method](../../../../../assets/content/docs/integrations/others/statsd/9c7b60f-Screenshot_2023-01-05_at_11.48.39_AM.png)

1. `statsd_client_application` pushes metrics to `statsd_server`
2. `statsd_server` has enabled built in backend [Graphite](https://github.com/statsd/statsd/blob/master/docs/backend.md)
3. `vmagent` listens on port 2003 to accept metrics in Graphite format
4. `vmagent` remote writes these metrics to Last9/

A complete example using this approach can be found [here](https://github.com/last9/last9-integrations/tree/master/levitate/remote-write/statsd/vmagent-graphite).

**This is our recommended approach for pushing statsd metrics to Last9.**

## Relay method

![Relay method](../../../../../assets/content/docs/integrations/others/statsd/6bbaca1-Screenshot_2022-12-27_at_10.25.22_PM.png)

1. `statsd_client_application` pushes metrics to `statsd_exporter`
2. `statsd_exporter` transparently relays the metrics to existing
   `statsd_server`, which writes them to the `statsd_backend` e.g. Graphite, InfluxDb.
3. `statsd_exporter` exposes the metrics on a `/metrics` port
4. `vmagent` scrapes these metrics and remote writes them to Last9

A complete example using this approach can be found [here](https://github.com/last9/last9-integrations/tree/master/levitate/remote-write/statsd/relay)

## Repeater method

![Repeater method](../../../../../assets/content/docs/integrations/others/statsd/9097d11-Screenshot_2022-12-27_at_10.48.26_PM.png)

1. statsd_application pushes metrics to statsd_server
2. statsd_server enables
   [repeater](https://github.com/statsd/statsd/blob/master/docs/backend.md) mode
   to push metrics to existing `statsd_backend` and `statsd_exporter`
3. `statsd_exporter` exposes metrics on `/metrics`
4. `vmagent` scrapes these metrics and remote writes them to Last9

A complete example using this approach can be found [here](https://github.com/last9/last9-integrations/tree/master/levitate/remote-write/statsd/repeater)

## Comparison

| Approach         | Pros                                                                    | Cons                                  |
| :--------------- | :---------------------------------------------------------------------- | :------------------------------------ |
| Graphite backend | vmagent can push metrics to Last9, no config changes to the application | Requires changing statsd config       |
| Relay            | No config changes to the statsd.                                        | Requires changing application config. |
| Repeater         | No config changes to the application.                                   | Requires changing statsd config.      |

## Next steps

Create a read token for your Last9 Cluster and follow our guide to [Configure Grafana](/docs/grafana-config/) to visualize the time series data getting sent to Last9.

---

## Troubleshooting

Please get in touch with us on [Discord](https://discord.com/invite/Q3p2EEucx9) or [Email](mailto:support@last9.io) if you have any questions.
