Skip to content

Commit 0df5940

Browse files
Dockerfile (#2)
* Ease debugging * Ease consumption via a Dockerfile and Docker Hub container
1 parent 705b930 commit 0df5940

File tree

6 files changed

+335
-490
lines changed

6 files changed

+335
-490
lines changed

.dockerignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
.eslintrc.yml
2+
.git
3+
.gitignore
4+
.prettierrc
5+
README.md
6+
node_modules
7+
package-lock.json

Dockerfile

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
FROM graphiteapp/graphite-statsd:1.1.10-4
2+
3+
ARG VSN=1.0.0
4+
5+
WORKDIR /etc/service/dogstatsd-2-statsd
6+
7+
# Read /entrypoint to understand why we use run and /etc/service
8+
RUN set -ex \
9+
&& sed -i 's/8125/8135/g' /opt/statsd/config/udp.js \
10+
&& apk add npm git \
11+
&& git clone --depth 1 --branch $VSN https://github.com/paulo-ferraz-oliveira/dogstatsd-2-statsd.git . \
12+
&& npm install --omit=dev \
13+
&& echo -e "#!/bin/bash\n\nexec node index.js" > run \
14+
&& chmod +x run
15+
16+
ENTRYPOINT /entrypoint

README.md

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,31 @@ We implement a very basic translation layer for when you're using
44
Datadog as a remote sink for your metrics but, e.g. locally you're using
55
Graphite.
66

7-
## Reference
7+
## References
88

99
* Datadog: Datagram Format and Shell Usage:
1010
* <https://docs.datadoghq.com/developers/dogstatsd/datagram_shell?tab=metrics>
1111

1212
* Stats: StatsD Metric Types:
1313
* <https://github.com/statsd/statsd/blob/master/docs/metric_types.md>
1414

15+
## Docker
16+
17+
Find a Docker container, created from our [Dockerfile](Dockerfile), at
18+
[Docker Hub: pauloferrazoliveira/dogstatsd-2-statsd](https://hub.docker.com/repository/docker/pauloferrazoliveira/dogstatsd-2-statsd).
19+
1520
## Usage
1621

1722
To use for the first time:
1823

1924
```shell
20-
npm install
25+
npm install --omit=dev
2126
```
2227

2328
Make sure your 8125 is not bound and then:
2429

2530
```shell
26-
node index.js | ./node_modules/bunyan/bin/bunyan
31+
node index.js
2732
```
2833

2934
Now start sending your metrics and watch the logs.
@@ -33,6 +38,18 @@ Now start sending your metrics and watch the logs.
3338
* local port 8125 is not bound (this is our input)
3439
* local port 8135 is bound to `statsd` input
3540

41+
## Contributing
42+
43+
First, make sure you have `yarn` installed locally.
44+
45+
Then run
46+
47+
```shell
48+
npm install
49+
```
50+
51+
to install dev dependencies.
52+
3653
## Linting
3754

3855
To lint

index.js

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
import dgram from 'node:dgram'
2-
import bunyan from 'bunyan'
3-
4-
const log = bunyan.createLogger({ name: 'dogstatsd-2-statsd', level: 'trace' })
52

63
function trans(msg) {
7-
log.trace(`server got: ${msg}`)
4+
console.log(`SRC: ${msg}`)
85

96
// Very dumb translation, but hopefully serves _all_ our purposes.
107
// Assumes input is correctly formatted as Datadog.
@@ -40,21 +37,23 @@ function trans(msg) {
4037
if (sampleRate) {
4138
transMsg += `|@${sampleRate}`
4239
}
43-
44-
log.trace(`transformed it as ${transMsg}`)
40+
console.log(`DST: ${transMsg}`)
4541

4642
return transMsg
4743
}
4844

4945
const udpServer = dgram.createSocket('udp4')
5046
const udpClient = dgram.createSocket('udp4')
47+
const srcPort = 8125
48+
const dstPort = 8135
5149

5250
udpServer
5351
.on('message', (udp) => {
5452
const msgs = udp.toString().split('\n')
5553
msgs.forEach((msg) => {
5654
const transMsg = trans(msg)
57-
udpClient.send(transMsg, 8135, 'localhost')
55+
udpClient.send(transMsg, dstPort, 'localhost')
5856
})
5957
})
60-
.bind(8125)
58+
.bind(srcPort)
59+
console.log(`Relaying UDP ${srcPort} to ${dstPort}...`)

0 commit comments

Comments
 (0)