杨梅冲
每天在想什么呢?

一、Exporter概述

       所有可以向Prometheus提供监控样本数据的程序都可以被称为一个Exporter。而Exporter的一个实例称为target,如下所示,Prometheus通过轮询的方式定期从这些target中获取样本数据:

 

注:安装好Exporter后会暴露一个http://ip:端口/metrics的HTTP服务,通过Prometheus添加配置- targets: ['node_exporter:9100'](默认会加上/metrics),Prometheus就可以采集到这个http://ip:端口/metrics里面所有监控样本数据

二、Exporter的来源

从exporter来源讲,分为2类:

1.社区提供( https://prometheus.io/docs/instrumenting/exporters/ )

Prometheus社区提供了丰富的Exporter实现,涵盖了从基础设施,中间件以及网络等各个方面的监控功能。这些Exporter可以实现大部分通用的监控需求
2.用户自定义
除了直接使用社区提供的Exporter程序以外,用户还可以基于Prometheus提供的Client Library创建自己的Exporter程序,目前Promthues社区官方提供了对以下编程语言的支持:Go、Java/Scala、Python、Ruby。同时还有第三方实现的如:Bash、C++、Common Lisp、Erlang,、Haskeel、Lua、Node.js、PHP、Rust等

三、Exporter类型

通常可以将Exporter分为2类:
1.直接采集型

这类Exporter直接内置了相应的应用程序,用于向Prometheus直接提供Target数据支持。这样设计的好处是,可以更好地监控各自系统的内部运行状态,同时也适合更多自定义监控指标的项目实施。例如cAdvisor、Kubernetes等,它们均内置了用于向Prometheus提供监控数据的端点。

2.间接采集型

原始监控目标并不直接支持Prometheus,需要我们使用Prometheus提供的Client Library编写该监控目标的监控采集程序,用户可以将该程序独立运行,去获取指定的各类监控数据值。例如,由于Linux操作系统自身并不能直接支持Prometheus,用户无法从操作系统层面上直接提供对Prometheus的支持,因此单独安装Node exporter,还有数据库或网站HTTP应用类等Exporter。

四、Exporter规范

所有的Exporter程序都需要按照Prometheus的规范,返回监控的样本数据。以Node Exporter为例,当访问http://192.168.10.14:9100/metrics地址时会返回以下内容:

# HELP go_gc_duration_seconds A summary of the pause duration of garbage collection cycles.
# TYPE go_gc_duration_seconds summary
go_gc_duration_seconds{quantile="0"} 2.8298e-05
go_gc_duration_seconds{quantile="0.25"} 5.1855e-05
go_gc_duration_seconds{quantile="0.5"} 6.7122e-05
go_gc_duration_seconds{quantile="0.75"} 9.3062e-05
go_gc_duration_seconds{quantile="1"} 0.001225949
go_gc_duration_seconds_sum 0.005331134
go_gc_duration_seconds_count 48

以#开始的行通常都是注释内容。这些样本数据集合说明如下:

● 以#HELP开始的行,表示metric的帮助与说明注释,可以包含当前监控指标名称和对应的说明信息。
● 以#TYPE开始的行,表示定义metric类型,可以包含当前监控指标名称和类型,类型有Counter、Gauge、Histogram、Summary和Untyped。
● 非#开头的行,就是监控样本数据

4.1 监控样本规范

metric_name [
  "{" label_name "=" `"` label_value `"` { "," label_name "=" `"` label_value `"` } [ "," ] "}"
] value [ timestamp ]

其中metric_name和label_name必须遵循PromQL的格式规范要求。value是一个float格式的数据,timestamp的类型为int64(从1970-01-01 00:00:00以来的毫秒数),timestamp为可选默认为当前时间。具有相同metric_name的样本必须按照一个组的形式排列,并且每一行必须是唯一的指标名称和标签键值对组合。

go_memstats_mcache_sys_bytes{} 15600
go_memstats_mcache_sys_bytes{instance="localhost:9090", job="prometheus"} timestamp VALUE

 

 

 

 

 

 

 

 

 

posted on 2024-04-24 15:03  杨梅冲  阅读(28)  评论(0编辑  收藏  举报