如何监控容器或K8s中的OpenSearch
概述
当前 OpenSearch 使用的越来越多, 但是 OpenSearch 生态还不尽完善.
针对如下情况:
- 监控容器化或运行在 K8s 中的 OpenSearch
我查了下, 官方还没有提供完备的方案.
这里如何监控 K8s 中的 OpenSearch, 包括安装 exporter 插件、采集、展示全环节。
OpenSearch 简介
- OpenSearch 是一款开源的分布式搜索引擎(从 ElasticSearch 特定版本分叉而来),可以执行快速、可扩展的全文搜索、应用程序和基础设施监控、安全和事件信息管理、运营健康跟踪等用例。
- OpenSearch 具有多种功能和插件,可以帮助索引、保护、监控和分析数据。
- OpenSearch 包含一个演示配置,以便您可以快速启动和运行,但在生产环境中使用 OpenSearch 之前,您必须使用自己的证书、身份验证方法、用户和密码手动配置安全插件。
- OpenSearch 由 AWS 支持,所有组件均可在 GitHub 上获得 Apache 许可证版本 2.0。
Prometheus Exporter Plugin for OpenSearch 简介
- Prometheus Exporter 插件用于将 OpenSearch 指标暴露为 Prometheus 格式。
- 插件版本必须与 OpenSearch 版本完全匹配,因此需要保持 prometheus-exporter-plugin-for-opensearch 版本与 OpenSearch 版本同步。
- 可以通过在每个要由 Prometheus 抓取的 OpenSearch 节点上安装插件来安装插件。
- 可以通过在
config/opensearch.yml中配置静态设置和动态设置来配置插件。 - 指标可以直接在
http(s)://<opensearch-host>:9200/_prometheus/metrics获得。
️相关参考资料
本文会使用到 2 个资源:
具体实现
两种方案:
- 自己制作包含 prometheus-exporter 插件的镜像
- 通过 OpenSearch Helm Chart 安装prometheus-exporter 插件
(方案一)制作包含 prometheus-exporter 插件的镜像并使用
Notes:
这里以
opensearch:2.12版本为例
Dockerfile 内容如下:
FROM opensearchproject/opensearch:2.12.0
LABEL maintainer="cuikaidong@foxmail.com"
ARG EXPORTER_PLUGIN_URL="https://github.com/Aiven-Open/prometheus-exporter-plugin-for-opensearch/releases/download/2.12.0.0/prometheus-exporter-2.12.0.0.zip"
RUN opensearch-plugin install -b ${EXPORTER_PLUGIN_URL}
Notes
如果 docker build 过程下载超时, 可以将对应
EXPORTER_PLUGIN_URL行替换为相关代理的 URL(这里不详述).
或者, 下载后, 通过COPY复制进去后再执行:
opensearch-plugin install -b file:///path/to/prometheus-exporter-2.12.0.0.zip
构建并推送镜像:
docker build -t xxxxx/opensearch:2.12.0-prometheus-exporter -f ./Dockerfile
docker push xxxx/opensearch:2.12.0-prometheus-exporter
Notes
您可以通过 CICD Pipeline, 随着 OpenSearch 和 prometheus-exporter-plugin-for-opensearch 的更新, 自动构建新的镜像.
我相信, 随着 OpenSearch 生态的完善, 应该会有已经包含 exporter 的 OpenSearch 镜像.
对于容器化或 K8s 运行的 OpenSearch, 只需要将镜像改为构建后的, 带 prometheus-exporter 的镜像即可.
如:
原来是:
image: opensearchproject/opensearch:2.12.0
修改为:
image: xxxx/opensearch:2.12.0-prometheus-exporter
(方案二)使用 OpenSearch Helm Chart
如果你是在 K8s 中运行 OpenSearch, 也可以考虑使用 OpenSearch 的 Helm Chart, 它包含了安装第三方插件的功能, 具体 values.yaml 如下:
## Enable to add 3rd Party / Custom plugins not offered in the default OpenSearch image.
plugins:
enabled: true
installList:
- https://github.com/Aiven-Open/prometheus-exporter-plugin-for-opensearch/releases/download/2.12.0.0/prometheus-exporter-2.12.0.0.zip
️参考文档:
修改 pometheus-exporter 的配置
另外, 可以按需修改prometheus-exporter 的配置, 详细配置说明见:
示例配置如下:
在 config/opensearch.yml, 追加如下内容:
plugins.security.disabled: true
prometheus.indices_filter.selected_indices: "log-*,*log,*log*,log*-test"
prometheus.indices_filter.selected_option: "STRICT_EXPAND_OPEN_FORBID_CLOSED"
声明
plugins.security.disabled: true可选项, 允许通过 http 协议访问插件 url. 生产不建议使用. 建议只在快速验证时采用
prometheus.indices_filter.selected_indices仅供参考. 请按需调整.
prometheus.indices_filter.selected_option使用默认配置. 请阅读细节后按需调整.
修改完配置后, 重启容器正常生效.
验证插件已启用
指标可直接在以下位置获取:
http(s)://opensearch-host:9200/_prometheus/metrics
作为示例结果,你将得到如下内容:
# HELP opensearch_process_mem_total_virtual_bytes Memory used by ES process
# TYPE opensearch_process_mem_total_virtual_bytes gauge
opensearch_process_mem_total_virtual_bytes{cluster="develop",node="develop01",} 3.626733568E9
# HELP opensearch_indices_indexing_is_throttled_bool Is indexing throttling ?
# TYPE opensearch_indices_indexing_is_throttled_bool gauge
opensearch_indices_indexing_is_throttled_bool{cluster="develop",node="develop01",} 0.0
# HELP opensearch_jvm_gc_collection_time_seconds Time spent for GC collections
# TYPE opensearch_jvm_gc_collection_time_seconds counter
opensearch_jvm_gc_collection_time_seconds{cluster="develop",node="develop01",gc="old",} 0.0
opensearch_jvm_gc_collection_time_seconds{cluster="develop",node="develop01",gc="young",} 0.0
# HELP opensearch_indices_requestcache_memory_size_bytes Memory used for request cache
# TYPE opensearch_indices_requestcache_memory_size_bytes gauge
opensearch_indices_requestcache_memory_size_bytes{cluster="develop",node="develop01",} 0.0
# HELP opensearch_indices_search_open_contexts_number Number of search open contexts
# TYPE opensearch_indices_search_open_contexts_number gauge
opensearch_indices_search_open_contexts_number{cluster="develop",node="develop01",} 0.0
# HELP opensearch_jvm_mem_nonheap_used_bytes Memory used apart from heap
# TYPE opensearch_jvm_mem_nonheap_used_bytes gauge
opensearch_jvm_mem_nonheap_used_bytes{cluster="develop",node="develop01",} 5.5302736E7
...
使用 Prometheus 采集指标
(仅作为参考示例, 请按需调整), 在 Prometheus 的 scrape 下面, 追加如下内容:
- job_name: opensearch
metrics_path: /_prometheus/metrics
relabel_configs:
- replacement: '<your-instance-name>'
target_label: node
static_configs:
- targets: ['<your-host-name>:9200']
配置 Prometheus Rules 和 Alerts
这里随便举一个简单例子, 现在使用 OpenSearch 的, 之前应该有完备的 ES 相关的 rules 和 alerts. 略作修改即可.
alert: OpenSearchYellowCluster
for: 5m
annotations:
summary: At least one of the clusters is reporting a yellow status.
description: '{{$labels.cluster}} health status is yellow over the last 5 minutes'
runbook_url: ''
labels:
severity: warning
'': ''
expr: |
opensearch_cluster_status == 1
使用 Grafana 查看
可以使用如下 Grafana Dashboard 进行查看:
效果如下:

