Postgresqlデータベース監視実験04-Telegrafのインストールと構成
環境
マシン:10.176.140.72
モバイルクラウドの
plat-ecloud01-mgmt-monitor04 monitor04
オペレーティングシステム:
CentOS Linuxリリース7.3.1611(コア)
InfluxDBバージョン:
influxdb-1.7.9
テレグラフバージョン:
telegraf-1.12.6
テレグラフの紹介
Telegrafは、メトリックを収集およびレポートするためのプラグイン駆動型サーバーエージェントであり、マークスタックの最初の部分です。Telegrafには、それを実行しているシステムからさまざまなインジケーターを直接取得したり、サードパーティのAPIからインジケーターを取得したり、statsdおよびKafkaコンシューマーサービスを通じてインジケーターを監視したりできる多くのプラグインがあります。また、InfluxDB、Graphite、OpenTSDB、Datadog、Librato、Kafka、MQTT、NSQなど、さまざまな他のデータストア、サービス、メッセージキューにメトリックを送信できる出力プラグインもあります。
特徴:
- 完全にgo言語で開発され、外部からの介入なしにバイナリファイルにコンパイルされました。
- 最小化されたメモリフットプリントを使用します。
- プラグインシステムが新しい入力と出力を簡単に追加できるようにします。
- 既製のサービスとAPIには、多くの一般的なサービスプラグインがすでに含まれており、ほとんどの機能に対応できます。
インストールする
公式ダウンロードインターフェイス:https://portal.influxdata.com/downloads/
rpmパッケージアドレス:https://repos.influxdata.com/centos/7/x86_64/stable
tarパッケージアドレス:https://dl.influxdata.com/telegraf/releases
最新の安定版を直接ダウンロードしたい場合は、リポジトリパッケージを直接作成することもできます。
[root@localhost ~]# cat <<EOF | sudo tee /etc/yum.repos.d/influxdb.repo
> [influxdb]
> name = InfluxDB Repository - RHEL \$releasever
> baseurl = https://repos.influxdata.com/rhel/\$releasever/\$basearch/stable
> enabled = 1
> gpgcheck = 1
> gpgkey = https://repos.influxdata.com/influxdb.key
> EOF
[influxdb]
name = InfluxDB Repository - RHEL $releasever
baseurl = https://repos.influxdata.com/rhel/$releasever/$basearch/stable
enabled = 1
gpgcheck = 1
gpgkey = https://repos.influxdata.com/influxdb.key
インストール:
[root@localhost opt]# yum install telegraf
テレグラフを開始し、プロセス情報を表示します。
[root@localhost opt]# systemctl start telegraf
[root@localhost opt]# ps -ef |grep telegraf|grep -v grep
telegraf 29023 1 0 03:36 ? 00:00:00 /usr/bin/telegraf -config /etc/telegraf/telegraf.conf -config-directory /etc/telegraf/telegraf.d
構成
yumを使用してtelegrafをインストールすると、関連するtelegraf構成ファイルがデフォルトでetcディレクトリに生成され、バックアップ後に変更されます。
今回は、influxdb関連の接続構成のみを変更して、テレグラフがキャプチャしたデータをinfluxdbに渡すことができるようにします。
[root@localhost opt]# cp /etc/telegraf/telegraf.conf /etc/telegraf/telegraf.conf.bak
[root@localhost opt]# vim /etc/telegraf/telegraf.conf
###############################################################################
# OUTPUT PLUGINS #
###############################################################################
# Configuration for sending metrics to InfluxDB
[[outputs.influxdb]]
## The full HTTP or UDP URL for your InfluxDB instance.
##
## Multiple URLs can be specified for a single cluster, only ONE of the
## urls will be written to each interval.
urls = ["http://127.0.0.1:8086"] #连接url,我这里使用本机
## The target database for metrics; will be created as needed.
## For UDP url endpoint database needs to be configured on server side.
database = "telegraf" #数据库名
## Name of existing retention policy to write to. Empty string writes to
## the default retention policy. Only takes effect when using HTTP.
retention_policy = ""
## Timeout for HTTP messages.
timeout = "5s" #http连接超时时间
## HTTP Basic Auth
username = "telegraf" #数据库用户名
password = "metricsmetricsmetricsmetrics" #数据库用户密码
保存後、テレグラフを再起動します。
[root@localhost opt]# systemctl restart telegraf
データ収集
influxdbに対応するユーザーとデータベースを
作成します。通常のユーザーtelegrafを作成し、パスワードをmetricsmetricsmetricsmetricsに設定します
[root@localhost ~]# influx
Connected to http://localhost:8086 version 1.7.9
InfluxDB shell version: 1.7.9
> create user "telegraf" with password 'metricsmetricsmetricsmetrics'
> > show users;
user admin
---- -----
telegraf false
データを格納するデータベーステレグラフを作成します。
> create database telegraf
> show databases;
name: databases
name
----
_internal
telegraf
確認する
influxdbを入力して、測定値を表示します。
[root@localhost ~]# influx -precision rfc3339
Connected to http://localhost:8086 version 1.7.9
InfluxDB shell version: 1.7.9
> use telegraf
Using database telegraf
> show measurements
name: measurements
name
----
cpu
disk
diskio
kernel
measurement_name
mem
processes
swap
system
Telegrafのデフォルト設定では、マシンの基本的な監視情報を取得してデータを表示します。
> select * from disk order by time desc limit 10
name: disk
time device free fstype host inodes_free inodes_total inodes_used mode path total used used_percent
---- ------ ---- ------ ---- ----------- ------------ ----------- ---- ---- ----- ---- ------------
2019-12-07T06:55:50Z sda1 866697216 xfs localhost.localdomain 523953 524288 335 rw /boot 1063256064 196558848 18.48650147928994
2019-12-07T06:55:50Z dm-0 43850530816 xfs localhost.localdomain 23609204 23654400 45196 rw / 48420556800 4570025984 9.438193787973955
2019-12-07T06:55:40Z sda1 866697216 xfs localhost.localdomain 523953 524288 335 rw /boot 1063256064 196558848 18.48650147928994
2019-12-07T06:55:40Z dm-0 43850530816 xfs localhost.localdomain 23609204 23654400 45196 rw / 48420556800 4570025984 9.438193787973955
2019-12-07T06:55:30Z sda1 866697216 xfs localhost.localdomain 523953 524288 335 rw /boot 1063256064 196558848 18.48650147928994
2019-12-07T06:55:30Z dm-0 43850530816 xfs localhost.localdomain 23609204 23654400 45196 rw / 48420556800 4570025984 9.438193787973955
2019-12-07T06:55:20Z sda1 866697216 xfs localhost.localdomain 523953 524288 335 rw /boot 1063256064 196558848 18.48650147928994
2019-12-07T06:55:20Z dm-0 43850571776 xfs localhost.localdomain 23609204 23654400 45196 rw / 48420556800 4569985024 9.438109195803381
2019-12-07T06:55:10Z sda1 866697216 xfs localhost.localdomain 523953 524288 335 rw /boot 1063256064 196558848 18.48650147928994
2019-12-07T06:55:10Z dm-0 43850571776 xfs localhost.localdomain 23609204 23654400 45196 rw / 48420556800 4569985024 9.438109195803381
デフォルトのデータキャプチャ間隔は10秒で、データは正常に書き込まれていることがわかります