﻿{
  "__inputs": [
    {
      "name": "DS_VICTORIAMETRICS-LOGS-DATASOURCE",
      "label": "victoriametrics-logs-datasource",
      "description": "",
      "type": "datasource",
      "pluginId": "victoriametrics-logs-datasource",
      "pluginName": "VictoriaLogs"
    }
  ],
  "__elements": {},
  "__requires": [
    {
      "type": "grafana",
      "id": "grafana",
      "name": "Grafana",
      "version": "12.1.2"
    },
    {
      "type": "panel",
      "id": "logs",
      "name": "Logs",
      "version": ""
    },
    {
      "type": "panel",
      "id": "table",
      "name": "Table",
      "version": ""
    },
    {
      "type": "panel",
      "id": "text",
      "name": "Text",
      "version": ""
    },
    {
      "type": "panel",
      "id": "timeseries",
      "name": "Time series",
      "version": ""
    },
    {
      "type": "datasource",
      "id": "victoriametrics-logs-datasource",
      "name": "VictoriaLogs",
      "version": "0.23.5"
    }
  ],
  "annotations": {
    "list": [
      {
        "builtIn": 1,
        "datasource": {
          "type": "grafana",
          "uid": "-- Grafana --"
        },
        "enable": true,
        "hide": true,
        "iconColor": "rgba(0, 211, 255, 1)",
        "name": "Annotations & Alerts",
        "type": "dashboard"
      }
    ]
  },
  "editable": true,
  "fiscalYearStartMonth": 0,
  "graphTooltip": 0,
  "id": null,
  "links": [],
  "panels": [
    {
      "gridPos": {
        "h": 8,
        "w": 4,
        "x": 0,
        "y": 0
      },
      "id": 5,
      "options": {
        "code": {
          "language": "plaintext",
          "showLineNumbers": false,
          "showMiniMap": false
        },
        "content": "## 使用说明\n\n### ⚠️ 查询时间范围限制\n- **<span style=\"color:red\">最大查询时间范围为 24h</span>**\n- **<span style=\"color:red\">请勿选择超过 24 小时的时间范围</span>**\n- **<span style=\"color:red\">时间范围越长，加载耗时稍微越长</span>**  \n  （例如：`Last 3 hours`）\n\n### 📊 查询方式建议\n为保证 **趋势清晰** 与 **查询性能稳定**，建议使用以下固定时间窗口或者指定起止时间：\n\n- **<span style=\"color:green\">Last 30minutes</span>**\n- **<span style=\"color:green\">Last 1h</span>**\n- **<span style=\"color:green\">Last 3h</span>**\n- **<span style=\"color:green\">Last 6h</span>**",
        "mode": "markdown"
      },
      "pluginVersion": "12.1.2",
      "type": "text"
    },
    {
      "datasource": {
        "type": "victoriametrics-logs-datasource",
        "uid": "${DS_VICTORIAMETRICS-LOGS-DATASOURCE}"
      },
      "gridPos": {
        "h": 8,
        "w": 20,
        "x": 4,
        "y": 0
      },
      "id": 1,
      "options": {
        "dedupStrategy": "none",
        "enableInfiniteScrolling": false,
        "enableLogDetails": true,
        "prettifyLogMessage": false,
        "showCommonLabels": false,
        "showLabels": false,
        "showTime": true,
        "sortOrder": "Descending",
        "wrapLogMessage": true
      },
      "pluginVersion": "12.1.2",
      "targets": [
        {
          "datasource": {
            "type": "victoriametrics-logs-datasource",
            "uid": "${DS_VICTORIAMETRICS-LOGS-DATASOURCE}"
          },
          "direction": "desc",
          "editorMode": "code",
          "expr": "job:=\"$job\" durationMillis:>$durationThreshold ns:\"$attrNs\"",
          "maxLines": 500,
          "queryType": "instant",
          "refId": "A"
        }
      ],
      "title": "mongodb日志面板（最新500条）",
      "type": "logs"
    },
    {
      "datasource": {
        "type": "victoriametrics-logs-datasource",
        "uid": "${DS_VICTORIAMETRICS-LOGS-DATASOURCE}"
      },
      "description": "按时间桶统计慢查询次数；鼠标悬停显示该时间桶内每个库表(ns)的慢查询次数。总计 表示此时间点慢查询日志总条目",
      "fieldConfig": {
        "defaults": {
          "color": {
            "mode": "palette-classic"
          },
          "custom": {
            "axisBorderShow": false,
            "axisCenteredZero": false,
            "axisColorMode": "text",
            "axisLabel": "",
            "axisPlacement": "auto",
            "barAlignment": 0,
            "barWidthFactor": 0.6,
            "drawStyle": "line",
            "fillOpacity": 10,
            "gradientMode": "none",
            "hideFrom": {
              "legend": false,
              "tooltip": false,
              "viz": false
            },
            "insertNulls": false,
            "lineInterpolation": "linear",
            "lineWidth": 1,
            "pointSize": 5,
            "scaleDistribution": {
              "type": "linear"
            },
            "showPoints": "never",
            "spanNulls": true,
            "stacking": {
              "group": "A",
              "mode": "none"
            },
            "thresholdsStyle": {
              "mode": "off"
            }
          },
          "mappings": [],
          "thresholds": {
            "mode": "absolute",
            "steps": [
              {
                "color": "green",
                "value": 0
              },
              {
                "color": "red",
                "value": 80
              }
            ]
          }
        },
        "overrides": [
          {
            "matcher": {
              "id": "byName",
              "options": "Value"
            },
            "properties": [
              {
                "id": "displayName",
                "value": "${__field.labels.ns}"
              },
              {
                "id": "custom.lineWidth",
                "value": 2
              }
            ]
          },
          {
            "matcher": {
              "id": "byName",
              "options": "total"
            },
            "properties": [
              {
                "id": "displayName",
                "value": "总计"
              }
            ]
          }
        ]
      },
      "gridPos": {
        "h": 11,
        "w": 24,
        "x": 0,
        "y": 8
      },
      "id": 3,
      "interval": "5s",
      "options": {
        "legend": {
          "calcs": [
            "lastNotNull",
            "max"
          ],
          "displayMode": "table",
          "placement": "right",
          "showLegend": true,
          "sortBy": "Max",
          "sortDesc": true
        },
        "tooltip": {
          "hideZeros": false,
          "mode": "multi",
          "sort": "desc"
        }
      },
      "pluginVersion": "12.1.2",
      "targets": [
        {
          "datasource": {
            "type": "victoriametrics-logs-datasource",
            "uid": "${DS_VICTORIAMETRICS-LOGS-DATASOURCE}"
          },
          "editorMode": "code",
          "expr": "job:=\"$job\" durationMillis:>$durationThreshold\r\n| filter ns:~\"^(${attrNs:pipe})$\"\r\n| stats by (_time:$__interval, ns) count() as value_by_ns\r\n",
          "hide": false,
          "queryType": "statsRange",
          "refId": "A"
        },
        {
          "datasource": {
            "type": "victoriametrics-logs-datasource",
            "uid": "${DS_VICTORIAMETRICS-LOGS-DATASOURCE}"
          },
          "editorMode": "code",
          "expr": "job:=\"$job\" durationMillis:>$durationThreshold\r\n| filter ns:~\"^(${attrNs:pipe})$\"\r\n| stats by (_time:$__interval) count() as total\r\n",
          "hide": false,
          "queryType": "statsRange",
          "refId": "B"
        }
      ],
      "title": "慢查询次数趋势（按库表分组）",
      "type": "timeseries"
    },
    {
      "datasource": {
        "type": "victoriametrics-logs-datasource",
        "uid": "${DS_VICTORIAMETRICS-LOGS-DATASOURCE}"
      },
      "description": "sort by durationThreshold (client-side sort). maxLines 已限制，避免1C2G打满。",
      "fieldConfig": {
        "defaults": {
          "color": {
            "mode": "thresholds"
          },
          "custom": {
            "align": "center",
            "cellOptions": {
              "type": "color-text"
            },
            "inspect": true
          },
          "mappings": [],
          "thresholds": {
            "mode": "percentage",
            "steps": [
              {
                "color": "green",
                "value": 0
              },
              {
                "color": "super-light-orange",
                "value": 1000
              }
            ]
          }
        },
        "overrides": [
          {
            "matcher": {
              "id": "byName",
              "options": "库表"
            },
            "properties": [
              {
                "id": "custom.width",
                "value": 362
              }
            ]
          },
          {
            "matcher": {
              "id": "byName",
              "options": "慢查询耗时（单位毫秒）"
            },
            "properties": [
              {
                "id": "mappings",
                "value": [
                  {
                    "options": {
                      "from": 1000,
                      "result": {
                        "color": "semi-dark-yellow",
                        "index": 0
                      },
                      "to": 3000
                    },
                    "type": "range"
                  },
                  {
                    "options": {
                      "from": 3000,
                      "result": {
                        "color": "semi-dark-orange",
                        "index": 1
                      },
                      "to": 5000
                    },
                    "type": "range"
                  },
                  {
                    "options": {
                      "from": 5000,
                      "result": {
                        "color": "semi-dark-red",
                        "index": 2
                      },
                      "to": 10000000
                    },
                    "type": "range"
                  }
                ]
              },
              {
                "id": "custom.width",
                "value": 185
              }
            ]
          },
          {
            "matcher": {
              "id": "byName",
              "options": "原始命令内容"
            },
            "properties": [
              {
                "id": "custom.cellOptions",
                "value": {
                  "type": "json-view"
                }
              },
              {
                "id": "custom.width",
                "value": 400
              }
            ]
          },
          {
            "matcher": {
              "id": "byName",
              "options": "查询执行方式"
            },
            "properties": [
              {
                "id": "custom.width",
                "value": 300
              }
            ]
          },
          {
            "matcher": {
              "id": "byName",
              "options": "总条数"
            },
            "properties": [
              {
                "id": "custom.width",
                "value": 152
              }
            ]
          },
          {
            "matcher": {
              "id": "byName",
              "options": "时间"
            },
            "properties": [
              {
                "id": "thresholds",
                "value": {
                  "mode": "absolute",
                  "steps": [
                    {
                      "color": "green",
                      "value": 0
                    }
                  ]
                }
              },
              {
                "id": "custom.width",
                "value": 166
              }
            ]
          },
          {
            "matcher": {
              "id": "byName",
              "options": "库表"
            },
            "properties": [
              {
                "id": "custom.width",
                "value": 319
              }
            ]
          },
          {
            "matcher": {
              "id": "byName",
              "options": "慢查询耗时（单位毫秒）"
            },
            "properties": [
              {
                "id": "custom.width",
                "value": 200
              }
            ]
          }
        ]
      },
      "gridPos": {
        "h": 11,
        "w": 24,
        "x": 0,
        "y": 19
      },
      "id": 2,
      "options": {
        "cellHeight": "sm",
        "footer": {
          "countRows": false,
          "enablePagination": true,
          "fields": "",
          "reducer": [
            "sum"
          ],
          "show": false
        },
        "showHeader": true,
        "sortBy": []
      },
      "pluginVersion": "12.1.2",
      "targets": [
        {
          "datasource": {
            "type": "victoriametrics-logs-datasource",
            "uid": "${DS_VICTORIAMETRICS-LOGS-DATASOURCE}"
          },
          "editorMode": "code",
          "expr": "job:=\"$job\" durationMillis:>$durationThreshold ns:\"$attrNs\"",
          "maxLines": 500,
          "queryType": "instant",
          "refId": "A"
        }
      ],
      "title": "慢查询明细（最多500条，按耗时客户端排序）",
      "transformations": [
        {
          "id": "organize",
          "options": {
            "excludeByName": {
              "Line": true,
              "detected_level": true
            },
            "includeByName": {},
            "indexByName": {},
            "orderByMode": "manual",
            "renameByName": {
              "Line": "",
              "Time": "",
              "labels": ""
            }
          }
        },
        {
          "id": "extractFields",
          "options": {
            "delimiter": ",",
            "source": "labels"
          }
        },
        {
          "id": "filterFieldsByName",
          "options": {
            "byVariable": false,
            "include": {
              "pattern": "^Time$|^durationMillis$|^ns$|^planSummary$|^reslen$|^docsExamined$|^attr$"
            }
          }
        },
        {
          "id": "organize",
          "options": {
            "excludeByName": {},
            "includeByName": {},
            "indexByName": {
              "Time": 0,
              "attr": 3,
              "docsExamined": 5,
              "durationMillis": 2,
              "ns": 1,
              "planSummary": 4,
              "reslen": 6
            },
            "renameByName": {
              "Time": "时间",
              "attr": "原始命令内容",
              "command": "原始命令内容",
              "docsExamined": "总条数",
              "durationMillis": "慢查询耗时（单位毫秒）",
              "ns": "库表",
              "planSummary": "查询执行方式",
              "reslen": "查询响应数"
            }
          }
        },
        {
          "id": "convertFieldType",
          "options": {
            "conversions": [
              {
                "destinationType": "number",
                "targetField": "慢查询耗时（单位毫秒）"
              }
            ],
            "fields": {}
          }
        },
        {
          "id": "sortBy",
          "options": {
            "fields": {},
            "sort": [
              {
                "desc": true,
                "field": "慢查询耗时（单位毫秒）"
              }
            ]
          }
        }
      ],
      "type": "table"
    },
    {
      "datasource": {
        "type": "victoriametrics-logs-datasource",
        "uid": "${DS_VICTORIAMETRICS-LOGS-DATASOURCE}"
      },
      "description": "24h内统计推荐用这个面板（聚合后排序，资源占用小）。",
      "fieldConfig": {
        "defaults": {
          "color": {
            "mode": "thresholds"
          },
          "custom": {
            "align": "center",
            "cellOptions": {
              "type": "color-text"
            },
            "inspect": true
          },
          "mappings": [],
          "thresholds": {
            "mode": "percentage",
            "steps": [
              {
                "color": "green",
                "value": 0
              }
            ]
          }
        },
        "overrides": [
          {
            "matcher": {
              "id": "byName",
              "options": "最大慢查询耗时（毫秒）"
            },
            "properties": [
              {
                "id": "mappings",
                "value": [
                  {
                    "options": {
                      "from": 1000,
                      "result": {
                        "color": "semi-dark-yellow",
                        "index": 0
                      },
                      "to": 3000
                    },
                    "type": "range"
                  },
                  {
                    "options": {
                      "from": 3000,
                      "result": {
                        "color": "semi-dark-orange",
                        "index": 1
                      },
                      "to": 5000
                    },
                    "type": "range"
                  },
                  {
                    "options": {
                      "from": 5000,
                      "result": {
                        "color": "semi-dark-red",
                        "index": 2
                      },
                      "to": 10000000
                    },
                    "type": "range"
                  }
                ]
              }
            ]
          },
          {
            "matcher": {
              "id": "byName",
              "options": "时间"
            },
            "properties": [
              {
                "id": "thresholds",
                "value": {
                  "mode": "absolute",
                  "steps": [
                    {
                      "color": "green",
                      "value": 0
                    }
                  ]
                }
              },
              {
                "id": "custom.width",
                "value": 199
              }
            ]
          },
          {
            "matcher": {
              "id": "byName",
              "options": "最小慢查询耗时（毫秒）"
            },
            "properties": [
              {
                "id": "mappings",
                "value": [
                  {
                    "options": {
                      "from": 1000,
                      "result": {
                        "color": "semi-dark-yellow",
                        "index": 0
                      },
                      "to": 3000
                    },
                    "type": "range"
                  },
                  {
                    "options": {
                      "from": 3000,
                      "result": {
                        "color": "semi-dark-orange",
                        "index": 1
                      },
                      "to": 5000
                    },
                    "type": "range"
                  },
                  {
                    "options": {
                      "from": 5000,
                      "result": {
                        "color": "semi-dark-red",
                        "index": 2
                      },
                      "to": 10000000
                    },
                    "type": "range"
                  }
                ]
              },
              {
                "id": "custom.width",
                "value": 200
              }
            ]
          },
          {
            "matcher": {
              "id": "byName",
              "options": "出现频次"
            },
            "properties": [
              {
                "id": "mappings",
                "value": [
                  {
                    "options": {
                      "from": 0,
                      "result": {
                        "color": "green",
                        "index": 0
                      },
                      "to": 20
                    },
                    "type": "range"
                  },
                  {
                    "options": {
                      "from": 20,
                      "result": {
                        "color": "yellow",
                        "index": 1
                      },
                      "to": 50
                    },
                    "type": "range"
                  },
                  {
                    "options": {
                      "from": 50,
                      "result": {
                        "color": "red",
                        "index": 2
                      },
                      "to": 10000000
                    },
                    "type": "range"
                  }
                ]
              }
            ]
          }
        ]
      },
      "gridPos": {
        "h": 11,
        "w": 24,
        "x": 0,
        "y": 30
      },
      "id": 4,
      "options": {
        "cellHeight": "sm",
        "footer": {
          "countRows": false,
          "enablePagination": true,
          "fields": "",
          "reducer": [
            "sum"
          ],
          "show": false
        },
        "showHeader": true,
        "sortBy": []
      },
      "pluginVersion": "12.1.2",
      "targets": [
        {
          "datasource": {
            "type": "victoriametrics-logs-datasource",
            "uid": "${DS_VICTORIAMETRICS-LOGS-DATASOURCE}"
          },
          "editorMode": "code",
          "expr": "job:=\"$job\" ns:\"$attrNs\" durationMillis:>$durationThreshold\n| stats by (ns) \n    count() as slow_cnt,\n    max(durationMillis) as max_ms,\n    min(durationMillis) as min_ms\n| sort by (slow_cnt) desc",
          "hide": false,
          "maxLines": 500,
          "queryType": "instant",
          "refId": "A"
        }
      ],
      "title": "慢查询统计（最多500条）",
      "transformations": [
        {
          "id": "organize",
          "options": {
            "excludeByName": {
              "Line": false,
              "detected_level": true,
              "labels": true
            },
            "includeByName": {},
            "indexByName": {},
            "renameByName": {}
          }
        },
        {
          "id": "extractFields",
          "options": {
            "delimiter": ",",
            "source": "Line"
          }
        },
        {
          "id": "organize",
          "options": {
            "excludeByName": {
              "Line": true
            },
            "includeByName": {},
            "indexByName": {
              "Line": 1,
              "Time": 0,
              "max_ms": 4,
              "min_ms": 5,
              "ns": 2,
              "slow_cnt": 3
            },
            "renameByName": {
              "Line": "",
              "Time": "时间",
              "max_ms": "最大慢查询耗时（毫秒）",
              "min_ms": "最小慢查询耗时（毫秒）",
              "ns": "库表",
              "slow_cnt": "出现频次"
            }
          }
        },
        {
          "id": "convertFieldType",
          "options": {
            "conversions": [
              {
                "destinationType": "number",
                "targetField": "出现频次"
              }
            ],
            "fields": {}
          }
        },
        {
          "id": "sortBy",
          "options": {
            "fields": {},
            "sort": [
              {
                "desc": true,
                "field": "出现频次"
              }
            ]
          }
        }
      ],
      "type": "table"
    }
  ],
  "refresh": "10m",
  "schemaVersion": 41,
  "tags": [
    "hap-monitor"
  ],
  "templating": {
    "list": [
      {
        "allowCustomValue": false,
        "current": {},
        "datasource": {
          "type": "victoriametrics-logs-datasource",
          "uid": "${DS_VICTORIAMETRICS-LOGS-DATASOURCE}"
        },
        "definition": "",
        "label": "节点",
        "name": "job",
        "options": [],
        "query": {
          "field": "job",
          "limit": 100,
          "query": "",
          "refId": "VictoriaLogsVariableQueryEditor-VariableQuery",
          "type": "fieldValue"
        },
        "refresh": 1,
        "regex": "",
        "type": "query"
      },
      {
        "allowCustomValue": true,
        "current": {
          "text": "1000",
          "value": "1000"
        },
        "description": "耗时单位毫秒，默认1000ms",
        "label": "慢查询耗时",
        "name": "durationThreshold",
        "options": [
          {
            "selected": true,
            "text": "1000",
            "value": "1000"
          }
        ],
        "query": "1000",
        "type": "custom"
      },
      {
        "allowCustomValue": true,
        "current": {},
        "datasource": {
          "type": "victoriametrics-logs-datasource",
          "uid": "${DS_VICTORIAMETRICS-LOGS-DATASOURCE}"
        },
        "definition": "",
        "description": "例如：mddatapipeline.task_usage_202601（All=空表示不过滤ns），只展示最多40个，请输入指定值查询",
        "includeAll": true,
        "label": "库表",
        "name": "attrNs",
        "options": [],
        "query": {
          "field": "ns",
          "limit": 40,
          "query": "",
          "refId": "VictoriaLogsVariableQueryEditor-VariableQuery",
          "type": "fieldValue"
        },
        "refresh": 1,
        "regex": "",
        "type": "query"
      }
    ]
  },
  "time": {
    "from": "now-30m",
    "to": "now"
  },
  "timepicker": {
    "refresh_intervals": [
      "30s",
      "1m",
      "2m",
      "5m",
      "10m",
      "15m",
      "30m",
      "1h"
    ]
  },
  "timezone": "browser",
  "title": "mongodb-VictoriaLogs慢查询展示面板",
  "uid": "hap-mongodb-victorialogs",
  "version": 1,
  "weekStart": ""
}