|
|
# promethus exportor
|
|
|
https://blog.csdn.net/wanger5354/article/details/120211773
|
|
|
|
|
|
https://github.com/teamzerolabs/mirth_channel_exporter
|
|
|
|
|
|
https://cloud.tencent.com/developer/article/1744817
|
|
|
|
|
|
https://blog.csdn.net/weixin_45413603/article/details/107024467
|
|
|
|
|
|
https://medium.com/teamzerolabs/15-steps-to-write-an-application-prometheus-exporter-in-go-9746b4520e26
|
|
|
|
|
|
# build on arm64
|
|
|
```bash
|
|
|
cd /root
|
|
|
rm -rf sreExporter
|
|
|
git clone https://git.sre.ink/go/sreExporter.git
|
|
|
cd sreExporter
|
|
|
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 GO111MODULE=on go mod tidy
|
|
|
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 GO111MODULE=on go build -o exporter.bin main.go
|
|
|
docker build -t sre/exporter:arm64 .
|
|
|
kubectl rollout restart deployment -n kuboard sre-exporter
|
|
|
```
|
|
|
|
|
|
|
|
|
# Prometheus的基本指标类型
|
|
|
1、 Counter:只增不减的累加指标
|
|
|
|
|
|
Counter就是一个计数器,表示一种累积型指标,该指标只能单调递增或在重新启动时重置为零,例如,您可以使用计数器来表示所服务的请求数,已完成的任务或错误。
|
|
|
|
|
|
2、 Gauge:可增可减的测量指标
|
|
|
|
|
|
Gauge是最简单的度量类型,只有一个简单的返回值,可增可减,也可以set为指定的值。所以Gauge通常用于反映当前状态,比如当前温度或当前内存使用情况;当然也可以用于“可增加可减少”的计数指标。
|
|
|
|
|
|
3、Histogram:自带buckets区间用于统计分布的直方图
|
|
|
|
|
|
Histogram主要用于在设定的分布范围内(Buckets)记录大小或者次数。
|
|
|
|
|
|
例如http请求响应时间:0-100ms、100-200ms、200-300ms、>300ms 的分布情况,Histogram会自动创建3个指标,分别为:
|
|
|
|
|
|
事件发送的总次数:比如当前一共发生了2次http请求
|
|
|
所有事件产生值的大小的总和:比如发生的2次http请求总的响应时间为150ms
|
|
|
事件产生的值分布在bucket中的次数:比如响应时间0-100ms的请求1次,100-200ms的请求1次,其他的0次
|
|
|
4、Summary:数据分布统计图
|
|
|
|
|
|
Summary和Histogram类似,都可以统计事件发生的次数或者大小,以及其分布情况。
|
|
|
|
|
|
Summary和Histogram都提供了对于事件的计数_count以及值的汇总_sum,因此使用_count,和_sum时间序列可以计算出相同的内容。
|
|
|
|
|
|
同时Summary和Histogram都可以计算和统计样本的分布情况,比如中位数,n分位数等等。不同在于Histogram可以通过histogram_quantile函数在服务器端计算分位数。 而Sumamry的分位数则是直接在客户端进行定义。因此对于分位数的计算。 Summary在通过PromQL进行查询时有更好的性能表现,而Histogram则会消耗更多的资源。相对的对于客户端而言Histogram消耗的资源更少。
|
|
|
|
|
|
# 视频讲解如何开发exporter
|
|
|
链接: https://pan.baidu.com/s/1I_eoqypKl6Pw7R3Ai5m0sQ 密码: cs75
|
|
|
|
|
|
go build
|
|
|
./mirth_channel_exporter [flags]
|
|
|
|
|
|
|
|
|
http://127.0.0.1:9101/metrics
|
|
|
[]: # Language: markdown
|
|
|
[]: # Path: readme.md
|
|
|
|
|
|
# Mirth Channel Exporter
|
|
|
|
|
|
Export [Mirth Connect](https://en.wikipedia.org/wiki/Mirth_Connect) channel
|
|
|
statistics to [Prometheus](https://prometheus.io).
|
|
|
|
|
|
Metrics are retrieved using the Mirth Connect REST API. This has only been tested
|
|
|
with Mirth Connect 3.7.1, and it should work with version after 3.7.1.
|
|
|
|
|
|
To run it:
|
|
|
|
|
|
go build
|
|
|
./mirth_channel_exporter [flags]
|
|
|
|
|
|
## Exported Metrics
|
|
|
| Metric | Description | Labels |
|
|
|
| ------ | ------- | ------ |
|
|
|
| mirth_up | Was the last Mirth CLI query successful | |
|
|
|
| mirth_messages_received_total | How many messages have been received | channel |
|
|
|
| mirth_messages_filtered_total | How many messages have been filtered | channel |
|
|
|
| mirth_messages_queued | How many messages are currently queued | channel |
|
|
|
| mirth_messages_sent_total | How many messages have been sent | channel |
|
|
|
| mirth_messages_errored_total | How many messages have errored | channel |
|
|
|
|
|
|
## Flags
|
|
|
./mirth_channel_exporter --help
|
|
|
|
|
|
| Flag | Description | Default |
|
|
|
| ---- | ----------- | ------- |
|
|
|
| log.level | Logging level | `info` |
|
|
|
| web.listen-address | Address to listen on for telemetry | `:9141` |
|
|
|
| web.telemetry-path | Path under which to expose metrics | `/metrics` |
|
|
|
| config.file-path | Optional environment file path | `None` |
|
|
|
|
|
|
## Env Variables
|
|
|
|
|
|
Use a .env file in the local folder, /etc/sysconfig/mirth_channel_exporter, or
|
|
|
use the --config.file-path command line flag to provide a path to your
|
|
|
environment file
|
|
|
```
|
|
|
MIRTH_ENDPOINT=https://mirth-connect.yourcompane.com
|
|
|
MIRTH_USERNAME=admin
|
|
|
MIRTH_PASSWORD=admin
|
|
|
```
|
|
|
|
|
|
## Notice
|
|
|
|
|
|
This exporter is inspired by the [consul_exporter](https://github.com/prometheus/consul_exporter)
|
|
|
and has some common code. Any new code here is Copyright © 2020 TeamZero, Inc. See the included
|
|
|
LICENSE file for terms and conditions. |