# compute-engine/jobs/global/metrics-snapshot/promql.yaml
# compute-engine/jobs/global/healthcheck-report/extra_promql_v3.yaml

# 1 QPS
qps:
  - name: 'QPS:by_type'
    expr: 'label_replace(sum(rate(tidb_executor_statement_total{cluster_id=~".*$tidb_cluster"}[2m]))by(type),"name","$1","type","(.*)")'
    unit: '1'
  - name: 'QPS:total'
    expr: 'label_replace(sum(rate(tidb_executor_statement_total{cluster_id=~".*$tidb_cluster"}[2m])),"name","total","","")'
    unit: '1'
  - name: 'QPS_failed:total'
    expr: 'label_replace(sum(rate(tidb_server_execute_error_total{cluster_id=~".*$tidb_cluster"}[2m])),"name","failed","","")'
    unit: '1'
# 2 TiDB CPU/Mem
tidb_resource:
  - name: 'TiDB_cpu_avg:total'
    expr: 'label_replace(avg(rate(process_cpu_seconds_total{cluster_id=~".*$tidb_cluster",component="tidb"}[2m]))*100,"name","CPU Avg","","")'
    unit: '%'
  - name: 'TiDB_CPU_max:total'
    expr: 'label_replace(max(rate(process_cpu_seconds_total{cluster_id=~".*$tidb_cluster",component="tidb"}[2m]))*100,"name","CPU Max","","")'
    unit: '%'
  - name: 'TiDB_CPU_delta:total'
    expr: 'label_replace((max(rate(process_cpu_seconds_total{cluster_id=~".*$tidb_cluster",component="tidb"}[2m]))-min(rate(process_cpu_seconds_total{cluster_id=~".*$tidb_cluster",component="tidb"}[2m])))*100,"name","CPU Delta","","")'
    unit: '%'
  - name: 'TiDB CPU Quota'
    expr: 'label_replace(max(tidb_server_maxprocs{cluster_id=~".*$tidb_cluster",component="tidb"})*100,"name","CPU Quota","","")'
    unit: '%'
  - name: 'TiDB_memory_max:total'
    expr: 'label_replace(max(process_resident_memory_bytes{cluster_id=~".*$tidb_cluster",component="tidb"})/1024/1024/1024,"name","MEM Max","","")'
    unit: 'GiB'
# 3 TiKV CPU/Mem
tikv_resource:
  - name: 'TiKV_cpu_avg:total'
    expr: 'label_replace(avg(rate(process_cpu_seconds_total{cluster_id=~".*$tidb_cluster",component="tikv"}[2m]))*100,"name","CPU Avg","","")'
    unit: '%'
  - name: 'TiKV_CPU_max:total'
    expr: 'label_replace(max(rate(process_cpu_seconds_total{cluster_id=~".*$tidb_cluster",component="tikv"}[2m]))*100,"name","CPU Max","","")'
    unit: '%'
  - name: 'TiKV_CPU_delta:total'
    expr: 'label_replace((max(rate(process_cpu_seconds_total{cluster_id=~".*$tidb_cluster",component="tikv"}[2m]))-min(rate(process_cpu_seconds_total{cluster_id=~".*$tidb_cluster",component="tikv"}[2m])))*100,"name","CPU Delta","","")'
    unit: '%'
  - name: 'TiKV CPU Quota'
    expr: 'label_replace(max(tikv_server_cpu_cores_quota{cluster_id=~".*$tidb_cluster",component="tikv"})*100,"name","CPU Quota","","")'
    unit: '%'
  - name: 'TiKV_memory_max:total'
    expr: 'label_replace(max(process_resident_memory_bytes{cluster_id=~".*$tidb_cluster",component="tikv"})/1024/1024/1024,"name","MEM Max","","")'
    unit: 'GiB'
# 4 PD CPU/Mem
pd_resource:
  - name: 'PD_CPU_max:total'
    expr: 'label_replace(max(rate(process_cpu_seconds_total{cluster_id=~".*$tidb_cluster",component=~".*(pd|tso|scheduling).*"}[2m]))*100,"name","CPU Max","","")'
    unit: '%'
  - name: 'PD CPU Quota'
    expr: 'label_replace(max(pd_service_maxprocs{cluster_id=~".*$tidb_cluster",component=~".*(pd|tso|scheduling).*"})*100,"name","CPU Quota","","")'
    unit: '%'
  - name: 'PD_memory_max:total'
    expr: 'label_replace(max(process_resident_memory_bytes{cluster_id=~".*$tidb_cluster",component=~".*(pd|tso|scheduling).*"})/1024/1024/1024,"name","MEM Max","","")'
    unit: 'GiB'
# 5 Uptime by component
uptime:
  - name: 'TiDB_uptime:by_instance'
    expr: 'label_replace(time()-process_start_time_seconds{cluster_id=~".*$tidb_cluster",component="tidb"},"name","$1","instance","(.*)")'
    unit: 's'
  - name: 'TiKV_uptime:by_instance'
    expr: 'label_replace(time()-process_start_time_seconds{cluster_id=~".*$tidb_cluster",component="tikv"},"name","$1","instance","(.*)")'
    unit: 's'
  - name: 'TiFlash_uptime:by_instance'
    expr: 'label_replace(tiflash_system_asynchronous_metric_Uptime{cluster_id=~".*$tidb_cluster"},"name","$1","instance","(.*)")'
    unit: 's'
  - name: 'PD_uptime:by_instance'
    expr: 'label_replace((time()-process_start_time_seconds{cluster_id=~".*$tidb_cluster",component=~"pd"}),"name","$1","instance","(.*)")'
    unit: 's'
  - name: 'TiProxy_uptime:by_instance'
    expr: 'label_replace((time()-process_start_time_seconds{cluster_id=~".*$tidb_cluster",component=~"tiproxy"}),"name","$1","instance","(.*)")'
    unit: 's'
# 6 TiKV iops
tikv_iops:
  - name: 'TiKV_IOPS_Read'
    expr: 'label_replace(max(sum(rate(node_disk_reads_completed_total{cluster_id=~".*$tidb_cluster"}[2m]))by(instance)),"name","IOPS Read Max","","")'
    unit: '1'
  - name: 'TiKV_IOPS_Write'
    expr: 'label_replace(max(sum(rate(node_disk_writes_completed_total{cluster_id=~".*$tidb_cluster"}[2m]))by(instance)),"name","IOPS Write Max","","")'
    unit: '1'
# # 7 TiProxy
# - name: ''
#   expr: ''
# - name: ''
#   expr: ''
# - name: ''
#   expr: ''
# - name: ''
#   expr: ''
# # 8 TiFlash
# - name: 'TiFlash_CPU_Max:by_instance'
#   expr: 'label_replace(max(rate(tiflash_proxy_process_cpu_seconds_total{cluster_id=~".*$tidb_cluster",component="tiflash"}[2m]))*100,"name","CPU Max","","")'
#   unit: '%'
# - name: ''
#   expr: ''
# - name: ''
#   expr: ''
# - name: ''
#   expr: ''
