何为 Prometheus Exporter?
Prometheus 监控基于一个很简单的模型: 主动抓取目标的指标接口(HTTP 协议)获取监控指标, 再存储到本地或远端的时序数据库. Prometheus 对于指标接口有一套固定的格式要求, 格式大致如下:
# HELP http_requests_total The total number of HTTP requests.
# TYPE http_requests_total counter
http_requests_total{method="post",code="200"} 1027
http_requests_total{method="post",code="400"}    3 

而这样的代理服务, 就称作 Prometheus Exporter, 对于上面那些常见的情形, 社区早就写好了成熟的 Exporter, 它们就是 node_exporter, redis_exporter 和 snmp_exporter。
 

为什么要写 Exporter?
写 exporter 可以把监控信息接进 Prometheus, 那为什么非要接进 Prometheus 呢?
集成到 Prometheus 监控之后, 借助 PromQL 强大的表达能力和 Alertmanager, Grafana 的强大生态, 我们不仅能实现所有监控信息的整合打通, 还能获得更丰富的报警选择和更强的看板能力. 
 

如何为中间件开发Exporter
Prometheus 为开发这提供了客户端工具,用于为自己的中间件开发Exporter,对接Prometheus 。
目前支持的客户端
Go
Java
Python
Ruby 
 
exporter demo:

一个简单的 exporter
下面我将用 golang 实现一个简单的 sample_exporter.go, 其代码大致为:

package main
 
import (
    "fmt"
    "net/http"
)
 
func handler(w http.ResponseWriter, r *http.Request) {
    fmt.Fprintf(w, exportData)
}
 
func main() {
    http.HandleFunc("/", handler)
    http.ListenAndServe(":8080", nil)
}
 
