> ## Content Index
> Fetch the complete content index at: https://blog.hacking.pub/llms.txt
> Use this file to discover other available public pages before exploring further.

# prometheus 笔记
- URL: https://blog.hacking.pub/2018/04/26/prometheus-biao-da-shi/
- Published: 2018-04-26T17:16:57.000Z
- Updated: 2018-04-26T17:41:35.000Z
- Author: chainhelen
- Tags: prometheus, 笔记, 监控, grafana

#### 笔记

1. go语言创造，静态编译，无需安装太多依赖环境
2. 对于非法的路径，可以根据404返回头过滤成一类 others
3. 使用 record.rules 能够提前把数据组合好，直接访问处理后的数据，而不是实时去求表达式
4. 10分钟是个经验值，grafan 总是 能被 smoothed

Counter

```
// responseCounter Inc() 回复的总数 ，假设传入两个维度（默认还有其他维度） path 、method、status

qps:
sum(rate(requests_total[10m])) 

按照维度分，可以保留下面grafa  
sum(rate(requests_total[10m])) by (endpoint, method, status)

```

Histogram

```
// 耗时responseLatency.Observe() 假如 bucket 10., 20., 30., 50., 80., 100., 200., 300., 500., 1000., 2000., 3000
评价耗时：
sum(rate(response_latency_millisecond_sum[10m])) by (endpoint, method) / sum(rate(response_latency_millisecond_count[10m])) by (endpoint, method)

大于3秒延迟个数
sum(rate(response_latency_millisecond_bucket{le="+Inf"}[10m]))  - sum(rate(response_latency_millisecond_bucket{le="3000"}[10m]))

1s - 3s 延迟个数
sum(rate(response_latency_millisecond_bucket{le="3000"}[10m]))  - sum(rate(response_latency_millisecond_bucket{le="1000"}[10m])) 

10ms - 1s 耗时个数

sum(rate(response_latency_millisecond_bucket{le="1000"}[10m]))  - sum(rate(response_latency_millisecond_bucket{le="10"}[10m])) 

// 删除series
curl -X DELETE \                                                              
  -g 'http://localhost:9090/api/v1/series?match[]=up&match[]=process_start_time_seconds{job="prometheus"}'

```