postgresql数据库监控实验04-Telegraf安装配置

postgresql数据库监控实验04-Telegraf安装配置

环境

机器:
移动云的
10.176.140.72 plat-ecloud01-mgmt-monitor04 monitor04

操作系统:
CentOS Linux release 7.3.1611 (Core)

InfluxDB版本:
influxdb-1.7.9

telegraf版本:
telegraf-1.12.6

telegraf简介

Telegraf是一个插件驱动的服务器代理,用于收集和报告度量,并且是标记堆栈的第一部分。Telegraf有许多插件,可以直接从运行它的系统中获取各种指标,从第三方api获取指标,甚至通过statsd和Kafka消费者服务监听指标。它还具有输出插件,可以将指标发送到各种其他数据存储、服务和消息队列,包括InfluxDB, Graphite, OpenTSDB, Datadog, Librato, Kafka, MQTT, NSQ等。

特性:

  1. 完全使用go语言开发,他被编译为一个完全没有外部干预的二进制文件。
  2. 使用最小化的内存占用。
  3. 提供插件系统可以方便的添加新输入输出。
  4. 现成的服务和api已经包含了很多流行的服务插件,能满足大部分功能。

安装

参见:telegraf官网介绍

官方下载界面:https://portal.influxdata.com/downloads/

rpm包地址: https://repos.influxdata.com/centos/7/x86_64/stable
tar包地址: https://dl.influxdata.com/telegraf/releases

如果想直接下载最新稳定版,可也可以直接创建repo包:

[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

安装:

扫描二维码关注公众号,回复: 10741752 查看本文章
[root@localhost opt]# yum install telegraf

启动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后,会默认在etc目录下生成相关telegraf的配置文件,备份后进行修改:

我这次仅修改influxdb相关连接配置,让telegraf可以将抓取的数据传给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"     #数据库用户密码

保存后重启telegraf:

[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

创建数据库telegraf用来存储数据:

> create database telegraf
> show databases;
name: databases
name
----
_internal
telegraf

验证

进入influxdb,查看measurement:

[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

可以看到默认的数据抓取间隔为10s,数据正常写入

发布了136 篇原创文章 · 获赞 58 · 访问量 36万+

猜你喜欢

转载自blog.csdn.net/sunbocong/article/details/103420194