Prometheus(八):Prometheus监控elasticsearch及常用API

server/2024/9/19 0:51:05/ 标签: prometheus, elasticsearch, jenkins

目录

  • 1 Prometheus监控elasticsearch
    • 1.1 启动ES自带的监控模块暴露指标数据
    • 1.2 通过Prometheus的插件 Elasticsearch Exporter来获取指标数据
      • 1、简介
      • 2、安装
      • 3、Prometheus配置
  • 2 Prometheus常用API
    • 2.1 查询
    • 2.2 删除
    • 2.3 注册服务

elasticsearch_1">1 Prometheus监控elasticsearch

使用Prometheus获取Elasticsearch的监控指标,一共有两者方法:

  • 通过启动ES自带的监控模块暴露指标数据
  • 通过Prometheus的插件 Elasticsearch Exporter来获取指标数据

1.1 启动ES自带的监控模块暴露指标数据

通过启动ES自带的监控模块暴露指标数据,主要步骤如下:
1、在 Elasticsearch 中启用监控模块修改 Elasticsearch 的配置文件,加入监控相关配置:

xpack.monitoring.collection.enabled: true  # 启用监控收集
http.cors.enabled: true
http.cors.allow-origin: "*"  # 设置跨域访问

重启 Elasticsearch 实例后,监控相关 API 会自动启用。
2、配置 Prometheus 监控 Elasticsearch
在 Prometheus 的配置文件中添加 Elasticsearch 的 job:

scrape_configs:
- job_name: 'elasticsearch'metrics_path: "/_prometheus/metrics"static_configs:- targets: - "es-master:9200"     # Elasticsearch master 节点地址

3、Prometheus 初始抓取后,可以在控制台看到 Elasticsearch 的相关指标,如:

  • es_process_cpu_seconds_total # CPU 时间
  • es_jvm_memory_bytes_committed # JVM 内存占用
  • es_indices_indexing_index_total # 索引次数
  • es_nodes_fs_total_bytes # 节点磁盘空间占用
  • 等等

4、根据指标定义告警规则
当某些关键指标超过阈值时,Prometheus 可以发出告警,如:

groups:
- name: elasticsearch rules:- alert: ElasticsearchNodeDownexpr: up{job="elasticsearch", instance="es-master:9200"} == 0for: 5mlabels:severity: criticalannotations:summary: "Elasticsearch master node is down"  

1.2 通过Prometheus的插件 Elasticsearch Exporter来获取指标数据

1、简介

Elasticsearch Exporter主要是用来获取 Elasticsearch的指标数据,是使用Go语言写的,端口号为:9114

2、安装

# 下载安装
wget https://github.com/prometheus-community/elasticsearch_exporter/releases/download/v1.6.0/elasticsearch_exporter-1.6.0.linux-amd64.tar.gz
tar -zxf elasticsearch_exporter-1.6.0.linux-amd64.tar.gz -C /usr/local/# 配置快速启动文件
cat > /lib/systemd/system/elasticsearch_exporter.service << EOF
[Unit]
Description=elasticsearch_exporter
After=syslog.target network.target
[Service]
Type=simple
RemainAfterExit=no
WorkingDirectory=/usr/local/elasticsearch_exporter-1.6.0.linux-amd64/
User=root
Group=root
ExecStart=/usr/local/elasticsearch_exporter-1.6.0.linux-amd64/elasticsearch_exporter  --es.all --es.indices --collector.clustersettings --es.node="elk" --es.indices_settings --es.shards --es.snapshots --es.timeout=5s --web.listen-address ":9114" --web.telemetry-path "/metrics" --es.ssl-skip-verify --es.clusterinfo.interval=5m --es.uri https://elastic:password@192.168.92.100:9200
Restart=always
RestartSec=5
[Install]
WantedBy=multi-user.target
EOF
### 参数说明
--es.all:查询集群中所有节点的统计信息
--es.indices:查询集群中所有索引的统计信息
--es.indices_settings:查询集群中所有索引的设置状态
--collector.clustersettings:查询集群设置的统计信息(从v1.6.0开始,此标志已取代" .cluster_settings")
--es.node:需要获取指标的节点min
--es.shards:查询集群中所有索引的统计信息,包括分片级统计信息
--es.snapshots:导出集群快照的统计信息 
--es.timeout=5s:尝试从Elasticsearch获取统计信息超时 
--web.listen-address ":9114":地址监听网络接口,默认是9114
--es.uri http://用户:口令@IP:端口 :应该连接到的Elasticsearch节点的地址(主机和端口)。
--web.telemetry-path "/metrics":指标路径
--es.ssl-skip-verify:连接Elasticsearch时跳过SSL验证
--es.clusterinfo.interval=5m:集群标签的集群信息更新间隔# 启动
systemctl daemon-reload
systemctl start elasticsearch_exporter.service # 查看
192.168.92.100:9555/metrics

