prometheus數(shù)據(jù)遠(yuǎn)程寫(xiě)入elasticsearch方式
prometheus數(shù)據(jù)遠(yuǎn)程寫(xiě)入elasticsearch
一、部署elasticsearch
version: '3'
# 網(wǎng)橋es -> 方便相互通訊
networks:
es:
driver: bridge
services:
elasticsearch:
image: elasticsearch:7.14.1
container_name: elasticsearch # 容器名為'elasticsearch'
restart: unless-stopped # 指定容器退出后的重啟策略為始終重啟,但是不考慮在Docker守護(hù)進(jìn)程啟動(dòng)時(shí)就已經(jīng)停止了的容器
volumes: # 數(shù)據(jù)卷掛載路徑設(shè)置,將本機(jī)目錄映射到容器目錄
- "./elasticsearch/data:/usr/share/elasticsearch/data"
- "./elasticsearch/logs:/usr/share/elasticsearch/logs"
- "./elasticsearch/config/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml"
# - "./elasticsearch/config/jvm.options:/usr/share/elasticsearch/config/jvm.options"
- "./elasticsearch/plugins/ik:/usr/share/elasticsearch/plugins/ik" # IK中文分詞插件
environment: # 設(shè)置環(huán)境變量,相當(dāng)于docker run命令中的-e
TZ: Asia/Shanghai
LANG: en_US.UTF-8
TAKE_FILE_OWNERSHIP: "true" # 權(quán)限
discovery.type: single-node
ES_JAVA_OPTS: "-Xmx512m -Xms512m"
ELASTIC_PASSWORD: "123456" # elastic賬號(hào)密碼
ports:
- "9200:9200"
- "9300:9300"
networks:
- es
kibana:
image: kibana:7.14.1
container_name: kibana
restart: unless-stopped
volumes:
- ./elasticsearch/kibana/config/kibana.yml:/usr/share/kibana/config/kibana.yml
ports:
- "5601:5601"
depends_on:
- elasticsearch
links:
- elasticsearch
networks:
- es其中的配置文件和插件查看地址:https://gitee.com/huanglei1111/docker-compose/tree/master/Linux/elasticsearch
查看是否運(yùn)行成功

訪問(wèn)elasticsearch:ip:端口
訪問(wèn)kibana:ip:端口
- 用戶名:elastic
- 密碼:123456

二、部署prometheus
version: "3"
# 網(wǎng)橋 -> 方便相互通訊
networks:
prometheus:
ipam:
driver: default
config:
- subnet: "172.22.0.0/24"
services:
# 開(kāi)源的系統(tǒng)監(jiān)控和報(bào)警系統(tǒng)
prometheus:
image: prom/prometheus:v2.34.0
container_name: hl-prometheus
restart: unless-stopped
volumes:
- ./config/prometheus.yml:/etc/prometheus/prometheus.yml
# - "./web-config.yml:/etc/prometheus/web-config.yml"
command:
--config.file=/etc/prometheus/prometheus.yml
--web.enable-lifecycle
# --web.config.file=/etc/prometheus/web-config.yml
ports:
- "19090:9090"
depends_on:
- hl-node-exporter
networks:
prometheus:
ipv4_address: 172.22.0.11
# 采集服務(wù)器層面的運(yùn)行指標(biāo)
node-exporter:
image: prom/node-exporter:v1.3.1
container_name: hl-node-exporter
restart: unless-stopped
volumes:
- "./node-exporter/proc:/host/proc:ro"
- "./node-exporter/sys:/host/sys:ro"
- "./node-exporter:/rootfs:ro"
ports:
- "19100:9100"
networks:
prometheus:
ipv4_address: 172.22.0.22
# 使用prometheusbeat 把prometheus的數(shù)據(jù)存儲(chǔ)到elasticsearch中
beat:
image: infonova/prometheusbeat
container_name: hl-prometheusbeat
ports:
- 18081:8080
depends_on:
- hl-prometheus
volumes:
- "./config/prometheusbeat.yml:/prometheusbeat.yml"
- "/etc/localtime:/etc/localtime"
networks:
prometheus:
ipv4_address: 172.22.0.33相關(guān)配置文件查看地址:https://gitee.com/huanglei1111/docker-compose/tree/master/Linux/prometheus/prometheus-es/config
查看是否部署成功

查看監(jiān)控指標(biāo)是否健康
注意:狀態(tài)為down,注意修改prometheus.yml配置文件中targets的ip為服務(wù)器ip

