LoginSignup
3
0

More than 3 years have passed since last update.

Gitlab RunnerをPrometheusで監視する

Last updated at Posted at 2019-07-16
1 / 19

モチベーション


Gitlab CI Runnerのトラブルにいち早く気づきたい

  • zabbixでもいいけど、監視対象に対してプロダクトが大きすぎる感
  • gitlabがprometheus対応を前面に出している
    • 1バイナリを監視対象にデプロイするだけ -> 楽そう

Runnerをオートスケールしたい

  • Runner上で稼働しているJobの数等を分析したうえで適切にスケールさせたい

流行ってる

  • 流行ってる

Prometheusとは

Prometheus


Prometheus Server

INSTALLATIONを参考に


とりあえず立ち上げる

docker run -p 9090:9090 prom/prometheus

http:://localhost:9090/


コメント 2019-07-09 202144.png


config使いたい

手早く進めたかったので、手元にソース用意して進めます。

Building from sourceに従って、


$ mkdir -p $GOPATH/src/github.com/prometheus
$ cd $GOPATH/src/github.com/prometheus
$ git clone https://github.com/prometheus/prometheus.git
$ cd prometheus
$ make build
$ ./prometheus --config.file=prometheus.yml

Gitlab Runner

今回はAWS LightsailにRunnerをセットアップしました。Ubuntu 18.04を使用。
Install GitLab Runner using the official GitLab repositoriesを参考に進めます。


インストール&起動

$ curl -L https://packages.gitlab.com/install/repositories/runner/gitlab-runner/script.deb.sh | sudo bash
$ sudo apt install gitlab-runner

Runnerの状態を確認

$ sudo gitlab-runner status

Runnerをレポジトリに登録

$ sudo gitlab-runner register

プロンプトでURLとかTokenの入力を要求されるので進めると登録完了します。


Runnerの/metricsを有効にする

Gitlab Runnerのconfigファイルである config.toml を以下のように編集します

config.toml
concurrent = 4
check_interval = 0
listen_address = "${ip or hostname}:${port}"

# 以下略

今回私はIPアドレスを登録を利用しようとしましたが、LightsailだとPrivate IPを listen_address フィールドには入れなければならなかったです。


Prometheusの設定

prometheus.yml
scrape_configs:
  - job_name: 'gitlab'
    static_configs:
      - targets: ['${ip or hostname}:${port}']
$ ./prometheus --config.file=prometheus.yml

実行後、http:://localhost:9090/にアクセス、Status->Targets


コメント 2019-07-10 012351.png


あとはPromQLでデータを加工すれば、というところです。

一番時間がかかったのがGitlab RunnerのConfigで、PrometheusのConfigにはほとんど時間を使っていないという...認証やアラートなど必要なものは自分で後付しなければいけませんが、土台がこんなに簡単なのは流石だなと思います。


展望

認証やアラートの追加、Grafanaできれいなグラフを表示したいです。

3
0
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
3
0