LoginSignup
7
5

More than 3 years have passed since last update.

Datadog🐶にwebSocketの接続数を記録した話

Last updated at Posted at 2019-12-10

はじめに

Datadog Advent Calendar 2019の12/11の記事です。
最近弊社でもDatadogを採用し始めました。サービスはまだリリース前で絶賛開発中です。
ちょうどDatadogのAdventCalenderがあるよと先輩に教えてもらったので、飛び入りで参加してみました。

何をしたのか

WebSocketの接続数をDatadogに記録した。
これだけですすいません。
経緯としては弊社で開発中のWebRTCのサービスの負荷試験を行う際に
WebSocketクライアント(シグナリングに使っている)の接続数を記録しておきたかったので
ささっとスクリプトを書いたらかんたんにDatadogのダッシュボードで見ることができるようになったぜということです。

AWSだったのでCloudWatch Logsにカスタムメトリクスを飛ばせばいいとも思ったのですが
権限周りで数分つまったのでええいDatadogになげちゃえと
すぐあきらめちゃうのも時には大事🐶

スクリプト

#!/bin/bash
API_KEY=xxxxxxxxxxxxxxxxxxx
HOST=xxxxxxxxxxxxxxxxx
while :
do
    count=$(netstat -anop | grep 443| grep ESTA| wc -l)
    currenttime=$(date +%s)
    curl -s -X POST -H "Content-type: application/json" \
        -d "{ \"series\" :
            [{\"metric\":\"wss-socket\",
            \"points\":[[$currenttime, $count]],
            \"type\":\"gauge\",
            \"host\":\"${HOST}\",
            \"tags\":[\"hostname:${HOST}\", \"region:ap-northeast-1\"]}
            ]
        }" "https://app.datadoghq.com/api/v1/series?api_key=$API_KEY"
    sleep 10
done

これだけです。
単純にnetstatで出したものをカウントして送っているだけですね。
datadog.png

まとめ

Detadogちょっとつかえるようになった🐶

7
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
5