2
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 3 years have passed since last update.

TelegrafでWindowsのメトリクスを取得しInfluxDBに格納しGrafanaで可視化する

Last updated at Posted at 2020-06-22

性能評価をする際に Windows のメトリクスをリアルタイムで監視したかったので,Telagraf で Windows のメトリクスを取得して InfluxDB に格納し,Grafana で可視化した。

概要

ソフト 内容
InfluxDB 時系列DB。メトリクスをここに格納する。
Grafana 様々なデータソースを可視化するGUIツール。
Telegraf 様々なメトリクスを influxdb に収集するコレクタ。
  • 対象の Windows に Telegraf をインストールし,Telegraf から Windows のメトリクスを InfluxDB に流し,Grafana で可視化する。
    • Telegraf -> InfluxDB -> Grafana

Docker コンテナ作成

InfluxDB と Grafana は Docker で用意する。

ディレクトリ

  • ローカルに influxdb, grafana のデータを保持したり influxdb の設定ファイルを読み込んだり出来るようにディレクトリを用意する。
$ pwd
C:\LoadTest\Docker
$ ls
grafana  influxdb

influxdb.conf

データのディレクトリを設定する。

$ pwd
C:\LoadTest\Docker
$ vi influxb/etc/influxdb.conf
[meta]
  dir = "/var/lib/influxdb/meta"

[data]
  dir = "/var/lib/influxdb/data"
  engine = "tsm1"
  wal-dir = "/var/lib/influxdb/wal"

docker-compose.yml

  • InfluxDB, Grafana のコンテナを作成する。
$ pwd
C:\LoadTest\Docker
$ vi docker-compose.yml
$ ls
docker-compose.yml  grafana  influxdb
version: "3"
services:
  influxdb:
    image: influxdb:latest
    ports:
      - "8086:8086"
    volumes:
      - ./influxdb/data:/var/lib/influxdb
      - ./influxdb/etc:/etc/influxdb
  grafana:
    image: grafana/grafana:latest
    ports:
      - "3000:3000"
    volumes:
      - ./grafana:/var/lib/grafana/
    depends_on:
      - influxdb

コンテナ作成

$ pwd
C:\LoadTest\Docker
$ docker-compose up -d
$ docker-compose ps
         Name                  Command               State           Ports
----------------------------------------------------------------------------------------
docker_grafana_1      /run.sh                          Up      0.0.0.0:3000->3000/tcp
docker_influxdb_1     /entrypoint.sh influxd           Up      0.0.0.0:8086->8086/tcp

InfluxDB

動作確認

$ curl -sl -I http://localhost:8086/ping
HTTP/1.1 204 No Content
Content-Type: application/json
Request-Id: 47b37236-8a8b-11ea-8001-0242ac120002
X-Influxdb-Build: OSS
X-Influxdb-Version: 1.8.0
X-Request-Id: 47b37236-8a8b-11ea-8001-0242ac120002
Date: Thu, 14 May 2020 00:44:43 GMT

DB 作成

  • Windows のメトリクスを格納する DB を作成する。
$ curl -i -XPOST http://localhost:8086/query --data-urlencode "q=CREATE DATABASE win_perf"
HTTP/1.1 200 OK
Content-Type: application/json
Request-Id: 4e59158c-957c-11ea-8002-0242ac130003
X-Influxdb-Build: OSS
X-Influxdb-Version: 1.8.0
X-Request-Id: 4e59158c-957c-11ea-8002-0242ac130003
Date: Thu, 14 May 2020 00:46:11 GMT
Transfer-Encoding: chunked

{"results":[{"statement_id":0}]}

Telegraf

パフォーマンスを見たい Windows にインストールする。

インストール

https://portal.influxdata.com/downloads から Windows 用の Telegraf をダウンロードする。
今回は https://dl.influxdata.com/telegraf/releases/telegraf-1.14.2_windows_amd64.zip をダウンロードした。
これを任意のディレクトリに C:\Program Files\telegraf 解凍した。

中身はシンプル。
設定ファイルと実行ファイルのみ。

> tree /F .
C:\PROGRAM FILES\TELEGRAF
    telegraf.conf
    telegraf.exe

telegraf.conf

設定ファイルは InfluxDB の接続先とDB名を設定する。

[[outputs.influxdb]]
  urls = ["http://xxx.xxx.xxx.xxx:8086"]
  database = "win_perf"

起動

> cd C:\"Program Files"\telegraf
> .\telegraf.exe --config .\telegraf.conf

サービス化

> C:\"Program Files"\telegraf\telegraf.exe --service install

サービス起動/停止

> net start telegraf
> net stop telegraf

grafana

管理者作成

userid password
admin admin

data source (InfluxDB) 追加

  • Add data source をクリックする。
  • InfluxDB を選択する。
  • 下記設定し Test & Save をクリックする。
項目 設定
Name InfluxDB_WinPerf
URL http://xxx.xxx.xxx.xxx:8086
Access Server
Database win_perf
User admin
Password admin
HTTP Method GET

フォルダ作成

  • + アイコンをクリックし,Create\Folder を選択する。
  • Name : win_perf
  • Create をクリックする。

Dashboard 作成

  • + アイコンをクリックし,Create\Dashboard を選択する。
  • Add Query をクリックする。
  • Query で InfluxDB_WinPerf を選択する。
  • FROM の select measurement で win_cpu を選択する。
  • FROM の WHERE に host = 見たいホスト名,instance = _Total を設定する。
  • Visualization の Axes を設定する。
    • Unit : percent(0-100)
    • Y-Max : 100
  • General の Title を CPU Usage
  • Save dashboard から
    • Dashboard name : Windows Performance Monitor
    • Folder : win_perf
    • Save をクリックする
2
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
2
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?