天天看點

prometheus專題—(六)普羅米修斯概念介紹

prometheus 基本概念 

在prometheus graph頁面上查詢資料

node_cpu_seconds_total{mode="user"}

sample 資料點      
prometheus專題—(六)普羅米修斯概念介紹

sample 資料點

type sample struct {
    t int64
    v float64
}


sample代表一個資料點

size:16byte: 包含 1個8byte int64時間戳和1個8byte float64 value 
      
prometheus專題—(六)普羅米修斯概念介紹

Label 标簽

type Label struct {
    Name, Value string
}

一對label 比如 `cpu="0"` `mode: "user"`
      
prometheus專題—(六)普羅米修斯概念介紹

Labels 标簽組

type Labels []Label

- 就是metric 一個名額的所有tag values


      

prometheus四種查詢類型

即時向量 Instant vector : 一組時間序列,每個時間序列包含一個樣本,所有樣本共享相同的時間戳

# 在prometheus頁面上就是table查詢 ,對應查詢接口 /api/v1/query

prometheus專題—(六)普羅米修斯概念介紹
vector 向量 
type Vector []Sample
1. - ector 向量,是samples的别名,但是所有sample具有相同timestamp ,常用作instance_query的結果

      

2.範圍向量 Range vector : 一組時間序列,每個時間序列包含一個樣本,所有樣本共享相同的時間戳

> 在prometheus頁面上就是graph查詢 ,對應查詢接口 /api/v1/query 

> Matrix 矩陣
type Matrix []Series

Matrix是series的切片,一般的range_query傳回的結果      
prometheus專題—(六)普羅米修斯概念介紹
1. 标量 `Scalar` 一個簡單的數字浮點值
2. String 一個簡單的字元串值;目前未使用      

四種标簽比對模式

1. `=` 等于
   - 查詢: cpu第一個核并且是使用者态的資料  node_cpu_seconds_total{mode="user",cpu="0"}
2. `!=` 不等于
   - 查詢: 非lo網卡的接收位元組數  node_network_receive_bytes_total{device!="lo"}
3. `=~` 正則比對
   - 查詢: 挂載點以/run開頭的檔案系統剩餘位元組數  node_filesystem_avail_bytes{mountpoint=~"^/run.*"}
4. `!~` 正則非比對
   - 查詢: 塊裝置名字不包含vda的讀位元組數  node_disk_read_bytes_total{device!~".*vda.*"}      

四種資料類型

  • gauge 目前值
node_memory_MemFree_bytes      
  • counter 計數器是代表一個累積名額單調遞增計數器,其價值隻能在重新啟動增加或歸零。例如,您可以使用計數器來表示已服務請求,已完成任務或錯誤的數量。
http_request_total      
  • histogram 直方圖樣本觀測(通常之類的東西請求持續時間或響應大小)和計數它們配置的桶中。它還提供所有觀察值的總和
# http所有接口 總的95分位值
# sum/count 可以算平均值
prometheus_http_request_duration_seconds_sum/ prometheus_http_request_duration_seconds_count

# histogram_quantile(0.95, sum(rate(prometheus_http_request_duration_seconds_bucket[5m])) by (le,handler))

histogram_quantile(0.95, sum(rate(prometheus_http_request_duration_seconds_bucket[1m])) by (le))

# range_query接口的95分位值
histogram_quantile(0.95, sum(rate(prometheus_http_request_duration_seconds_bucket{handler="/api/v1/query_range"}[5m])) by (le))

      

summary 摘要會采樣觀察值(通常是請求持續時間和響應大小之類的東西)。盡管它還提供了觀測值的總數和所有觀測值的總和,但它可以計算滑動時間視窗内的可配置分位數。

# gc耗時

# 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"} 0.000135743
go_gc_duration_seconds{quantile="0.25"} 0.000872805
go_gc_duration_seconds{quantile="0.5"} 0.000965516
go_gc_duration_seconds{quantile="0.75"} 0.001055636
go_gc_duration_seconds{quantile="1"} 0.006464756

# summary 平均值
go_gc_duration_seconds_sum /go_gc_duration_seconds_count


-       

範圍向量選擇器 Range Vector Selectors

- 範圍矢量的工作方式與即時矢量一樣,不同之處在于它們從目前即時中選擇了一定範圍的樣本。文法上,将持續時間附加在[]向量選擇器末尾的方括号()中,以指定應為每個結果範圍向量元素提取多遠的時間值。
      
  • 隻能作用在counter上

時間範圍

ms -毫秒
s -秒
m - 分鐘
h - 小時
d -天-假設一天總是24小時
w -周-假設一周始終為7天
y -年-假設一年始終為365天

直接查詢報錯   node_network_receive_bytes_total{device!="lo"}[1m]
Error executing query: invalid expression type "range vector" for range query, must be Scalar or instant Vector

> 需要疊加一個非聚合函數 如 rate irate delta idelta sum 等

-  計算網卡入流量
  rate(node_network_receive_bytes_total{device!="lo"}[1m])

> > 時間範圍 ,不能低于采集間隔

- - 采集30秒 ,查詢10秒則無資料
- - rate(node_network_receive_bytes_total{device!="lo"}[10s])

      

繼續閱讀