2017-08-25 DBA日记,telegraf、influxDB、Grafana的安装与基本使用
2017-08-25 18:44
597 查看
目的
理解influxDB的数据收集原理和方法为使用grafana分析数据及展示结作好准备
介绍
[收集数据] Telegraf 是一个用 Go 编写的代理程序,可收集系统和服务的统计数据,并写入到 InfluxDB 数据库。Telegraf 具有内存占用小的特点,通过插件系统开发人员可轻松添加支持其他服务的扩展。[存储数据] InfluxDB 是 Go 语言开发的一个开源分布式时序数据库,非常适合存储指标、事件、分析等数据
[展示数据] Grafana 是纯 Javascript 开发的前端工具,用于访问InfluxDB,自定义报表、显示图表等。
telegraf安装
下载wget http://get.influxdb.org/telegraf/telegraf-0.11.1-1.x86_64.rpm
安装
yum localinstall telegraf-0.11.1-1.x86_64.rpm -y
启动服务、添加开机启动
systemctl start telegraf.service
service telegraf status
systemctl enable telegraf.service
查看版本
telegraf --version
Telegraf - Version 0.11.1
配置
路径:/etc/telegraf/telegraf.conf
示例:安装完成后会有一个示列配置文件,请根据所需仔细阅读文件。
influxDB安装
安装部署,添加yum 源cat <<EOF | sudo tee /etc/yum.repos.d/influxdb.repo [influxdb] name = InfluxDB Repository - RHE e214 L \$releasever baseurl = https://repos.influxdata.com/rhel/\$releasever/\$basearch/stable enabled = 1 gpgcheck = 1 gpgkey = https://repos.influxdata.com/influxdb.key EOF
安装: yum install influxdb -y
启动服务、添加开机启动
service influxdb start systemctl enable influxdb service influxdb status
服务默认使用端口:
Networking By default, InfluxDB uses the following network ports: TCP port 8083 is used for InfluxDB’s Admin panel TCP port 8086 is used for client-server communication over InfluxDB’s HTTP API TCP ports 8088 and 8091 are required for clustered InfluxDB instances
服务验证 -输入 influx 进入数据库
[root@ctn-7-12 ~]# influx Visit https://enterprise.influxdata.com to register for updates, InfluxDB server management, and monitoring. Connected to http://localhost:8086 version 0.11.0 InfluxDB shell 0.11.0
创建一个查询用户
CREATE USER "ptquery" WITH PASSWORD 'ptquery' > show users; user admin ptquery false ptdb1 fals
7.也可以在页面创建查询用户 CREATE USER "ptquery" WITH PASSWORD 'ptquery'
查看服务端口
[root@ctn-7-12 ~]# netstat -tunlp Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp6 0 0 :::8083 :::* LISTEN 22124/influxd tcp6 0 0 :::8086 :::* LISTEN 22124/influxd
浏览器访问数据库管理平台:
http://172.16.7.11:8083/
参考信息:
https://influxdata.com/downloads/
grafana安装
手动安装:wget https://grafanarel.s3.amazonaws.com/builds/grafana-latest-1.x86_64.rpm yum install grafana-latest-1.x86_64.rpm
安装包详情
二进制文件 /usr/sbin/grafana-server 启动脚本 /etc/init.d/grafana-server 环境变量 /etc/sysconfig/grafana-server 配置文件 /etc/grafana/grafana.ini systemd服务 grafana-server.service 日志 /var/log/grafana/grafana.log
服务详情
启动用户 grafana 服务名称 grafana-server 默认端口 3000 账号 admin 密码 admin
启动服务、添加开机启动
systemctl daemon-reload systemctl start grafana-server systemctl status grafana-server systemctl enable grafana-server.service
访问
http://server IP :3000
将数据写入influxDB
influxDB line写入协议介绍
格式: [measurements],[tag]=[tagvalue]空格 [field1]=[field1value],[field1]=[field1value]说明:
命名规则:measurements、tag、field的命名不能含空间,逗号,如必须有,需有\转义;
行格式有严格的要求,“=”左右及","分隔不能有空格
measurements,从统计学角度上看,这叫做样本集。相当于关系数据库的Table
tag,样本集中个体的标识符,相当于关系数据库的primary key,
filed,个体属性的度量值,可以为整型,浮点型,字符型,布尔型 ,相当于关系数据库的一般字段
根据上面的写入协议,编写sh脚本,然后通过telegraf调度执行,就可以把数据写入到influxDB,具体步骤如下:
编写sh脚本,例子如下(bash shell脚本也可以调用python脚本,只要满足line写入协议输出即可):
#! /bin/env bash echo 'employee,empname=kk age=20,salary=3000'
修改telegraf的配置文件/etc/telegraf/telegraf.conf,具体如下:
[[outputs.influxdb]] urls = ["http://192.168.18.118:8086"] #infulxdb地址 database = "telegraf" #数据库 precision = "s" timeout = "5s" username = "admin" #帐号 password = "admin" #密码 [[inputs.exec]] # Shell/commands array commands = ["/tmp/qq.sh"] # Data format to consume. This can be "json", "influx" or "graphite" (line-protocol) # NOTE json only reads numerical measurements, strings and booleans are ignored. data_format = "influx" interval = "60s" #调度间隔 timeout = "15s" #超时控制
检验数据,登录到http://192.168.18.118:8086 数据已经被写入到influxDB中
相关文章推荐
- linux学习使用总结-linux系统的安装和与windows双系统共享,linux常用的基本命令,今天贴在这里和大家分享
- SQL 2005 体验版 基本安装和使用 (1)
- PRTG流量监控基本安装和使用方法
- SERV-U 7 的安装和基本使用方法教程
- ncftp 安装及基本使用
- PRTG流量监控基本安装和使用方法
- Qt使用日记(1): 安装
- Memcached安装和基本使用
- sersync2 完全安装配置说明(一) ----基本功能使用
- lighttpd的安装和基本模块的使用介绍
- sersync2 完全安装配置说明(三) ----插件基本配置和使用
- PRTG流量监控基本安装和使用方法
- Maven3安装以及基本使用
- PC上安装MAC OS. 包括基本软件与双系统使用
- SQL 2005 体验版 基本安装和使用 (3)
- sersync2 完全安装配置说明(三) ----插件基本配置和使用
- Cygwin 介绍 安装 基本使用 交叉编译vivi kernel
- sniffer的安装及基本使用
- MySQL安装和基本使用方法
- 源码包安装mysql的一些基本使用方法