1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Drone CI のサーバーメトリクスを取得する

Last updated at Posted at 2020-03-13

はじめに

Drone サーバーでは、/metrics エンドポイントで Prometheus から利用可能なメトリクスが公開されています。

https://drone.example.com/metrics

Go ランタイムによって公開されるパフォーマンスメトリックや
ビルド数などの Drone 固有のメトリクスを参照することができます。

Metrics
https://docs.drone.io/server/metrics/

メトリクスの取得方法も上記ドキュメントに記載があるのですが、2020年3月時点で
微妙に記載が誤っているようなので、こちらに手順を残します。

気をつけておきたいこと

メトリクスの取得は Enterprise Edtion のみの機能であるようです。
Open Source Edtion(OSS版)では /metrics エンドポイントにリクエストを行っても
空の応答が返ってきます。

Docker Hub で公開されているイメージ( https://hub.docker.com/r/drone/drone )は
Enterprise Edtion です。
個人または年間総収益が100万米ドル未満の組織では無料で利用できます。
それ以外の組織では商用ライセンスの購入が必要となりますが、
5000ビルドまでは無料でトライアルできます。

Enterprise FAQ
https://docs.drone.io/enterprise/

OSS版は Docker イメージなどは公開されていないため、以下の手順を参考に
ソースコードからビルドする必要があります。

手順

メトリクスエンドポイントにアクセスするにはユーザーの認証トークンが必要です。
以下は、モニタリング専用のユーザーを作成し、メトリクスの取得を行う例です。
Drone CLI( https://docs.drone.io/cli/install/ )を使用します。
※ユーザーを作成するにはadmin権限が必要です。

$ drone --verison
drone version 1.2.1

$ export DRONE_SERVER=http://drone.exapmle.com
$ export DRONE_TOKEN=60aac7c4e6c45c7fdab05b4aade6be28
$ drone info
User: your_username
Email:

monitor という名前のマシンユーザーを作成します。
ユーザー名は自由に設定できます。

$ openssl rand -hex 16
40528980ea85811431e065ef1bbc340b

$ drone user add monitor --machine --token=40528980ea85811431e065ef1bbc340b
Successfully added user monitor
Generated account token h1GmYpjK49dEKLqfctqQWFlUaQon9z8J

生成されたトークンで /metrics エンドポイントにアクセスできます。
Authorization ヘッダーの値として Authorization: Bearer <access_token>
の形式でリクエストします。

$ curl -i https://drone.example.com/metrics -H "Authorization: Bearer h1GmYpjK49dEKLqfctqQWFlUaQon9z8J"
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0HTTP/1.1 200 OK
Content-Length: 5933
Content-Type: text/plain; version=0.0.4; charset=utf-8
Date: Fri, 13 Mar 2020 04:56:44 GMT
以下メトリクスの出力は省略

Prometheus でメトリクスを取得する場合は scrape_configs: に以下のような定義を
追加することで値を参照可能になります。

  - job_name: 'drone'
    # コンテナにマウントしたファイルを参照
    bearer_token_file: /var/run/secrets/kubernetes.io/serviceaccount/token
    # もしくはbearer_tokenで直書き
    # bearer_token: h1GmYpjK49dEKLqfctqQWFlUaQon9z8J
    
    static_configs:
    - targets: ['drone.example.com']

image.png
image.png

アクセストークンがない場合は、Access deniedになります。

$ curl -i https://drone.example.com/metrics
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100    36  100    36    0     0    734      0 --:--:-- --:--:-- --:--:--   750HTTP/1.1 401 Unauthorized
Content-Type: text/plain; charset=utf-8
X-Content-Type-Options: nosniff
Date: Fri, 13 Mar 2020 07:57:21 GMT
Content-Length: 36

Invalid or missing prometheus token

OSS版の場合、空のレスポンスが返ります。

$ curl -i https://drone.example.com/metrics
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0HTTP/1.1 200 OK
Date: Sat, 07 Mar 2020 01:27:12 GMT
Content-Length: 0

以上です。
参考になれば幸いです。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?