Member-only story

GOでアプリケーション Prometheus Exporterを書く15のステップ

gavin.zhou
12 min readMay 5, 2021

--

要約:例に出している完全なコード:https://github.com/teamzerolabs/mirth_channel_exporter、インストラクションにゆっくり目を通してください。

バックグラウンド

エクスポーターは、 Prometheus モニタリング パイプラインの心臓部であり、魂です。エクスポーターがまだ存在しないのであれば、ぜひ自分で書いてみてください。エクスポータを作るために必要な手順について書きました。心配ありません、とても簡単ですから!

目標

  • GOでエクスポーターを書く
  • エクスポータは、スクレイプされるとアプリケーション(この例ではMirth Connect)に対してREST APIを呼び出す。
  • エクスポータは結果のペイロードをメトリクスに変換する。

1. GO と*パッケージディペンデンシーの設定

go mod init my_first_exportergo get github.com/prometheus/client_golanggo get github.com/joho/godotenv--> creates go.mod file--> Installs dependency into the go.mod file

2. Entry-pointを作成し、*ディペンデンシーをインポートする

main.go fileを作成し、次のようにペーストしてください。

package mainimport ("github.com/joho/godotenv""github.com/prometheus/client_golang/prometheus""github.com/prometheus/client_golang/prometheus/promhttp"

--

--

No responses yet