CentOS搭建Influxdb v1.8.3并将Prometheus的数据存储到Influxdb中

一、准备工作

CentOS搭建最新版Prometheus将RabbitMQ集群指标exporter到Prometheus

二、获取InfluxDB

[root@node01 ~]# wget https://dl.influxdata.com/influxdb/releases/influxdb-1.8.3.x86_64.rpm
[root@node01 ~]# ll
total 97488
-rw-r--r--. 1 root root 64097226 Sep 30  2020 influxdb-1.8.3.x86_64.rpm

三、安装InfluxDB

 [root@node01 ~]# yum localinstall -y influxdb-1.8.3.x86_64.rpm 

四、启动InfluxDB

 [root@node01 ~]# systemctl start influxdb
 [root@node01 ~]# systemctl enable influxdb

五、配置InfluxDB

[root@node01 ~]# influx
Connected to http://localhost:8086 version 1.8.3
InfluxDB shell version: 1.8.3
> create database prometheus;
> create user prome with password '123321';
> grant all on prometheus to prome;
> show retention policies on prometheus;
name    duration  shardGroupDuration replicaN default
----    --------  ------------------ -------- -------
autogen 8760h0m0s 168h0m0s           1        true
> alter retention policy "autogen" on "prometheus" duration 365d default;
> quit
[root@node01 ~]#

六、配置prometheus.yml

[root@node01 ~]# vi /opt/prometheus/prometheus.yml 
#Remote write configuration (for Graphite, OpenTSDB, or InfluxDB).
remote_write:
   - url: "http://node01:8086/api/v1/prom/write?db=prometheus"


# Remote read configuration (for InfluxDB only at the moment).
remote_read:
   - url: "http://node01:8086/api/v1/prom/read?db=prometheus"
[root@node01 ~]# systemctl restart prometheus 

七、测试结果

[root@node01 ~]# influx
Connected to http://localhost:8086 version 1.8.3
InfluxDB shell version: 1.8.3
> show databases;
name: databases
name
----
_internal
prometheus
test
> use prometheus;
Using database prometheus
> show measurements;
name: measurements
name
----
go_gc_duration_seconds
go_gc_duration_seconds_count
go_gc_duration_seconds_sum
go_goroutines
go_info
go_memstats_alloc_bytes
go_memstats_alloc_bytes_total
go_memstats_buck_hash_sys_bytes
...
prometheus_web_federation_warnings_total
promhttp_metric_handler_requests_in_flight
promhttp_metric_handler_requests_total
rabbitmq_channels
rabbitmq_connections
...
rabbitmq_uptime
rabbitmq_version_info
scrape_duration_seconds
scrape_samples_post_metric_relabeling
scrape_samples_scraped
scrape_series_added
up
> 

八、总结

1、InfluxDB(时序数据库),常用的一种使用场景:监控数据统计。每毫秒记录一下电脑内存的使用情况,然后就可以根据统计的数据,利用图形化界面(配合Grafana)制作内存使用情况的折线图;可以理解为按时间记录一些数据,然后制作图表做统计;

2、使用 Go 语言编写,无需外部依赖。其设计目标是实现分布式和水平伸缩扩展。

上一篇:基于GO语言的单据管理系统


下一篇:2021-03-30