インフラ運用管理ツールと
GolangTIS株式会社
池田 大輔
Hello!I am Daisuke IKEDA (@ike_dai)TIS Inc. OSS Promotion Office.
Zabbix Specialist
Golang?
Ref. https://golang.org/
Googleが開発するOSSのプログラミング言語
Shellスクリプトで運用のための処理プログラム作ったり
e.g.AWS操作用スクリプト
DBバックアップ用スクリプト
That happens
・スクリプトを動かすためにツール等が必要
・Shellスクリプトでの処理の面倒さ
(JSONやXMLのパースとか)
What’s concern?
Golangってどうよ?
1One binary file
Golang builds one binary file.
Easy build
$ go build sample.go$ ls -lh-rwxr-xr-x 1 ike_dai staff 2.2M 4 19 23:35 sample-rw-r--r-- 1 ike_dai staff 77B 4 19 23:35 sample.go$ ./sampleHello World$ go run sample.go
package mainimport "fmt"
func main() {fmt.Println("Hello World")
}
※都度buildしなくてもgo runで即時実行可
2Cross platform
The same code for Linux, Windows, MacOS
Cross Compile
$ GOOS=linux GOARCH=amd64 go build sample.go
Linux
Windows
MacOS
$ GOOS=windows GOARCH=amd64 go build sample.go
$ GOOS=darwin GOARCH=amd64 go build sample.go
3Various library
Golang have so many efficient libraries.
[Golang標準ライブラリ] flag : コマンドライン引数処理
log : ログ出力
net: ネットワーク通信関連処理
time: 時刻処理
encoding/json : JSON形式のデータ処理
encoding/xml : XML形式のデータ処理
等
Golang library
[Zabbix]Zabbix API library
https://github.com/AlekSi/zabbix
Zabbix Senderhttps://github.com/AlekSi/zabbix-sender
Golang library
[AWS]AWS API library (AWS official)
https://github.com/aws/aws-sdk-go
Golang library
なければ作ればいい
[JobScheduler] JobScheduler API library
https://github.com/ike-dai/go-jobscheduler
Golang library
Go DocGitHubにコミットすれば自動的にコメントの内容やメソッド、構造体をもとにドキュメントサイトが生成
https://godoc.org/github.com/ike-dai/go-jobscheduler/jobscheduler
4Rich compiler
Golang compiler is so kind.
Go Compiler単純に動く動かないの構文チェックだけじゃなく
・使っていないパッケージをimportしていることを指摘とか
・使っていないのに変数定義していることを指摘とか
Code Build resultpackage main
import "fmt"
func main() {
sample_var := "test"fmt.Println("Hello World")
}
$ go build sample.go # command-line-arguments./sample.go:6: sample_var declared and not used
5Easy Parallel processing
Go routine and channel architecture.
Go routine & channel関数にgoつけて実行するだけで非同期並列処理化
並列処理間のデータ連携にはchannelで送受信
package mainimport "fmt"
func main() {fmt.Println("Hello World")ch := make(chan int)
go backend_process(ch)receive := <-chfmt.Println(receive)
}
func backend_process(ch chan int) {fmt.Println("Backend Process")ch <- 1
}
$ go run sample.goHello WorldBackend Process1
Go routine & channel関数にgoつけて実行するだけで非同期並列処理化
並列処理間のデータ連携にはchannelで送受信
package mainimport "fmt"
func main() {fmt.Println("Hello World")ch := make(chan int)
go backend_process(ch)receive := <-chfmt.Println(receive)
}
func backend_process(ch chan int) {fmt.Println("Backend Process")ch <- 1
}
$ go run sample.goHello WorldBackend Process1
複数処理を並行でバックエンド処理させるのが簡単
I tried!
ZabbixでAWSの状況を監視するテンプレートAWSとZabbixとの連携処理をGolangで実装
1コマンドで処理可能
・EC2インスタンスの情報取得
・CloudWatchの情報取得
・Zabbix Senderプロトコルを話してZabbixに連携
ZAWS (Zabbix AWS monitoring template)
https://github.com/ike-dai/zaws
Case運用管理系ツール展開のHashicorp社のGolangツール
・Serf・Consul・Terraform・Otto・Nomad
DockerもGolang製
Conclusion
Let’s try together!
ノウハウ等、まだ少ないところはあるが可能性は十分あり
さくっと試して日頃の業務を改善するには便利
作ったものを配布、敷居低く試してもらうにはもってこい!
Thanks!Any questions?
You can find me at @ike_dai & [email protected]