LoginSignup
6
3

More than 3 years have passed since last update.

お茶の子SAISAI SAIを使ってresourceを可視化する

Last updated at Posted at 2019-12-13

この記事はSplunk Advent Calendar 2019、14日目の記事です。

はじめに

saeoshiです。2回目ですw
意外とみんな知らないSAIを使って、Universalforwarderとagent(collectd)を1ライナーでインストールして
簡単にサーバリソースを可視化するぞ!

SAIって・・・?

Splunk App for Infrastructure っていうApp。

Linux/Windows/K8S/Openshift/AWSのリソースを簡単に可視化できて、かつMetrics storeを使うので検索も早いすぐれもの。
Setupめんどくさくね?って思われるけど、実はおちゃのこSAISAIです(錯乱

SplunkにSAIをインストール

https://splunkbase.splunk.com/app/3975/
https://splunkbase.splunk.com/app/4217/

からappをダウンロードして、GUIでUpしましょう。
インストールが終わるとこんな画面。

Screen Shot 2019-12-10 at 8.11.02 AM.jpg

HECの設定をつくる

Metricsを集めるとIndexerに送信するのに、HECが必要なので、Settingしてあげる。
Setting → Data inputsから、HECの設定。

New Tokenを選択して、いい感じに設定。
注意点としては、Metrics Storeを使うので、indexにem_metricsを指定。

Screen Shot 2019-12-12 at 11.30.16 AM.jpg

もう一回、Data inputの画面に移動して、Global Tokenをenable。

Screen Shot 2019-12-10 at 8.17.30 AM.jpg

Receive portをOnにしておく。

Settingから、Forwarding and recivingから、Configure reciveingを選択して、9997ポートをenableしておく。

ワンライナーを生成する

SAIのAppに移動して、Add DataからLinuxを選択して、必要項目を埋める!

Monitoring Machineは、SAIが入ってるhostね。

Screen Shot 2019-12-12 at 11.31.17 AM.jpg

入力が完了すると、下のほうにワンライナーが生成されるんでコピー。

export SPLUNK_URL=172.31.22.100 && export HEC_PORT=8088 && export RECEIVER_PORT=9997 && export INSTALL_LOCATION=/opt/  && export HEC_TOKEN=2ab72fc9-69b9-4644-8879-b1fe679d11b8 && export SAI_ENABLE_DOCKER=  && export DIMENSIONS= METRIC_TYPES=cpu,uptime,df,disk,interface,load,memory,processmon METRIC_OPTS=cpu.by_cpu LOG_SOURCES=/etc/collectd/collectd.log%collectd,\$SPLUNK_HOME/var/log/splunk/*.log*%uf,/var/log/syslog%syslog,/var/log/daemon.log%syslog,/var/log/auth.log%syslog AUTHENTICATED_INSTALL=No && wget --no-check-certificate http://172.31.22.100:8000/static/app/splunk_app_infrastructure/unix_agent/unix-agent.tgz && tar -xzf unix-agent.tgz || gunzip -c unix-agent.tgz | tar xvf - && cd unix-agent && bash install_uf.sh && bash install_agent.sh && cd .. && rm -rf unix-agent && rm -rf unix-agent.tgz

クライアント側で実行する

UFとAgentを入れたいサーバにログインして、↑でコピーしたワンライナーを貼り付けると、ufとcollectdが
インストールされる。

root@ip-172-31-20-242:~/unix-agent# export SPLUNK_URL=172.31.22.100 && export HEC_PORT=8088 && export RECEIVER_PORT=9997 && export INSTALL_LOCATION=/opt/  && export HEC_TOKEN=2ab72fc9-69b9-4644-8879-b1fe679d11b8 && export SAI_ENABLE_DOCK$
R=  && export DIMENSIONS= METRIC_TYPES=cpu,uptime,df,disk,interface,load,memory,processmon METRIC_OPTS=cpu.by_cpu LOG_SOURCES=/etc/collectd/collectd.log%collectd,\$SPLUNK_HOME/var/log/splunk/*.log*%uf,/var/log/syslog%syslog,/var/log/daem$
n.log%syslog,/var/log/auth.log%syslog AUTHENTICATED_INSTALL=No && wget --no-check-certificate http://172.31.22.100:8000/static/app/splunk_app_infrastructure/unix_agent/unix-agent.tgz && tar -xzf unix-agent.tgz || gunzip -c unix-agent.tgz
| tar xvf - && cd unix-agent && bash install_uf.sh && bash install_agent.sh && cd .. && rm -rf unix-agent && rm -rf unix-agent.tgz
--2019-12-12 02:17:16--  http://172.31.22.100:8000/static/app/splunk_app_infrastructure/unix_agent/unix-agent.tgz
Connecting to 172.31.22.100:8000... connected.
HTTP request sent, awaiting response... 303 See Other
Location: http://172.31.22.100:8000/en-US/static/app/splunk_app_infrastructure/unix_agent/unix-agent.tgz [following]
--2019-12-12 02:17:16--  http://172.31.22.100:8000/en-US/static/app/splunk_app_infrastructure/unix_agent/unix-agent.tgz
Reusing existing connection to 172.31.22.100:8000.
HTTP request sent, awaiting response... 200 OK
Length: 234122 (229K) [text/plain]
Saving to: 'unix-agent.tgz'

unix-agent.tgz                                              100%[=========================================================================================================================================>] 228.63K  --.-KB/s    in 0.002s


・
・
・
done.
done.

 Installing any missing dependency...

Reading package lists... Done
Building dependency tree
Reading state information... Done
0 upgraded, 0 newly installed, 0 to remove and 61 not upgraded.

 Step:Configure agent...

root@ip-172-31-20-242:~/unix-agent#

SAIの画面で確認

5分くらいすると、entityが登録された!ってこんな感じででてくる。

Screen Shot 2019-12-12 at 11.33.22 AM.jpg

Metricsを見ていく

Investigateタブをみると、登録したhostがこんな感じで表示されてくる。

Screen Shot 2019-12-12 at 11.34.42 AM.jpg

Entity NameのIPをクリックすると、対象hostのoverviewが表示される。
CPU、Memory、プロセスの状態なんかが出てくる。

FireShot Capture 043 - Metrics Analysis - Splunk App for Infrastructure - 54.199.160.11.png

Analyticsタブを開くと、それぞれのMetricsのDrilldownができる。

Screen Shot 2019-12-12 at 11.39.41 AM.jpg

左側のMetricsタブで必要なMetricsを選択して、右側のAggregationでAvg,Sum/Split/timeshiftとか選択できる。

Screen Shot 2019-12-12 at 11.45.28 AM.jpg

Screen Shot 2019-12-12 at 11.45.35 AM.jpg

Screen Shot 2019-12-12 at 11.45.40 AM.jpg

hostをグルーピングしてみる

investigateの画面で、表示されたhostたちをグルーピングしてみる。
今回はOSで絞って、ubuntuグループを作る。WEBサーバとかでグルーピングできるようになる!

上のバーにos: ubuntuと入力して、save as groupボタンを押す。

Screen Shot 2019-12-12 at 12.09.56 PM.jpg

グループから対象グループを選択すると、こんな感じでgroupごとのリソースを可視化できる。

Screen Shot 2019-12-12 at 12.13.03 PM.jpg

Alertもセットしてみる

表示されてるメトリクスの・・・ボタンをクリックすると、こんな感じでalertを作成するっていうダイアログがでるので
クリックしてみると

Screen Shot 2019-12-12 at 12.19.33 PM.jpg

閾値・通知方法を設定するようにでてくるので、設定しておわり!簡単!

Screen Shot 2019-12-12 at 12.20.13 PM.jpg

おわりに

こんな感じで簡単にMetricsを収集できるので、splunkでログ分析しつつ、metricsを見てっていうフローが使えるのではと思いました。

設定もcollectdベースなので、etc/collectdの設定を修正すればいけるっすね〜

そんな感じで!今年もお疲れっす!

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