三、通過(guò)prometheusbeat寫(xiě)入數(shù)據(jù)到es
上面在部署docker-compose-prometheus.yml文件已經(jīng)部署啦
如果es有用戶密碼,需要在prometheusbeat.yml配置文件中添加配置
prometheusbeat: # prometheusbeat 服務(wù)的端口。默認(rèn)為8080 listen: ":8080" # Context path. Defaults to /prometheus context: "/prometheus" output.elasticsearch: # elasticsearch 的地址 hosts: ["127.0.0.1:9200"] username: "elastic" password: "123456"
其次修改prometheus.yml配置文件
prometheus 通過(guò) remote_write 來(lái)實(shí)現(xiàn)遠(yuǎn)端存儲(chǔ),所以在 prometheus.yml 配置文件中增加 remote_write 參數(shù)
global:
scrape_interval: 10s
scrape_timeout: 10s
evaluation_interval: 10m
remote_write:
# 遠(yuǎn)程寫(xiě)入到prometheusbeat中
- url: "http://127.0.0.1:18081/prometheus"
write_relabel_configs:
- source_labels: [__name__]
action: keep
regex: go_gc_cycles_automatic_gc_cycles_total
remote_timeout: 30s
scrape_configs:
# prometheus
- job_name: prometheus
static_configs:
- targets: ['127.0.0.1:19090']
labels:
instance: prometheus
# 采集node exporter監(jiān)控?cái)?shù)據(jù),即linux
- job_name: linux
static_configs:
- targets: ['127.0.0.1:19100']
labels:
instance: localhost配置說(shuō)明
- url:prometheusbeat 的服務(wù)地址
- write_relabel_configs:這個(gè)很有用,用于過(guò)濾數(shù)據(jù),可以設(shè)置多個(gè)過(guò)濾條件,同時(shí)滿足這些條件的數(shù)據(jù)才會(huì)被存到遠(yuǎn)端存儲(chǔ)!
- source_labels:根據(jù)哪個(gè)字段進(jìn)行過(guò)濾
- regex:值過(guò)濾的規(guī)則
- action:keep(保留)/drop(丟棄)
所以,上面配置文件中的配置意思就是:prometheus 收到數(shù)據(jù)后,遠(yuǎn)程發(fā)送給 prometheusbeat,并且只發(fā)送 name 為 go_gc_cycles_automatic_gc_cycles_total
然后重啟prometheus。之后當(dāng)收集到數(shù)據(jù)時(shí),就能成功保存到 elasticsearch 了,首次保存時(shí)會(huì)自動(dòng)創(chuàng)建索引:prometheusbeat-7.3.1,數(shù)據(jù)都存在此索引中。
四、elasticsearch head驗(yàn)證
我們通過(guò)瀏覽器安裝elasticsearch head插件,發(fā)現(xiàn)已經(jīng)多了這個(gè)索引了


總結(jié)
以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
Java 高并發(fā)二:多線程基礎(chǔ)詳細(xì)介紹
本文主要介紹Java 高并發(fā)多線程的知識(shí),這里整理詳細(xì)的資料來(lái)解釋線程的知識(shí),有需要的學(xué)習(xí)高并發(fā)的朋友可以參考下2016-09-09
IDEA如何切換數(shù)據(jù)庫(kù)版本mysql5或mysql8
本文介紹了如何將IntelliJ IDEA從MySQL5切換到MySQL8的詳細(xì)步驟,包括下載MySQL8、安裝、配置、停止舊服務(wù)、啟動(dòng)新服務(wù)以及更改密碼等2025-01-01
spring boot tomcat jdbc pool的屬性綁定
這篇文章主要介紹了spring boot tomcat jdbc pool的屬性綁定的相關(guān)資料,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友參考下2018-01-01
IntelliJ IDEA連接MySQL數(shù)據(jù)庫(kù)詳細(xì)圖解
今天小編就為大家分享一篇關(guān)于intellij idea連接mysql數(shù)據(jù)庫(kù)詳細(xì)圖解,小編覺(jué)得內(nèi)容挺不錯(cuò)的,現(xiàn)在分享給大家,具有很好的參考價(jià)值,需要的朋友一起跟隨小編來(lái)看看吧2018-10-10
完美解決request請(qǐng)求流只能讀取一次的問(wèn)題
這篇文章主要介紹了完美解決request請(qǐng)求流只能讀取一次的問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2020-08-08
Java網(wǎng)絡(luò)通信中ServerSocket的設(shè)計(jì)優(yōu)化方案
今天小編就為大家分享一篇關(guān)于Java網(wǎng)絡(luò)通信中ServerSocket的設(shè)計(jì)優(yōu)化方案,小編覺(jué)得內(nèi)容挺不錯(cuò)的,現(xiàn)在分享給大家,具有很好的參考價(jià)值,需要的朋友一起跟隨小編來(lái)看看吧2019-04-04
Spring MVC 請(qǐng)求參數(shù)綁定實(shí)現(xiàn)方式
Spring MVC 是一個(gè)用于構(gòu)建 Web 應(yīng)用程序的框架,它提供了一種方便的方式來(lái)處理 HTTP 請(qǐng)求和響應(yīng),Spring MVC 提供了多種方式來(lái)實(shí)現(xiàn)請(qǐng)求參數(shù)綁定,本文結(jié)合實(shí)例代碼給大家介紹的非常詳細(xì),需要的朋友跟隨小編一起看看吧2023-09-09
Selenium Webdriver實(shí)現(xiàn)截圖功能的示例
今天小編就為大家分享一篇Selenium Webdriver實(shí)現(xiàn)截圖功能的示例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2018-05-05

