Skip to content

Instantly share code, notes, and snippets.

@nshun
Last active June 23, 2018 10:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nshun/9a6cd9e8f453ef1fa238cd8a86634627 to your computer and use it in GitHub Desktop.
Save nshun/9a6cd9e8f453ef1fa238cd8a86634627 to your computer and use it in GitHub Desktop.
GPU サーバのログを ELK サーバに送信して管理する ref: https://qiita.com/shun_n/items/e15451888a348706c672
# http input from gpu server on port 5141
input {
http {
port => 5141
type => "gpu"
}
}
filter {
if [type] == "gpu" {
grok {
match => ["message", "(?<name>[^,]*),(?<Date>[^,]*),(?<gpu_util>[^,]*),(?<memory_util>[^,]*),(?<memory_total>[^,]*),(?<memory_free>[^,]*),(?<memory_used>[^,]*),(?<temperature>[^,]*)"]
}
date{
match => ["Date" , "yyyy/MM/dd HH:mm:ss.SSS"]
timezone => "Asia/Tokyo"
}
mutate{
convert => {
gpu_util => float
memory_util => float
memory_total => float
memory_free => float
memory_used => float
temperature => float
}
remove_field => ["headers"]
}
}
}
output {
if [type] == "gpu" {
elasticsearch {
hosts => ["localhost:9200"]
index => "logstash-gpu-%{+YYYY.MM.dd}"
}
}
$ cd /etc/logstash/conf.d/
$ sudo vim ./01-inputs.txt
$ sudo chmod +x ./sendlog.sh
$ sudo apt install curl
$ crontab -e
* * * * * bash /home/${ユーザー名}/sendlog.sh
$ sudo vim ./10-gpu-filter.conf
$ sudo vim ./30-outputs.conf
$ sudo ufw allow 5141
$ nvidia-smi
Sat Jun 23 16:24:39 2018
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 396.26 Driver Version: 396.26 |
|-------------------------------+----------------------+----------------------+
| GPU Name Persistence-M| Bus-Id Disp.A | Volatile Uncorr. ECC |
| Fan Temp Perf Pwr:Usage/Cap| Memory-Usage | GPU-Util Compute M. |
|===============================+======================+======================|
| 0 GeForce GTX 1080 Off | 00000000:01:00.0 Off | N/A |
| 0% 35C P0 35W / 180W | 0MiB / 8119MiB | 0% Default |
+-------------------------------+----------------------+----------------------+
+-----------------------------------------------------------------------------+
| Processes: GPU Memory |
| GPU PID Type Process name Usage |
|=============================================================================|
| No running processes found |
+-----------------------------------------------------------------------------+
Failed to initialize NVML: Driver/library version mismatch
$ cd ~
$ sudo vim ./sendlog.sh
#!/bin/bash
nvidia-smi --query-gpu=timestamp,utilization.gpu,utilization.memory,memory.total,memory.free,memory.used,temperature.gpu --format=csv,noheader,nounits | (read log ; curl -XPUT ${ELK サーバの IP }:5141 -d "${GPU サーバの名前},${log}" > /dev/null 2>&1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment