{
  "annotations": {
    "list": [
      {
        "builtIn": 1,
        "datasource": "-- Grafana --",
        "enable": true,
        "hide": true,
        "iconColor": "rgba(0, 211, 255, 1)",
        "name": "Annotations & Alerts",
        "target": {
          "limit": 100,
          "matchAny": false,
          "tags": [],
          "type": "dashboard"
        },
        "type": "dashboard"
      },
      {
        "datasource": "Infinity",
        "enable": true,
        "iconColor": "blue",
        "name": "anomaly",
        "target": {
          "columns": [],
          "filters": [],
          "format": "dataframe",
          "global_query_id": "",
          "limit": 100,
          "matchAny": false,
          "refId": "",
          "root_selector": "",
          "source": "url",
          "tags": [],
          "type": "json",
          "url": "__CLINIC_ADDR__/clinic/api/v1/diagnosis/annotations",
          "url_options": {
            "data": "",
            "method": "GET",
            "params": [
              {
                "key": "start_ts",
                "value": "${__from:date:seconds}"
              },
              {
                "key": "end_ts",
                "value": "${__to:date:seconds}"
              },
              {
                "key": "tidb_cluster",
                "value": "${tidb_cluster}"
              },
              {
                "key": "measurement",
                "value": "avg_latency_analysis_anno"
              }
            ]
          }
        },
        "type": "dashboard"
      }
    ]
  },
  "editable": true,
  "fiscalYearStartMonth": 0,
  "graphTooltip": 1,
  "id": 12,
  "iteration": 1647506321584,
  "links": [],
  "liveNow": false,
  "panels": [
    {
      "collapsed": false,
      "gridPos": {
        "h": 1,
        "w": 24,
        "x": 0,
        "y": 0
      },
      "id": 72,
      "panels": [],
      "title": "Compile Duration",
      "type": "row"
    },
    {
      "datasource": "Infinity",
      "gridPos": {
        "h": 8,
        "w": 24,
        "x": 0,
        "y": 1
      },
      "id": 86,
      "options": {
        "content": "{{#if (eq total_latency_good 0)}}\n{{#if (eq time_1 1)}}\n\n从 {{time_1_start_unix_rfc3339}} 到 {{time_1_end_unix_rfc3339}} 时间范围内：\n\n{{#if (eq cps_prop_good_time_1 0)}}\n\n应用可能未使用 Prepare Statement 功能，建议排查确认，打开相应功能对优化 Compile Duration 有帮助。\n\n{{/if}}\n\n{{#if (eq cps_prop_good_time_1 1)}}\n\n{{#if (eq plan_cache_prop_time_1 0)}}\n\nTiDB 可能未开启 Plan Cache 功能，建议排查确认，打开相应功能对优化 Compile Duration 有帮助。\n\n{{/if}}\n\n{{#if (eq plan_cache_prop_time_1 1)}}\n\n应用侧的 SQL 写法可能导致 Plan Cache 命中率不高，建议结合 Slow query 等工具进一步检查。\n\n{{/if}}\n{{/if}}\n\n(以上为异常项，如上述无异常则空白)\n\n{{/if}}\n\n{{#if (eq time_2 1)}}\n\n从 {{time_2_start_unix_rfc3339}} 到 {{time_2_end_unix_rfc3339}} 时间范围内：\n\n{{#if (eq cps_prop_good_time_2 0)}}\n\n应用可能未使用 Prepare Statement 功能，建议排查确认，打开相应功能对优化 Compile Duration 有帮助。\n\n{{/if}}\n\n{{#if (eq cps_prop_good_time_2 1)}}\n\n{{#if (eq plan_cache_prop_time_2 0)}}\n\nTiDB 可能未开启 Plan Cache 功能，建议排查确认，打开相应功能对优化 Compile Duration 有帮助。\n\n{{/if}}\n\n{{#if (eq plan_cache_prop_time_2 1)}}\n\n应用侧的 SQL 写法可能导致 Plan Cache 命中率不高，建议结合 Slow query 等工具进一步检查。\n\n{{/if}}\n{{/if}}\n\n(以上为异常项，如上述无异常则空白)\n\n{{/if}}\n\n{{#if (eq time_3 1)}}\n\n从 {{time_3_start_unix_rfc3339}} 到 {{time_3_end_unix_rfc3339}} 时间范围内：\n\n{{#if (eq cps_prop_good_time_3 0)}}\n\n应用可能未使用 Prepare Statement 功能，建议排查确认，打开相应功能对优化 Compile Duration 有帮助。\n\n{{/if}}\n\n{{#if (eq cps_prop_good_time_3 1)}}\n\n{{#if (eq plan_cache_prop_time_3 0)}}\n\nTiDB 可能未开启 Plan Cache 功能，建议排查确认，打开相应功能对优化 Compile Duration 有帮助。\n\n{{/if}}\n\n{{#if (eq plan_cache_prop_time_3 1)}}\n\n应用侧的 SQL 写法可能导致 Plan Cache 命中率不高，建议结合 Slow query 等工具进一步检查。\n\n{{/if}}\n{{/if}}\n\n(以上为异常项，如上述无异常则空白)\n\n{{/if}}\n{{/if}}",
        "defaultContent": "The query didn't return any results.",
        "everyRow": true
      },
      "targets": [
        {
          "columns": [],
          "data": "__CLINIC_ADDR__/clinic/api/v1/diagnosis/dynamic_text_value",
          "datasource": "Infinity",
          "filters": [],
          "format": "dataframe",
          "global_query_id": "",
          "refId": "A",
          "root_selector": "",
          "source": "url",
          "type": "json",
          "url": "__CLINIC_ADDR__/clinic/api/v1/diagnosis/dynamic_text_value",
          "url_options": {
            "data": "",
            "method": "GET",
            "params": [
              {
                "key": "measurement",
                "value": "avg_latency_analysis_dt"
              },
              {
                "key": "start_ts",
                "value": "${__from:date:seconds}"
              },
              {
                "key": "end_ts",
                "value": "${__to:date:seconds}"
              },
              {
                "key": "tidb_cluster",
                "value": "${tidb_cluster}"
              },
              {
                "key": "default_1",
                "value": "total_latency_good"
              }
            ]
          }
        }
      ],
      "title": "基于平均延迟性能的自动化诊断报告",
      "type": "marcusolsson-dynamictext-panel"
    },
    {
      "datasource": "Prometheus",
      "fieldConfig": {
        "defaults": {
          "color": {
            "mode": "palette-classic"
          },
          "custom": {
            "axisLabel": "",
            "axisPlacement": "auto",
            "barAlignment": 0,
            "drawStyle": "line",
            "fillOpacity": 0,
            "gradientMode": "none",
            "hideFrom": {
              "legend": false,
              "tooltip": false,
              "viz": false
            },
            "lineInterpolation": "linear",
            "lineWidth": 1,
            "pointSize": 5,
            "scaleDistribution": {
              "type": "linear"
            },
            "showPoints": "auto",
            "spanNulls": false,
            "stacking": {
              "group": "A",
              "mode": "none"
            },
            "thresholdsStyle": {
              "mode": "off"
            }
          },
          "mappings": [],
          "thresholds": {
            "mode": "absolute",
            "steps": [
              {
                "color": "green",
                "value": null
              },
              {
                "color": "red",
                "value": 80
              }
            ]
          },
          "unit": "s"
        },
        "overrides": []
      },
      "gridPos": {
        "h": 8,
        "w": 12,
        "x": 0,
        "y": 9
      },
      "id": 34,
      "options": {
        "legend": {
          "calcs": [],
          "displayMode": "list",
          "placement": "bottom"
        },
        "tooltip": {
          "mode": "single"
        }
      },
      "targets": [
        {
          "datasource": "Prometheus",
          "exemplar": false,
          "expr": "(sum(rate(tidb_session_compile_duration_seconds_sum{tidb_cluster=\"$tidb_cluster\", sql_type=\"general\"}[1m])) / sum(rate(tidb_session_compile_duration_seconds_count{tidb_cluster=\"$tidb_cluster\", sql_type=\"general\"}[1m])))",
          "interval": "",
          "legendFormat": "avg",
          "refId": "A"
        }
      ],
      "title": "Compile duration",
      "type": "timeseries"
    },
    {
      "datasource": "Prometheus",
      "fieldConfig": {
        "defaults": {
          "color": {
            "mode": "palette-classic"
          },
          "custom": {
            "axisLabel": "",
            "axisPlacement": "auto",
            "barAlignment": 0,
            "drawStyle": "line",
            "fillOpacity": 0,
            "gradientMode": "none",
            "hideFrom": {
              "legend": false,
              "tooltip": false,
              "viz": false
            },
            "lineInterpolation": "linear",
            "lineWidth": 1,
            "pointSize": 5,
            "scaleDistribution": {
              "type": "linear"
            },
            "showPoints": "auto",
            "spanNulls": false,
            "stacking": {
              "group": "A",
              "mode": "none"
            },
            "thresholdsStyle": {
              "mode": "off"
            }
          },
          "mappings": [],
          "thresholds": {
            "mode": "absolute",
            "steps": [
              {
                "color": "green",
                "value": null
              },
              {
                "color": "red",
                "value": 80
              }
            ]
          }
        },
        "overrides": []
      },
      "gridPos": {
        "h": 8,
        "w": 12,
        "x": 12,
        "y": 9
      },
      "id": 111,
      "options": {
        "legend": {
          "calcs": [],
          "displayMode": "list",
          "placement": "bottom"
        },
        "tooltip": {
          "mode": "single"
        }
      },
      "targets": [
        {
          "datasource": "Prometheus",
          "exemplar": false,
          "expr": "sum(rate(tidb_server_plan_cache_total{tidb_cluster=\"$tidb_cluster\"}[1m]))",
          "interval": "",
          "legendFormat": "Plan-cache-ops",
          "refId": "A"
        },
        {
          "datasource": "Prometheus",
          "exemplar": false,
          "expr": "sum(rate(tidb_server_query_total{tidb_cluster=\"$tidb_cluster\", type=\"StmtExecute\"}[1m]))",
          "hide": false,
          "interval": "",
          "legendFormat": "StmtExecute",
          "refId": "B"
        }
      ],
      "title": "Plan cache v.s. StmtExecute",
      "type": "timeseries"
    },
    {
      "datasource": "Prometheus",
      "fieldConfig": {
        "defaults": {
          "color": {
            "mode": "palette-classic"
          },
          "custom": {
            "axisLabel": "",
            "axisPlacement": "auto",
            "barAlignment": 0,
            "drawStyle": "line",
            "fillOpacity": 0,
            "gradientMode": "none",
            "hideFrom": {
              "legend": false,
              "tooltip": false,
              "viz": false
            },
            "lineInterpolation": "linear",
            "lineWidth": 1,
            "pointSize": 5,
            "scaleDistribution": {
              "type": "linear"
            },
            "showPoints": "auto",
            "spanNulls": false,
            "stacking": {
              "group": "A",
              "mode": "none"
            },
            "thresholdsStyle": {
              "mode": "off"
            }
          },
          "mappings": [],
          "thresholds": {
            "mode": "absolute",
            "steps": [
              {
                "color": "green",
                "value": null
              },
              {
                "color": "red",
                "value": 80
              }
            ]
          }
        },
        "overrides": []
      },
      "gridPos": {
        "h": 8,
        "w": 12,
        "x": 0,
        "y": 17
      },
      "id": 108,
      "options": {
        "legend": {
          "calcs": [],
          "displayMode": "list",
          "placement": "bottom"
        },
        "tooltip": {
          "mode": "single"
        }
      },
      "targets": [
        {
          "datasource": "Prometheus",
          "exemplar": false,
          "expr": "sum(rate(tidb_server_query_total{tidb_cluster=\"$tidb_cluster\"}[1m]))",
          "interval": "",
          "legendFormat": "CPS-total",
          "refId": "A"
        },
        {
          "datasource": "Prometheus",
          "exemplar": false,
          "expr": "sum(rate(tidb_server_query_total{tidb_cluster=\"$tidb_cluster\", type=\"StmtExecute\"}[1m]))",
          "hide": false,
          "interval": "",
          "legendFormat": "StmtExecute",
          "refId": "B"
        }
      ],
      "title": "CPS v.s. StmtExecute",
      "type": "timeseries"
    }
  ],
  "refresh": false,
  "schemaVersion": 34,
  "style": "dark",
  "tags": [],
  "templating": {
    "list": [
      {
        "datasource": "Prometheus-fake",
        "definition": "",
        "hide": 0,
        "includeAll": false,
        "label": "tidb_cluster",
        "multi": false,
        "name": "tidb_cluster",
        "options": [],
        "query": {
          "query": "label_values({job=\"pd\"},tidb_cluster)",
          "refId": "StandardVariableQuery"
        },
        "refresh": 2,
        "regex": "",
        "skipUrlSync": false,
        "sort": 0,
        "type": "query"
      },
      {
        "allValue": ".*",
        "current": {
          "selected": true,
          "text": [
            "All"
          ],
          "value": [
            "$__all"
          ]
        },
        "datasource": "Prometheus",
        "definition": "",
        "hide": 0,
        "includeAll": true,
        "label": "instance",
        "multi": true,
        "name": "instance",
        "options": [],
        "query": {
          "query": "label_values(pd_cluster_status{tidb_cluster=\"$tidb_cluster\"}, instance)",
          "refId": "StandardVariableQuery"
        },
        "refresh": 1,
        "regex": "",
        "skipUrlSync": false,
        "sort": 0,
        "type": "query"
      }
    ]
  },
  "time": {
    "from": "now-6h",
    "to": "now"
  },
  "timepicker": {},
  "timezone": "",
  "title": "Sub - Compile Duration",
  "uid": "rXMpi9Y7k",
  "version": 8,
  "weekStart": ""
}