var exportData string = `# HELP sample_http_requests_total The total number of HTTP requests.
# TYPE sample_http_requests_total counter
sample_http_requests_total{method="post",code="200"} 1027 1395066363000
sample_http_requests_total{method="post",code="400"}    3 1395066363000
 
# Escaping in label values:
sample_msdos_file_access_time_seconds{path="C:\\DIR\\FILE.TXT",error="Cannot find file:\n\"FILE.TXT\""} 1.458255915e9
 
# Minimalistic line:
sample_metric_without_timestamp_and_labels 12.47
 
# A histogram, which has a pretty complex representation in the text format:
# HELP sample_http_request_duration_seconds A histogram of the request duration.
# TYPE sample_http_request_duration_seconds histogram
sample_http_request_duration_seconds_bucket{le="0.05"} 24054
sample_http_request_duration_seconds_bucket{le="0.1"} 33444
sample_http_request_duration_seconds_bucket{le="0.2"} 100392
sample_http_request_duration_seconds_bucket{le="0.5"} 129389
sample_http_request_duration_seconds_bucket{le="1"} 133988
sample_http_request_duration_seconds_bucket{le="+Inf"} 144320
sample_http_request_duration_seconds_sum 53423
sample_http_request_duration_seconds_count 144320
 
# Finally a summary, which has a complex representation, too:
# HELP sample_rpc_duration_seconds A summary of the RPC duration in seconds.
# TYPE sample_rpc_duration_seconds summary
sample_rpc_duration_seconds{quantile="0.01"} 3102
sample_rpc_duration_seconds{quantile="0.05"} 3272
sample_rpc_duration_seconds{quantile="0.5"} 4773
sample_rpc_duration_seconds{quantile="0.9"} 9001
sample_rpc_duration_seconds{quantile="0.99"} 76656
sample_rpc_duration_seconds_sum 1.7560473e+07
sample_rpc_duration_seconds_count 2693

当运行此程序,你访问 http://localhost:8080/metrics, 将看到这样的页面: 

与 Prometheus 集成
我们可以利用 Prometheus 的 static_configs 来收集 sample_exporter 的数据。
打开 prometheus.yml 文件, 在 scrape_configs 中添加如下配置:
- job_name: "sample"
    static_configs:
      - targets: ["127.0.0.1:8080"]
重启加载配置,然后到 Prometheus Console 查询,你会看到 simple_exporter 的数据。 

 
 

Prometheus 官方文档中 Writing Exporter 这篇写得非常全面 

exporter的更多相关文章

  1. Exporter - 实现默认的导入方法用于模块

    Exporter - 实现默认的导入方法用于模块 简介: In module YourModule.pm: package YourModule; require Exporter; @ISA = q ...

  2. perl Exporter一些神奇写法

    use base qw(Exporter); @JSON::EXPORT = qw(from_json to_json jsonToObj objToJson encode_json decode_j ...

  3. Dubbo源码学习--服务发布(DubboProtocol、Exporter)

    在Dubbo服务发布的整体流程一文中,只是分析了服务发布的整体流程,具体的细节还没有进一步分析.本节将继续分析服务暴露的过程.在ServiceConfig中通过一句话即可暴露服务,如下: Export ...

  4. zeebe 集成elasticsearch exporter

    zeebe 目前还在一直的开发中,同时一些变动还是挺大的,比如simple monitor 的以前是不需要配置HazelcastExporter的 估计是为了进行集群功能处理,新添加的,以前写的配置基 ...

  5. 编写一个简单的基于jmespath 的prometheus exporter

    目的很简单,因为系统好多监控指标是通过json 暴露的,并不是标准的prometheus metrics 格式,处理方法 实际上很简单,我们可以基于jsonpath 解析json数据,转换为prome ...

  6. exporter API(导出、输出器api)moodel3.3

    Moodle[导出器]是接收数据并将其序列化为一个简单的预定义结构的类.它们确保输出的数据格式统一,易于维护.它们也用于生成外部函数的签名(参数和返回值) 外部函数定义在moodle/lib/exte ...

  7. Go语言开发Prometheus Exporter示例

    一.Prometheus中的基本概念 Prometheus将所有数据存储为时间序列,这里先来了解一下prometheus中的一些基本概念 指标名和标签每个时间序列都由指标名和一组键值对(也称为标签)唯 ...

  8. Prometheus Node_exporter 之 Node Exporter

    Node Exporter 1. Node Exporter Scrape Time type: GraphUnit: secondsLabel: Seconds{{collector}} - 各个收 ...

  9. 7.4 服务远程暴露 - 创建Exporter与启动netty服务端

    为了安全:服务启动的ip全部使用10.10.10.10 远程服务的暴露总体步骤: 将ref封装为invoker 将invoker转换为exporter 启动netty 注册服务到zookeeper 订 ...

  10. Prometheus exporter的Node exporter是可以独立安装,用来测试的

    现在慢慢在把prometheus operator的一些概念组织完整. https://github.com/coreos/prometheus-operator/tree/master/contri ...

随机推荐

  1. P2639 [USACO09OCT]Bessie的体重问题Bessie's Weight

    题目传送门 这题和01背包最大的区别在于它没有价值,所以我们可以人工给它赋一个价值,由于要求体积最大,把价值赋成体积即可.顺带一提,这题数据范围很大,二维会MLE,要压缩成一维才可以AC 下面给出参考 ...

  2. 1481:Maximum sum (前缀和+dp)

    [题目描述] 对一个序列A={a1, a2,..., an}给出函数: t1 t2 d(A) = max{ ∑ai + ∑aj | 1 <= s1 <= t1 < s2 <= ...

  3. python学习第三十六天命名空间的概念

    python命名空间也叫名字空间,也叫名称空间,任何编程语言都有命名空间,大体意思都一样,定义文件所在的目录,下面详细讲述命名空间几种情况 1,locals: 是函数内的名称空间,包括局部变量和形参 ...

  4. C# 使用Silverlight打印图片

    原文:https://www.cnblogs.com/jiajiayuan/archive/2012/04/13/2444246.html Silverlight中的打印只有一个类,那就是PrintD ...

  5. C#面试 笔试题 六

    1.String str=new String("a")和String str = "a"有什么区别? String str = "a"; ...

  6. win10开机出现两个系统

    1.cmd(Ctrl+R) 2.输入msconfig 3.选引导 4.删除多余的系统(切记不能删错)

  7. 2018-2-13-wpf-绑定-TextLength-

    title author date CreateTime categories wpf 绑定 TextLength lindexi 2018-2-13 17:23:3 +0800 2018-2-13 ...

  8. 使用MyEclipse创建Servlet

    https://www.yiibai.com/servlet/creating-servlet-in-myeclipse-ide.html 如何在myeclipse IDE中创建Servlet? 要在 ...

  9. EBCDIC-1025 Russia

  10. 前端学习(三十七)angular(笔记)

    MVC     后台    M         Module             数据层    V         View             视图层    C         Contro ...