【metricbeat】通过metricbeat采集prometheus指标

通过metricbeat采集prometheus指标

通过beat采集prometheus内的单个指标。

低版本beat只能全量

环境

低版本metricbeat只能全量采集

软件版本:metricbeat==8.11.1

解压

cmd 复制代码
tar zxvf metricbeat-8.11.1-linux-x86_64.tar.gz -C /usr/local

配置

首先,修改metricbeat.yml,把output指定为接收地址,这里使用了logstash,原定使用kafka,但是本地kafka的版本较低,会出现发送失败问题。

output.logstash:
  hosts: ["192.168.113.138:5044"]

其次是修改modules.d/下的prometheus.yml.disabled为prometheus.yml,然后修改配置

cmd 复制代码
cp prometheus.yml.disabled prometheus.yml

第一块是配置prometheus

yml 复制代码
#- module: prometheus
#  period: 10s
#  hosts: ["localhost:9090"]
#  metrics_path: /metrics
  #metrics_filters:
  #  include: []
  #  exclude: []
  #username: "user"
  #password: "secret"

  # This can be used for service account based authorization:
  #bearer_token_file: /var/run/secrets/kubernetes.io/serviceaccount/token
  #ssl.certificate_authorities:
  #  - /var/run/secrets/kubernetes.io/serviceaccount/service-ca.crt

  # Use Elasticsearch histogram type to store histograms (beta, default: false)
  # This will change the default layout and put metric type in the field name
  #use_types: true

  # Store counter rates instead of original cumulative counters (experimental, default: false)
  #rate_counters: true

第二块是配置Prometheus 服务器使用 remote_write 选项发送的指标

yml 复制代码
# Metrics sent by a Prometheus server using remote_write option
#- module: prometheus
#  metricsets: ["remote_write"]
#  host: "localhost"
#  port: "9201"

  # Secure settings for the server using TLS/SSL:
  #ssl.certificate: "/etc/pki/server/cert.pem"
  #ssl.key: "/etc/pki/server/cert.key"

  # Use Elasticsearch histogram type to store histograms (beta, default: false)
  # This will change the default layout and put metric type in the field name
  #use_types: true

  # Store counter rates instead of original cumulative counters (experimental, default: false)
  #rate_counters: true

  # Define patterns for counter and histogram types so as to identify metrics' types according to these patterns
  #types_patterns:
  #  counter_patterns: []
  #  histogram_patterns: []

第三块才是我们用到的,将使用 PromQL 收集指标

- module: prometheus
  metricsets: ["query"]
  hosts: ["localhost:9090"]
  period: 10s
  queries:
  - name: "instant_vector"
    path: "/api/v1/query"
    params:
      query: "sum(rate(prometheus_http_requests_total[1m]))"
  - name: "range_vector"
    path: "/api/v1/query_range"
    params:
      query: "up"
      start: "2019-12-20T00:00:00.000Z"
      end:  "2019-12-21T00:00:00.000Z"
      step: 1h
  - name: "scalar"
    path: "/api/v1/query"
    params:
      query: "100"
  - name: "string"
    path: "/api/v1/query"
    params:
      query: "some_value"

效果

日志平台接收到可以看到

点开后发现有很多字段,最主要的是metricset_name,是配置query,采集回来的值字段为prometheus_query_scalar ,以此类推,会有prometheus_query_string 和prometheus_query_instant_vector

相关推荐
新手unity自用笔记4 小时前
项目-坦克大战学习-子弹的移动与销毁
笔记·学习·c#
qinzechen4 小时前
分享几个做题网站------学习网------工具网;
java·c语言·c++·python·c#
yufei-coder8 小时前
C# Windows 窗体开发基础
vscode·microsoft·c#·visual studio
dangoxiba8 小时前
[Unity Demo]从零开始制作空洞骑士Hollow Knight第十三集:制作小骑士的接触地刺复活机制以及完善地图的可交互对象
游戏·unity·visualstudio·c#·游戏引擎
AitTech8 小时前
深入理解C#中的TimeSpan结构体:创建、访问、计算与格式化
开发语言·数据库·c#
hiyo58512 小时前
C#中虚函数和抽象函数的概念
开发语言·c#
开心工作室_kaic14 小时前
基于微信小程序的校园失物招领系统的设计与实现(论文+源码)_kaic
c语言·javascript·数据库·vue.js·c#·旅游·actionscript
时光追逐者19 小时前
WaterCloud:一套基于.NET 8.0 + LayUI的快速开发框架,完全开源免费!
前端·microsoft·开源·c#·.net·layui·.netcore
friklogff20 小时前
【C#生态园】打造现代化跨平台应用:深度解析.NET桌面应用工具
开发语言·c#·.net
hiyo5851 天前
C#的面向对象
开发语言·c#