3、Prometheus配置

cat prometheus.yml- job_name: 'elasticsearch'scrape_interval: 15sscrape_timeout: 15smetrics_path: /metricsstatic_configs:- targets: ['192.168.92.100:9555']systemctl restart prometheus

2 Prometheus常用API

在Prometheus中,API的使用很常见,以下是常见的几个

2.1 查询

# 接口查询
curl http://localhost:9090/api/v1# 查询时间段内的
curl 'http://localhost:9090/api/v1/query_range?query=up&start=2023-12-10T20:10:30.781Z&end=2023-12-11T20:11:00.781Z&step=15s'# 获取到所有job
curl http://127.0.0.1:9090/api/v1/label/job/values# 查询10秒内数据
curl http://127.0.0.1:9090/api/v1/query_range?query=my_job&start=1607999428.447&end=1607999468.447&step=10s# 查询当前
curl http://127.0.0.1:9090/api/v1/query?query=network_traffic_input# 查询元数据
curl -g 'http://localhost:9090/api/v1/series?match[]=up&match[]=process_start_time_seconds{job="prometheus"}'

2.2 删除

# 删除某个标签匹配的数据
curl -X POST -g 'http://localhost:9090/api/v1/admin/tsdb/delete_series?match[]={instance="172.18.0.2:8300"}'curl -X POST -g 'http://192.168.92.100:9090/api/v1/admin/tsdb/delete_series?match[]=job="pushgateway"}&start<2023-02-26T00:00:00Z&end=2023-12-11T00:00:00Z'# 删除指定 Metric 名称全部数据.只是将数据标记为删除,实际的数据(tombstones)仍然存在于磁盘上,其在将来的某一时刻会被Prometheus清除释放空间,也可以通过数据清理接口显式地清除。
curl -X PUT -g 'http://127.0.0.1:9090/api/v1/admin/tsdb/delete_series?match[]=up{job="pushgateway"}&start=2023-08-01T00:00:00.000Z'# 删除单个instance的数据
curl -X PUT -g 'http://127.0.0.1:9090/api/v1/admin/tsdb/delete_series?match[]={instance="192.168.92.100:9100"}'
# 删除所有instance的数据,
curl -X PUT -g 'http://127.0.0.1:9090/api/v1/admin/tsdb/delete_series?match[]={instance=~".*"}&start>2023-02-26T00:00:00Z&end=2023-12-12T03:30:00Z'# 从磁盘删除已经被 delete_series 接口删除的数据,并清理现有的 tombstones
curl -X POST http://192.168.92.100:9090/api/v1/admin/tsdb/clean_tombstonescurl -XDELETE -g 'http://localhost:9090/api/v1/series?match[]=up&match[]=process_start_time_seconds{job="prometheus"}'

2.3 注册服务

consul注册服务
curl -X PUT -d '{"id": "test1","name": "test1","address": "192.24.17.156","port": 9500,"tags": ["dev"],"checks": [{"http": "http://192.24.17.156:9500/","interval": "5s"}]}'     http://192.24.17.156:8500/v1/agent/service/register