更多 OpenSearch Dashboard 可以在 https://grafana.com/grafana/dashboards/ 中搜索关键词 "OpenSearch".
总结
如何监控容器或 K8s 中的 OpenSearch?
- 先安装 OpenSearch Prometheus Exporter 插件, 有 2 种办法:
- 自己制作包含 OpenSearch Prometheus Exporter 插件的镜像
- 使用 OpenSearch Helm Chart 安装
- 配置 Prometheus scrape config
- 配置 Prometheus Rules 和 Alerts
- 使用 Grafana 查看
以上.
三人行, 必有我师; 知识共享, 天下为公. 本文由东风微鸣技术博客 EWhisper.cn 编写.
如何监控容器或K8s中的OpenSearch的更多相关文章
- k8s中yaml文常见语法
在k8s中,所有的配置都是 json格式的.但为了读写方便,通常将这些配置写成yaml 格式,其运行的时候,还是会靠yaml引擎将其转化为json,apiserver 也仅接受json的数据类型. y ...
- 【JVM故障问题排查心得】「内存诊断系列」Docker容器经常被kill掉,k8s中该节点的pod也被驱赶,怎么分析?
背景介绍 最近的docker容器经常被kill掉,k8s中该节点的pod也被驱赶. 我有一个在主机中运行的Docker容器(也有在同一主机中运行的其他容器).该Docker容器中的应用程序将会计算数据 ...
- k8s中使用prometheus operator监控外部服务器部署的windows exporter
k8s中使用prometheus operator监控外部服务器部署的windows exporter 0.文档说明 (1)Prometheus Operator是一个流行的k8s集群监控套件,项目地 ...
- k8s中初始化容器(init container)的作用及其使用方法
概述 在容器的部署过程中,有的时候需要在容器运行之前进行一些预配置的工作,比如下载配置,判断某些服务是否启动,修改配置等一些准备的工作,想要实现这些功能,在k8s中可以使用初始化容器,在应用容器运行之 ...
- K8s中的多容器Pod和Pod内容器间通信
容器(Container)常被用来解决比如微服务的单个问题,但在实际场景中,问题的解决往往需要多容器方案.本文会讨论将多个容器整合进单个Kubernetes Pod 中,以及Pod中的容器之间是如何通 ...
- k8s中pod的容器日志查看命令
如果容器已经崩溃停止,您可以仍然使用 kubectl logs --previous 获取该容器的日志,只不过需要添加参数 --previous. 如果 Pod 中包含多个容器,而您想要看其中某一个容 ...
- 在k8s中搭建可解析hostname的DNS服务
2016-01-25更新 上篇文章总结k8s中搭建hbase时,遇到Pod中hostname的DNS解析问题,本篇将通过修改kube2sky源码来解决这个问题. 1 前言 kube2sky在Githu ...
- Prometheus K8S中部署Alertmanager
Prometheus K8S中部署Alertmanager 设置告警和通知的主要步骤如下:一.部署Alertmanager二.配置Prometheus与Alertmanager通信三.配置告警 1. ...
- Kubernetes之在k8s中部署Java应用
部署好了k8s以后 部署参考https://www.cnblogs.com/minseo/p/12055731.html 怎么在k8s部署应用 项目迁移到k8s平台是怎样的流程 1,制作镜像 2,控制 ...
- k8s 中的 Pod 细节了解
k8s中Pod的理解 基本概念 k8s 为什么使用 Pod 作为最小的管理单元 如何使用 Pod 1.自主式 Pod 2.控制器管理的 Pod 静态 Pod Pod的生命周期 Pod 如何直接暴露服务 ...
随机推荐
- 【Azure 应用服务】[App Service For Linux(Function) ] Python ModuleNotFoundError: No module named 'MySQLdb'
问题描述 在使用Azure Function创建新的Python Function时,使用MySQLdb连接数据库时候出现 ModuleNotFoundError: No module named ' ...
- 一个利用go反向代理解决api转发的例子(go反向代理)
实现的效果: 如果访问的url路径是类似 /163/ 或 /163/debian 的形式,则转发到163开源镜像服务器 直接上代码: package main import ( "fmt& ...
- ASP.NET Core 从入门到精通-资源收集导航
ASP.NET Core 从入门到精通-资源收集导航 目录 ASP.NET Core 从入门到精通-资源收集导航 学习路线 学习路线资源导航大全 1,介绍 2,入门 3,教程 创建 Razor 页面 ...
- 在 Spring Boot 3.x 中使用 SpringDoc 2 / Swagger V3
SpringDoc V1 只支持到 Spring Boot 2.x springdoc-openapi v1.7.0 is the latest Open Source release support ...
- spring源码手写aop
AOP: aop切面编程,其实就是spring增强器的一个扩展,就是通过beanPostProcessor的after后置方式实现的,其中在after中把需要的bean通过放射+动态代理完 ...
- [学习笔记]PostgreSQL数据库的安装和配置
安装 安装源 yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat ...
- tomcat SSL安全连接配置简介
tomcat中使用https提供服务,配置的方式有两种.生成或购买CA证书时会要求绑定域名.设置密码和证书别名(aliase). tomcat可用的证书列表里用三个文件: 方式一: <Conne ...
- 摆脱鼠标系列 - 百度搜索 - 火柴 - 快捷键 Ctrl两次
摆脱鼠标系列 - 百度搜索 - 火柴 - 快捷键 Ctrl两次 有两款软件 utools 和 火柴,试用后觉得火柴符合试用功能 这里只用网络搜索 其他功能均不用 搜索用双核浏览器 因为用的老的chro ...
- typeorm-model-generator 数据库映射Model 命令 - nest
typeorm-model-generator 数据库映射Model 命令 NestJs中的控制器.路由.Get.Post方法参数装饰器 https://blog.csdn.net/urwddd/ar ...
- K8S容器环境下资源限制与jvm内存回收
一.k8s中的java资源限制与可能的问题 与以前单机跑单服务的情况相比,在k8s.docker容器化环境下的宿主机内存.cpu相对更大,所以当运行java类程序的时候,就必然有必要对容器进行内存限制 ...