You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

110 lines
4.6 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

# 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.