http://www.ppmy.cn/server/112426.html

相关文章

【自动驾驶】汽车智能驾驶计算芯片

文章目录 概述 术语 硬件要求 软件要求 性能要求 安全性要求 可靠性要求 试验方法 概述 本文介绍汽车智能驾驶计算芯片的软硬件要求、 可靠性和安全性要求、 性能要求&#xff0c;和相应的试验方法。除了用于汽车智能驾驶&#xff0c; 其他领域的计算芯片可参照执行。 …

Python基础语法(17多线程线程锁单例模式)

Python基础语法文章导航&#xff1a; Python基础&#xff08;01初识数据类型&变量&#xff09;Python基础&#xff08;02条件&循环语句&#xff09;Python基础&#xff08;03字符串格式化&运算符&进制&编码&#xff09;Python基础&#xff08;04 基础练习…

谈谈 JS 中new的原理与实现

new 做了那些事&#xff1f;new 返回不同的类型时会有什么表现&#xff1f;手写 new 的实现过程 new 关键词的主要作用就是执行一个构造函数、返回一个实例对象&#xff0c;在 new 的过程中&#xff0c;根据构造函数的情况&#xff0c;来确定是否可以接受参数的传递。下面我们通…

Python 爬虫爬取京东商品信息

Python 爬虫爬取京东商品信息 下面我将逐一解释每一部分的代码 导入库 from selenium import webdriver from selenium.webdriver.edge.service import Service from selenium.webdriver.edge.options import Options import time import random import csv from selenium.co…

命名空间using namespace std

文章目录 为什么要使用命名空间如何自主定义命名空间命名空间的使用方法 为什么要使用命名空间 命名空间的存在是为了提高代码效率&#xff0c;有效的管理编写代码过程中常用的一些常见关键字 #include <vector> #include <iostream> using namespace std;void ma…

Docker设置socks5代理

查看测试环境 $ lsb_release -a No LSB modules are available. Distributor ID: Ubuntu Description: Ubuntu 22.04.4 LTS Release: 22.04 Codename: jammy修改 Docker 服务代理配置文件 $ sudo mkdir -p /etc/systemd/system/docker.service.d $ sudo vi /etc/systemd/syst…

使用Nginx部署前端Vue项目

在使用Nginx部署前端Vue项目时&#xff0c;我们主要关注的是如何高效地将静态资源&#xff08;HTML、CSS、JavaScript、图片等&#xff09;提供给客户端浏览器。Vue.js是一个流行的JavaScript框架&#xff0c;用于构建用户界面&#xff0c;而Nginx作为一个高性能的HTTP和反向代…

Linux驱动学习之input子系统

简介 input 子系统就是管理输入的子系统&#xff0c;和pinctrl、gpio 子系统一样&#xff0c;都是 Linux 内核针对某一类设备而创建的框架。按键、鼠标、键盘、触摸屏等都属于输入设备&#xff0c;linux内核为此专门做了一个叫做input子系统的框架来处理输入事件。输入设备本…

华为AR路由使用PPPoE获取IPv6地址上网

公司搬家&#xff0c;从原有的思科设备换成华为AR路由器&#xff0c;有空研究了下华为AR路由器通过PPPoE拨号获取v6地址&#xff0c;且通过DHCPv6-PD给内网客户端分配地址。 全局开启IPv6 ipv6基本PPPoE配置 interface Dialer1link-protocol pppppp chap user 011111063930p…

什么是ip隧道技术?

你了解ip隧道技术吗&#xff1f;它就好比在开学第一天&#xff0c;你开车送孩子去上学&#xff0c;而平时的道路堵的水泄不通&#xff0c;为了更快的到达学校&#xff0c;你选择走一下高架单向路或是地下隧道。你的车是原始数据包&#xff0c;IP隧道就像高架路或是地下隧道&…

git中的分支是什么?分支有哪些好处?如何建立分支?

git中的分支是什么&#xff1f; 在Git中&#xff0c;分支是版本库中记录版本位置&#xff08;支线&#xff09;的一种方式。分支可以被视为一条时间线&#xff0c;每次提交都会在这条时间线上形成一个新的版本。通过分支&#xff0c;开发者可以在不影响主线&#xff08;通常是…

sql-libs第三关详细解答

首先看看and 12会不会正常显示 结果正常显示&#xff0c;说明存在引号闭合 加了一个引号&#xff0c;发现报错信息中还存在括号&#xff0c;说明sql语句中有括号&#xff0c;那我们还要闭合括号 现在就好了&#xff0c;and 11正常&#xff0c;and 12不正常&#xff0c;那就开始…

Ubuntu环境的MySql下载安装

下载压缩包 此文章下载的mysql版本位5.7.29 sudo wget https://downloads.mysql.com/archives/get/p/23/file/mysql-server_5.7.29-1ubuntu18.04_amd64.deb-bundle.tar解压缩 sudo tar -xvf mysql-server_5.7.29-1ubuntu18.04_amd64.deb-bundle.tar命令解释 -x&#xff1a;…

python dict转json字符串后写入csv后去除多余的引号

问题描述 dict转为标准json格式化字符串json_str&#xff0c;再把这个json字符串使用csv库写入csv文件 会有多余的双引号。 伪代码如下&#xff1a; import os import re import cv2 import glob import csv import json from tqdm import tqdmwith open(test.csv, w, newline…

【全网最全】《2024高教社杯/国赛》 C题 思路+代码+文献 蒙特卡洛+遗传算法 一到三问 农作物的种植策略

&#x1f4af;写在前面 通过百度网盘分享的文件&#xff1a;2024C题 (2).zip 链接&#xff1a;https://pan.baidu.com/s/1eOSebJTYBX-J-M2pVZUBdQ?pwd0azz 提取码&#xff1a;0azz

shell常用环境变量与内置变量

简介 shell变量分为两种,env变量和set变量: env变量:只在当前会话中有效,属于用户环境变量,也可以称为全局变量;set变量:只在自身shell脚本中有效,属于内置变量(也称局部变量),但可以通过export导入到env变量中;由于在当前会话中,可以包含很多shell脚本的运行,所…

请解释一下 JDBC 的作用,并给出一个简单的使用 JDBC 查询数据库的例子?

JDBC (Java Database Connectivity) 是 Java 编程语言中用于连接和操作关系型数据库的标准 API。 它的主要作用是为 Java 应用程序提供了一种标准的方式来访问和处理数据库中的数据&#xff0c;而不需要关心底层具体的数据库系统&#xff08;如 MySQL, Oracle, PostgreSQL 等&…

服务器访问端口命令

服务器访问端口命令是一组用于管理服务器端口的命令行指令。服务器端口是用于与外部设备或应用程序进行通信的逻辑通道&#xff0c;它允许数据在服务器和其他设备之间传输。以下是一些常见的服务器访问端口命令。 netstat&#xff1a;这个命令用于检查服务器上当前的网络连接和…

【flask】python框架flask的hello world

创建一个py文件&#xff0c;写如下内容 # save this as app.py from flask import Flaskapp Flask(__name__)app.route("/") def hello():return "Hello, World!"如下图 在此py文件路径下启动cmd&#xff0c;输入 flask run结果如下图 在浏览器中访问…

Cortex-M3架构学习

本学习参照 “Cortex-M3权威指南”学习&#xff0c;需要详细学习&#xff0c;建议自行观看。 Cortex-M3基础 CM3介绍 Cortex-M3 处理器内核其实就是单片机的中央处理单元&#xff08; CPU &#xff09;。 完整的基于 CM3 的 MCU 还需要很多其它组件&#xff0c;如下&#xff…