Grafana : выявление проблем у сервисов

Какие запросы самые тормозные

quantile_over_time(
  0.95,
  {hostname=~".+", service_name =~ "(.+)-be-([0-9].+)"}
  | json request_time, request_uri_wo_query_string
  | __error__=""
  | request_time != ``
  | keep request_time, request_uri_wo_query_string
  | unwrap request_time
  | __error__=""
  [$__auto]
)
{
  "id": 12,
  "type": "table",
  "title": "95 Percentile по запросам",
  "gridPos": {
    "x": 0,
    "y": 60,
    "h": 8,
    "w": 12
  },
  "fieldConfig": {
    "defaults": {
      "custom": {
        "align": "auto",
        "footer": {
          "reducers": []
        },
        "cellOptions": {
          "type": "auto"
        },
        "inspect": false
      },
      "mappings": [],
      "thresholds": {
        "mode": "absolute",
        "steps": [
          {
            "color": "green",
            "value": null
          },
          {
            "color": "red",
            "value": 80
          }
        ]
      },
      "color": {
        "mode": "thresholds"
      },
      "unit": "none"
    },
    "overrides": [
      {
        "matcher": {
          "id": "byName",
          "options": "Requests"
        },
        "properties": [
          {
            "id": "custom.width",
            "value": 153
          }
        ]
      }
    ]
  },
  "transformations": [
    {
      "id": "organize",
      "options": {
        "excludeByName": {
          "Time": true
        },
        "includeByName": {},
        "indexByName": {},
        "renameByName": {
          "Value #A": "p95"
        }
      }
    }
  ],
  "pluginVersion": "12.3.0",
  "targets": [
    {
      "datasource": {
        "type": "loki",
        "uid": "bf64dm2w8rvggc"
      },
      "direction": "backward",
      "editorMode": "code",
      "expr": "quantile_over_time(\n  0.95,\n  {hostname=~\".+\", service_name =~ \"(.+)-be-([0-9].+)\"}\n  | json request_time, request_uri_wo_query_string\n  | __error__=\"\"\n  | request_time != ``\n  | keep request_time, request_uri_wo_query_string\n  | unwrap request_time\n  | __error__=\"\"\n  [$__auto]\n)",
      "legendFormat": "",
      "queryType": "instant",
      "refId": "A"
    }
  ],
  "datasource": {
    "type": "loki",
    "uid": "bf64dm2w8rvggc"
  },
  "options": {
    "showHeader": true,
    "cellHeight": "sm",
    "sortBy": [
      {
        "desc": true,
        "displayName": "p95"
      }
    ]
  }
}

Какие запросы стоит оптимизировать в первую очередь

sum by (request_uri_wo_query_string) (
  count_over_time(
    {hostname=~".+", service_name=~"(.+)-be-([0-9].+)"} 
    | json 
    | __error__=""
    | request_uri_wo_query_string =~ ".+"
  [$__auto])
)
{
  "id": 10,
  "type": "table",
  "title": "95 персентиль по запросам + кол-во запросов",
  "gridPos": {
    "x": 12,
    "y": 60,
    "h": 8,
    "w": 12
  },
  "fieldConfig": {
    "defaults": {
      "custom": {
        "align": "auto",
        "footer": {
          "reducers": []
        },
        "cellOptions": {
          "type": "auto"
        },
        "inspect": false
      },
      "mappings": [],
      "thresholds": {
        "mode": "absolute",
        "steps": [
          {
            "color": "green",
            "value": null
          },
          {
            "color": "red",
            "value": 80
          }
        ]
      },
      "color": {
        "mode": "thresholds"
      },
      "unit": "none"
    },
    "overrides": [
      {
        "matcher": {
          "id": "byName",
          "options": "requests"
        },
        "properties": []
      },
      {
        "matcher": {
          "id": "byName",
          "options": "p95"
        },
        "properties": []
      }
    ]
  },
  "transformations": [
    {
      "id": "joinByField",
      "options": {
        "byField": "request_uri_wo_query_string",
        "mode": "outer"
      }
    },
    {
      "id": "organize",
      "options": {
        "excludeByName": {
          "Time 1": true,
          "Time 2": true
        },
        "includeByName": {},
        "indexByName": {
          "Time 1": 3,
          "Time 2": 0,
          "Value #A": 4,
          "Value #B": 2,
          "request_uri_wo_query_string": 1
        },
        "renameByName": {
          "Time 1": "Дата времени выполнения запроса для отображения данных",
          "Time 2": "Дата времени выполнения запроса для отображения данных",
          "Value #A": "requests",
          "Value #B": "p95"
        }
      }
    },
    {
      "id": "calculateField",
      "options": {
        "binary": {
          "left": {
            "matcher": {
              "id": "byName",
              "options": "p95"
            }
          },
          "operator": "*",
          "right": {
            "matcher": {
              "id": "byName",
              "options": "requests"
            }
          }
        },
        "mode": "binary",
        "reduce": {
          "reducer": "sum"
        },
        "replaceFields": false
      }
    }
  ],
  "pluginVersion": "12.3.0",
  "targets": [
    {
      "datasource": {
        "type": "loki",
        "uid": "bf64dm2w8rvggc"
      },
      "direction": "backward",
      "editorMode": "code",
      "expr": "sum by (request_uri_wo_query_string) (\n  count_over_time(\n    {hostname=~\".+\", service_name=~\"(.+)-be-([0-9].+)\"} \n    | json \n    | __error__=\"\"\n    | request_uri_wo_query_string =~ \".+\"\n  [$__auto])\n)",
      "legendFormat": "request_uri_wo_query_string",
      "queryType": "instant",
      "refId": "A"
    },
    {
      "datasource": {
        "type": "loki",
        "uid": "bf64dm2w8rvggc"
      },
      "direction": "backward",
      "editorMode": "code",
      "expr": "quantile_over_time(0.95, \n  {hostname=~\".+\", service_name=~\"(.+)-be-([0-9].+)\"} \n  | json \n  | __error__=\"\"\n  | unwrap request_time\n  [$__auto]\n) by (request_uri_wo_query_string)\n",
      "hide": false,
      "legendFormat": "p95",
      "queryType": "instant",
      "refId": "B"
    }
  ],
  "datasource": {
    "type": "loki",
    "uid": "bf64dm2w8rvggc"
  },
  "options": {
    "showHeader": true,
    "cellHeight": "sm",
    "sortBy": [
      {
        "desc": true,
        "displayName": "p95 * requests"
      }
    ]
  }
}

Ошибки json и не json

(sum(count_over_time({hostname=~".+", service_name =~ "(.+)-be-([0-9].+)"} | json | level > 200 [$__auto])) or vector(0)) + (sum(count_over_time({hostname=~".+", service_name =~ "(.+)-be-([0-9].+)"} |= "[error]" [$__auto])) or vector(0))
{
  "id": 15,
  "type": "timeseries",
  "title": "App error logs",
  "gridPos": {
    "x": 0,
    "y": 32,
    "h": 7,
    "w": 24
  },
  "fieldConfig": {
    "defaults": {
      "custom": {
        "drawStyle": "bars",
        "lineInterpolation": "linear",
        "barAlignment": 0,
        "barWidthFactor": 0.6,
        "lineWidth": 1,
        "fillOpacity": 0,
        "gradientMode": "none",
        "spanNulls": false,
        "insertNulls": false,
        "showPoints": "never",
        "showValues": false,
        "pointSize": 5,
        "stacking": {
          "mode": "none",
          "group": "A"
        },
        "axisPlacement": "auto",
        "axisLabel": "",
        "axisColorMode": "text",
        "axisBorderShow": false,
        "scaleDistribution": {
          "type": "linear"
        },
        "axisCenteredZero": false,
        "hideFrom": {
          "tooltip": false,
          "viz": false,
          "legend": false
        },
        "thresholdsStyle": {
          "mode": "off"
        }
      },
      "color": {
        "mode": "palette-classic"
      },
      "mappings": [],
      "thresholds": {
        "mode": "absolute",
        "steps": [
          {
            "color": "green",
            "value": null
          },
          {
            "color": "red",
            "value": 80
          }
        ]
      }
    },
    "overrides": []
  },
  "pluginVersion": "12.3.0",
  "targets": [
    {
      "datasource": {
        "type": "loki",
        "uid": "bf64dm2w8rvggc"
      },
      "direction": "backward",
      "editorMode": "code",
      "expr": "(sum(count_over_time({hostname=~\".+\", service_name =~ \"(.+)-be-([0-9].+)\"} | json | level > 200 [$__auto])) or vector(0)) + (sum(count_over_time({hostname=~\".+\", service_name =~ \"(.+)-be-([0-9].+)\"} |= \"[error]\" [$__auto])) or vector(0))",
      "hide": false,
      "legendFormat": "generally",
      "queryType": "range",
      "refId": "B"
    },
    {
      "datasource": {
        "type": "loki",
        "uid": "bf64dm2w8rvggc"
      },
      "direction": "backward",
      "editorMode": "code",
      "expr": "(sum(count_over_time({hostname=~\".+\", service_name=~\"mas-be-([0-9].+)\"} | json | level > 200 [$__auto])) or vector(0)) + (sum(count_over_time({hostname=~\".+\", service_name=~\"mas-be-([0-9].+)\"} |= \"[error]\" [$__auto])) or vector(0))",
      "hide": false,
      "legendFormat": "mas-be",
      "queryType": "range",
      "refId": "C"
    },
    {
      "datasource": {
        "type": "loki",
        "uid": "bf64dm2w8rvggc"
      },
      "direction": "backward",
      "editorMode": "code",
      "expr": "(sum(count_over_time({hostname=~\".+\", service_name=~\"pas-be-([0-9].+)\"} | json | level > 200 [$__auto])) or vector(0)) + (sum(count_over_time({hostname=~\".+\", service_name=~\"pas-be-([0-9].+)\"} |= \"[error]\" [$__auto])) or vector(0))",
      "hide": false,
      "legendFormat": "pas-be",
      "queryType": "range",
      "refId": "A"
    },
    {
      "datasource": {
        "type": "loki",
        "uid": "bf64dm2w8rvggc"
      },
      "direction": "backward",
      "editorMode": "code",
      "expr": "(sum(count_over_time({hostname=~\".+\", service_name=~\"stm-be-([0-9].+)\"} | json | level > 200 [$__auto])) or vector(0)) + (sum(count_over_time({hostname=~\".+\", service_name=~\"stm-be-([0-9].+)\"} |= \"[error]\" [$__auto])) or vector(0))",
      "hide": false,
      "legendFormat": "stm-be",
      "queryType": "range",
      "refId": "D"
    },
    {
      "datasource": {
        "type": "loki",
        "uid": "bf64dm2w8rvggc"
      },
      "direction": "backward",
      "editorMode": "code",
      "expr": "(sum(count_over_time({hostname=~\".+\", service_name=~\"scb-be-([0-9].+)\"} | json | level > 200 [$__auto])) or vector(0)) + (sum(count_over_time({hostname=~\".+\", service_name=~\"scb-be-([0-9].+)\"} |= \"[error]\" [$__auto])) or vector(0))",
      "hide": false,
      "legendFormat": "scb-be",
      "queryType": "range",
      "refId": "E"
    }
  ],
  "datasource": {
    "type": "loki",
    "uid": "bf64dm2w8rvggc"
  },
  "interval": "1s",
  "options": {
    "tooltip": {
      "mode": "multi",
      "sort": "none",
      "hideZeros": false
    },
    "legend": {
      "showLegend": true,
      "displayMode": "list",
      "placement": "bottom",
      "calcs": [
        "max"
      ],
      "sortBy": "Max",
      "sortDesc": true
    }
  }
}

Top app errors

topk(100, sum by (message,level_name) (count_over_time({hostname=~".+", service_name=~`(.+)-be-([0-9].+)`} | json | message=~".+" | level_name=~".+"  [$__auto])))
{
  "id": 13,
  "type": "table",
  "title": "Top app errors",
  "gridPos": {
    "x": 0,
    "y": 39,
    "h": 7,
    "w": 24
  },
  "fieldConfig": {
    "defaults": {
      "custom": {
        "align": "auto",
        "footer": {
          "reducers": []
        },
        "cellOptions": {
          "type": "auto"
        },
        "inspect": false
      },
      "mappings": [],
      "thresholds": {
        "mode": "absolute",
        "steps": [
          {
            "color": "green",
            "value": null
          },
          {
            "color": "red",
            "value": 80
          }
        ]
      },
      "color": {
        "mode": "thresholds"
      },
      "unit": "none"
    },
    "overrides": [
      {
        "matcher": {
          "id": "byName",
          "options": "Requests"
        },
        "properties": [
          {
            "id": "custom.width",
            "value": 118
          }
        ]
      },
      {
        "matcher": {
          "id": "byName",
          "options": "level_name"
        },
        "properties": [
          {
            "id": "custom.width",
            "value": 130
          }
        ]
      }
    ]
  },
  "transformations": [
    {
      "id": "organize",
      "options": {
        "excludeByName": {
          "Field": false,
          "Time": true
        },
        "includeByName": {},
        "indexByName": {
          "Time": 0,
          "Value #A": 3,
          "request_uri": 2,
          "status": 1
        },
        "renameByName": {
          "Value #A": "Requests"
        }
      }
    }
  ],
  "pluginVersion": "12.3.0",
  "targets": [
    {
      "datasource": {
        "type": "loki",
        "uid": "bf64dm2w8rvggc"
      },
      "direction": "backward",
      "editorMode": "code",
      "expr": "topk(100, sum by (message,level_name) (count_over_time({hostname=~\".+\", service_name=~`(.+)-be-([0-9].+)`} | json | message=~\".+\" | level_name=~\".+\"  [$__auto])))",
      "legendFormat": "{{status}}",
      "queryType": "instant",
      "refId": "A"
    }
  ],
  "datasource": {
    "type": "loki",
    "uid": "bf64dm2w8rvggc"
  },
  "options": {
    "showHeader": true,
    "cellHeight": "sm",
    "sortBy": [
      {
        "desc": true,
        "displayName": "Requests"
      }
    ]
  }
}

Memory Usage

sum(container_memory_rss{instance=~".+", name=~"(.+)-be-([0-9].+)"})
{
  "id": 14,
  "type": "timeseries",
  "title": "Memory Usage",
  "gridPos": {
    "x": 0,
    "y": 25,
    "h": 7,
    "w": 24
  },
  "fieldConfig": {
    "defaults": {
      "custom": {
        "drawStyle": "line",
        "lineInterpolation": "linear",
        "barAlignment": 0,
        "barWidthFactor": 0.6,
        "lineWidth": 1,
        "fillOpacity": 0,
        "gradientMode": "none",
        "spanNulls": true,
        "insertNulls": false,
        "showPoints": "never",
        "showValues": false,
        "pointSize": 5,
        "stacking": {
          "mode": "none",
          "group": "A"
        },
        "axisPlacement": "auto",
        "axisLabel": "",
        "axisColorMode": "text",
        "axisBorderShow": false,
        "scaleDistribution": {
          "type": "linear"
        },
        "axisCenteredZero": false,
        "hideFrom": {
          "tooltip": false,
          "viz": false,
          "legend": false
        },
        "thresholdsStyle": {
          "mode": "off"
        },
        "lineStyle": {
          "fill": "solid"
        }
      },
      "color": {
        "mode": "palette-classic"
      },
      "mappings": [],
      "thresholds": {
        "mode": "absolute",
        "steps": [
          {
            "color": "green",
            "value": null
          },
          {
            "color": "red",
            "value": 80
          }
        ]
      },
      "unit": "bytes"
    },
    "overrides": []
  },
  "pluginVersion": "12.3.0",
  "targets": [
    {
      "datasource": {
        "type": "prometheus",
        "uid": "ce4iqqnzxpatcb"
      },
      "editorMode": "code",
      "expr": "sum(container_memory_rss{instance=~\".+\", name=~\"(.+)-be-([0-9].+)\"})",
      "interval": "",
      "legendFormat": "generally",
      "range": true,
      "refId": "B"
    },
    {
      "datasource": {
        "type": "prometheus",
        "uid": "ce4iqqnzxpatcb"
      },
      "editorMode": "code",
      "expr": "sum(container_memory_rss{instance=~\".+\", name=~\"mas-be-([0-9].+)\"})",
      "hide": false,
      "legendFormat": "mas-be",
      "range": true,
      "refId": "C"
    },
    {
      "datasource": {
        "type": "prometheus",
        "uid": "ce4iqqnzxpatcb"
      },
      "editorMode": "code",
      "expr": "sum(container_memory_rss{instance=~\".+\", name=~\"pas-be-([0-9].+)\"})",
      "hide": false,
      "legendFormat": "pas-be",
      "range": true,
      "refId": "A"
    },
    {
      "datasource": {
        "type": "prometheus",
        "uid": "ce4iqqnzxpatcb"
      },
      "editorMode": "code",
      "expr": "sum(container_memory_rss{instance=~\".+\", name=~\"stm-be-([0-9].+)\"})",
      "hide": false,
      "legendFormat": "stm-be",
      "range": true,
      "refId": "D"
    },
    {
      "datasource": {
        "type": "prometheus",
        "uid": "ce4iqqnzxpatcb"
      },
      "editorMode": "code",
      "expr": "sum(container_memory_rss{instance=~\".+\", name=~\"scb-be-([0-9].+)\"})",
      "hide": false,
      "legendFormat": "scb-be",
      "range": true,
      "refId": "E"
    }
  ],
  "datasource": {
    "type": "prometheus",
    "uid": "ce4iqqnzxpatcb"
  },
  "interval": "1s",
  "options": {
    "tooltip": {
      "mode": "multi",
      "sort": "none",
      "hideZeros": false
    },
    "legend": {
      "showLegend": true,
      "displayMode": "list",
      "placement": "bottom",
      "calcs": [
        "max"
      ],
      "sortBy": "Max",
      "sortDesc": true
    }
  }
}

API HTTP requests per second (RPS) at all

sum(count_over_time({hostname=~".+", service_name =~ "(.+)-be-([0-9].+)"} |= "upstream_response_time" | json | __error__= "" [$__auto]))
{
  "id": 2,
  "type": "timeseries",
  "title": "API HTTP requests per second (RPS) at all",
  "gridPos": {
    "x": 0,
    "y": 0,
    "h": 11,
    "w": 24
  },
  "fieldConfig": {
    "defaults": {
      "custom": {
        "drawStyle": "line",
        "lineInterpolation": "linear",
        "barAlignment": 0,
        "barWidthFactor": 0.6,
        "lineWidth": 1,
        "fillOpacity": 0,
        "gradientMode": "none",
        "spanNulls": false,
        "insertNulls": false,
        "showPoints": "never",
        "showValues": false,
        "pointSize": 5,
        "stacking": {
          "mode": "none",
          "group": "A"
        },
        "axisPlacement": "auto",
        "axisLabel": "",
        "axisColorMode": "text",
        "axisBorderShow": false,
        "scaleDistribution": {
          "type": "linear"
        },
        "axisCenteredZero": false,
        "hideFrom": {
          "tooltip": false,
          "viz": false,
          "legend": false
        },
        "thresholdsStyle": {
          "mode": "off"
        }
      },
      "color": {
        "mode": "palette-classic"
      },
      "mappings": [],
      "thresholds": {
        "mode": "absolute",
        "steps": [
          {
            "color": "green",
            "value": null
          },
          {
            "color": "red",
            "value": 80
          }
        ]
      }
    },
    "overrides": []
  },
  "pluginVersion": "12.3.0",
  "targets": [
    {
      "datasource": {
        "type": "loki",
        "uid": "bf64dm2w8rvggc"
      },
      "direction": "backward",
      "editorMode": "code",
      "expr": "sum(count_over_time({hostname=~\".+\", service_name =~ \"(.+)-be-([0-9].+)\"} |= \"upstream_response_time\" | json | __error__= \"\" [$__auto]))",
      "hide": false,
      "legendFormat": "generally",
      "queryType": "range",
      "refId": "B"
    },
    {
      "datasource": {
        "type": "loki",
        "uid": "bf64dm2w8rvggc"
      },
      "direction": "backward",
      "editorMode": "code",
      "expr": "sum(count_over_time({hostname=~\"dc01(.+)\", service_name =~ \"(.+)-be-([0-9].+)\"} |= \"upstream_response_time\" | json | __error__= \"\" [$__auto]))",
      "hide": false,
      "legendFormat": "generally dc01",
      "queryType": "range",
      "refId": "F"
    },
    {
      "datasource": {
        "type": "loki",
        "uid": "bf64dm2w8rvggc"
      },
      "direction": "backward",
      "editorMode": "code",
      "expr": "sum(count_over_time({hostname=~\"dc02(.+)\", service_name =~ \"(.+)-be-([0-9].+)\"} |= \"upstream_response_time\" | json | __error__= \"\" [$__auto]))",
      "hide": false,
      "legendFormat": "generally dc02",
      "queryType": "range",
      "refId": "G"
    },
    {
      "datasource": {
        "type": "loki",
        "uid": "bf64dm2w8rvggc"
      },
      "direction": "backward",
      "editorMode": "code",
      "expr": "sum(count_over_time({hostname=~\".+\", service_name=~\"mas-be-([0-9].+)\"} |= \"upstream_response_time\" | json | __error__=\"\" [$__auto]))",
      "hide": false,
      "legendFormat": "mas-be",
      "queryType": "range",
      "refId": "C"
    },
    {
      "datasource": {
        "type": "loki",
        "uid": "bf64dm2w8rvggc"
      },
      "direction": "backward",
      "editorMode": "code",
      "expr": "sum(count_over_time({hostname=~\".+\", service_name=~\"pas-be-([0-9].+)\"} |= \"upstream_response_time\" | json | __error__=\"\"[$__auto]))",
      "hide": false,
      "legendFormat": "pas-be",
      "queryType": "range",
      "refId": "A"
    },
    {
      "datasource": {
        "type": "loki",
        "uid": "bf64dm2w8rvggc"
      },
      "direction": "backward",
      "editorMode": "code",
      "expr": "sum(count_over_time({hostname=~\".+\", service_name=~\"stm-be-([0-9].+)\"} |= \"upstream_response_time\" | json | __error__=\"\" [$__auto]))",
      "hide": false,
      "legendFormat": "stm-be",
      "queryType": "range",
      "refId": "D"
    },
    {
      "datasource": {
        "type": "loki",
        "uid": "bf64dm2w8rvggc"
      },
      "direction": "backward",
      "editorMode": "code",
      "expr": "sum(count_over_time({hostname=~\".+\", service_name=~\"scb-be-([0-9].+)\"} |= \"upstream_response_time\" | json | __error__=\"\" [$__auto]))",
      "hide": false,
      "legendFormat": "scb-be",
      "queryType": "range",
      "refId": "E"
    }
  ],
  "datasource": {
    "type": "loki",
    "uid": "bf64dm2w8rvggc"
  },
  "interval": "1s",
  "options": {
    "tooltip": {
      "mode": "multi",
      "sort": "asc",
      "hideZeros": false
    },
    "legend": {
      "showLegend": true,
      "displayMode": "list",
      "placement": "bottom",
      "calcs": [
        "max"
      ],
      "sortBy": "Max",
      "sortDesc": true
    }
  }
}

Top 100 HTTP requests

topk(100, sum by(request_uri) (count_over_time({hostname=~".+", service_name =~ "(.+)-be-([0-9].+)"} | json | status != `` [$__auto])))
{
  "id": 5,
  "type": "table",
  "title": "Top 100 HTTP requests",
  "gridPos": {
    "x": 0,
    "y": 46,
    "h": 13,
    "w": 12
  },
  "fieldConfig": {
    "defaults": {
      "custom": {
        "align": "auto",
        "footer": {
          "reducers": []
        },
        "cellOptions": {
          "type": "auto"
        },
        "inspect": false
      },
      "mappings": [],
      "thresholds": {
        "mode": "absolute",
        "steps": [
          {
            "color": "green",
            "value": null
          },
          {
            "color": "red",
            "value": 80
          }
        ]
      },
      "color": {
        "mode": "thresholds"
      },
      "unit": "none"
    },
    "overrides": [
      {
        "matcher": {
          "id": "byName",
          "options": "Requests"
        },
        "properties": [
          {
            "id": "custom.width",
            "value": 134
          }
        ]
      }
    ]
  },
  "transformations": [
    {
      "id": "organize",
      "options": {
        "excludeByName": {
          "Field": false,
          "Time": true
        },
        "includeByName": {},
        "indexByName": {
          "Time": 0,
          "Value #A": 1,
          "request_uri": 2,
          "status": 3
        },
        "renameByName": {
          "Value #A": "Requests"
        }
      }
    }
  ],
  "pluginVersion": "12.3.0",
  "targets": [
    {
      "datasource": {
        "type": "loki",
        "uid": "bf64dm2w8rvggc"
      },
      "direction": "backward",
      "editorMode": "code",
      "expr": "topk(100, sum by(request_uri) (count_over_time({hostname=~\".+\", service_name =~ \"(.+)-be-([0-9].+)\"} | json | status != `` [$__auto])))",
      "legendFormat": "{{status}}",
      "queryType": "instant",
      "refId": "A"
    }
  ],
  "datasource": {
    "type": "loki",
    "uid": "bf64dm2w8rvggc"
  },
  "options": {
    "showHeader": true,
    "cellHeight": "sm",
    "sortBy": [
      {
        "desc": true,
        "displayName": "Requests"
      }
    ]
  }
}

HTTP statuses

topk(100, sum by(status) (count_over_time({hostname=~".+", service_name =~ "(.+)-be-([0-9].+)"} | json status | status != `` [$__auto])))

Здесь важный момент то, что значения подменяются на описания согласно mappings:

{
  "id": 4,
  "type": "table",
  "title": "HTTP statuses",
  "gridPos": {
    "x": 12,
    "y": 46,
    "h": 13,
    "w": 12
  },
  "fieldConfig": {
    "defaults": {
      "custom": {
        "align": "auto",
        "footer": {
          "reducers": []
        },
        "cellOptions": {
          "type": "auto"
        },
        "inspect": false
      },
      "mappings": [
        {
          "options": {},
          "type": "value"
        }
      ],
      "thresholds": {
        "mode": "absolute",
        "steps": [
          {
            "color": "green",
            "value": null
          },
          {
            "color": "red",
            "value": 80
          }
        ]
      },
      "color": {
        "mode": "thresholds"
      },
      "unit": "none"
    },
    "overrides": [
      {
        "matcher": {
          "id": "byName",
          "options": "status"
        },
        "properties": [
          {
            "id": "mappings",
            "value": [
              {
                "options": {
                  "100": {
                    "index": 0,
                    "text": "100 : Continue (продолжайте)"
                  },
                  "101": {
                    "index": 1,
                    "text": "101 : Switching Protocols (переключение протоколов)"
                  },
                  "102": {
                    "index": 2,
                    "text": "102 : Processing (идёт обработка)"
                  },
                  "103": {
                    "index": 3,
                    "text": "103 : Early Hints (предварительный ответ)"
                  },
                  "200": {
                    "index": 4,
                    "text": "200 : OK (хорошо)"
                  },
                  "201": {
                    "index": 5,
                    "text": "201 : Created (создано)"
                  },
                  "202": {
                    "index": 6,
                    "text": "202 : Accepted (принято)"
                  },
                  "203": {
                    "index": 7,
                    "text": "203 : Non-Authoritative Information (информация не авторитетна)"
                  },
                  "204": {
                    "index": 8,
                    "text": "204 : No Content (нет содержимого)"
                  },
                  "205": {
                    "index": 9,
                    "text": "205 : Reset Content (сбросить содержимое)"
                  },
                  "206": {
                    "index": 10,
                    "text": "206 : Partial Content (частичное содержимое)"
                  },
                  "207": {
                    "index": 11,
                    "text": "207 : Multi-Status (многостатусный)"
                  },
                  "208": {
                    "index": 12,
                    "text": "208 : Already Reported (уже сообщалось)"
                  },
                  "226": {
                    "index": 13,
                    "text": "226 : IM Used (использовано IM)"
                  },
                  "300": {
                    "index": 14,
                    "text": "300 : Multiple Choices (множество выборов)"
                  },
                  "301": {
                    "index": 15,
                    "text": "301 : Moved Permanently (перемещено навсегда)"
                  },
                  "302": {
                    "index": 16,
                    "text": "302 : Found (найдено)"
                  },
                  "303": {
                    "index": 17,
                    "text": "303 : See Other (смотреть другое)"
                  },
                  "304": {
                    "index": 18,
                    "text": "304 : Not Modified (не изменялось)"
                  },
                  "305": {
                    "index": 19,
                    "text": "305 : Use Proxy (использовать прокси)"
                  },
                  "306": {
                    "index": 20,
                    "text": "306 : (зарезервировано)"
                  },
                  "307": {
                    "index": 21,
                    "text": "307 : Temporary Redirect (временное перенаправление)"
                  },
                  "308": {
                    "index": 22,
                    "text": "308 : Permanent Redirect (постоянное перенаправление)"
                  },
                  "400": {
                    "index": 23,
                    "text": "400 : Bad Request (некорректный запрос)"
                  },
                  "401": {
                    "index": 24,
                    "text": "401 : Unauthorized (не авторизован)"
                  },
                  "402": {
                    "index": 25,
                    "text": "402 : Payment Required (необходима оплата)"
                  },
                  "403": {
                    "index": 26,
                    "text": "403 : Forbidden (запрещено)"
                  },
                  "404": {
                    "index": 27,
                    "text": "404 : Not Found (не найдено)"
                  },
                  "405": {
                    "index": 28,
                    "text": "405 : Method Not Allowed (метод не поддерживается)"
                  },
                  "406": {
                    "index": 29,
                    "text": "406 : Not Acceptable (неприемлемо)"
                  },
                  "407": {
                    "index": 30,
                    "text": "407 : Proxy Authentication Required (необходима аутентификация прокси)"
                  },
                  "408": {
                    "index": 31,
                    "text": "408 : Request Timeout (клиент долго отправлял данные и сервер закрыл соединение)"
                  },
                  "409": {
                    "index": 32,
                    "text": "409 : Conflict (конфликт)"
                  },
                  "410": {
                    "index": 33,
                    "text": "410 : Gone (удалён)"
                  },
                  "411": {
                    "index": 34,
                    "text": "411 : Length Required (необходима длина)"
                  },
                  "412": {
                    "index": 35,
                    "text": "412 : Precondition Failed (условие ложно)"
                  },
                  "413": {
                    "index": 36,
                    "text": "413 : Payload Too Large (полезная нагрузка слишком велика)"
                  },
                  "414": {
                    "index": 37,
                    "text": "414 : URI Too Long (URI слишком длинный)"
                  },
                  "415": {
                    "index": 38,
                    "text": "415 : Unsupported Media Type (неподдерживаемый тип данных)"
                  },
                  "416": {
                    "index": 39,
                    "text": "416 : Range Not Satisfiable (диапазон не достижим)"
                  },
                  "417": {
                    "index": 40,
                    "text": "417 : Expectation Failed (ожидание не оправдалось)"
                  },
                  "418": {
                    "index": 41,
                    "text": "418 : I'm a teapot (я — чайник)"
                  },
                  "419": {
                    "index": 42,
                    "text": "419 : Authentication Timeout (ошибка проверки CSRF)"
                  },
                  "421": {
                    "index": 43,
                    "text": "421 : Misdirected Request"
                  },
                  "422": {
                    "index": 44,
                    "text": "422 : Unprocessable Entity (необрабатываемый экземпляр)"
                  },
                  "423": {
                    "index": 45,
                    "text": "423 : Locked (заблокировано)"
                  },
                  "424": {
                    "index": 46,
                    "text": "424 : Failed Dependency (невыполненная зависимость)"
                  },
                  "425": {
                    "index": 47,
                    "text": "425 : Too Early (слишком рано)"
                  },
                  "426": {
                    "index": 48,
                    "text": "426 : Upgrade Required (необходимо обновление)"
                  },
                  "428": {
                    "index": 49,
                    "text": "428 : Precondition Required (необходимо предусловие)"
                  },
                  "429": {
                    "index": 50,
                    "text": "429 : Too Many Requests (слишком много запросов)"
                  },
                  "431": {
                    "index": 51,
                    "text": "431 : Request Header Fields Too Large (поля заголовка слишком большие)"
                  },
                  "449": {
                    "index": 52,
                    "text": "449 : Retry With (повторить с)"
                  },
                  "451": {
                    "index": 53,
                    "text": "451 : Unavailable For Legal Reasons (недоступно по юридическим причинам)"
                  },
                  "499": {
                    "index": 54,
                    "text": "499 : Client Closed Request (клиент закрыл соединение)"
                  },
                  "500": {
                    "index": 55,
                    "text": "500 : Internal Server Error (ошибка в коде на сервере или не хватает ресурсов для обработки запроса на сервере)"
                  },
                  "501": {
                    "index": 56,
                    "text": "501 : Not Implemented (не реализовано)"
                  },
                  "502": {
                    "index": 57,
                    "text": "502 : Bad Gateway (сервер получил некорректный ответ от другого сервера)"
                  },
                  "503": {
                    "index": 58,
                    "text": "503 : Service Unavailable (сервис недоступен)"
                  },
                  "504": {
                    "index": 59,
                    "text": "504 : Gateway Timeout (шлюз не отвечает)"
                  },
                  "505": {
                    "index": 60,
                    "text": "505 : HTTP Version Not Supported (версия HTTP не поддерживается)"
                  },
                  "506": {
                    "index": 61,
                    "text": "506 : Variant Also Negotiates (вариант тоже проводит согласование)"
                  },
                  "507": {
                    "index": 62,
                    "text": "507 : Insufficient Storage (переполнение хранилища)"
                  },
                  "508": {
                    "index": 63,
                    "text": "508 : Loop Detected (обнаружено перенаправление)"
                  },
                  "509": {
                    "index": 64,
                    "text": "509 : Bandwidth Limit Exceeded (исчерпана пропускная ширина)"
                  },
                  "510": {
                    "index": 65,
                    "text": "510 : Not Extended (не расширено)"
                  },
                  "511": {
                    "index": 66,
                    "text": "511 : Network Authentication Required (требуется сетевая аутентификация)"
                  },
                  "520": {
                    "index": 67,
                    "text": "520 : Unknown Error (неизвестная ошибка)"
                  },
                  "521": {
                    "index": 68,
                    "text": "521 : Web Server Is Down (веб-сервер не работает)"
                  },
                  "522": {
                    "index": 69,
                    "text": "522 : Connection Timed Out (соединение не отвечает)"
                  },
                  "523": {
                    "index": 70,
                    "text": "523 : Origin Is Unreachable (источник недоступен)"
                  },
                  "524": {
                    "index": 71,
                    "text": "524 : A Timeout Occurred (время ожидания истекло)"
                  },
                  "525": {
                    "index": 72,
                    "text": "525 : SSL Handshake Failed (квитирование SSL не удалось)"
                  },
                  "526": {
                    "index": 73,
                    "text": "526 : Invalid SSL Certificate (недействительный сертификат SSL)"
                  }
                },
                "type": "value"
              }
            ]
          }
        ]
      },
      {
        "matcher": {
          "id": "byName",
          "options": "Requests"
        },
        "properties": [
          {
            "id": "custom.width",
            "value": 140
          }
        ]
      }
    ]
  },
  "transformations": [
    {
      "id": "organize",
      "options": {
        "excludeByName": {
          "Field": false,
          "Time": true
        },
        "includeByName": {},
        "indexByName": {},
        "orderByMode": "manual",
        "renameByName": {
          "Time": "",
          "Value #A": "Requests",
          "status": ""
        }
      }
    }
  ],
  "pluginVersion": "12.3.0",
  "targets": [
    {
      "datasource": {
        "type": "loki",
        "uid": "bf64dm2w8rvggc"
      },
      "direction": "backward",
      "editorMode": "code",
      "expr": "topk(100, sum by(status) (count_over_time({hostname=~\".+\", service_name =~ \"(.+)-be-([0-9].+)\"} | json status | status != `` [$__auto])))",
      "legendFormat": "",
      "queryType": "instant",
      "refId": "A"
    }
  ],
  "datasource": {
    "type": "loki",
    "uid": "bf64dm2w8rvggc"
  },
  "options": {
    "showHeader": true,
    "cellHeight": "sm",
    "sortBy": [
      {
        "desc": true,
        "displayName": "Requests"
      }
    ]
  }
}

All HTTP requests per status

topk(100, sum by(status, request_uri) (count_over_time({hostname=~".+", service_name =~ "(.+)-be-([0-9].+)"} | json | status != `` [$__auto])))
{
  "id": 6,
  "type": "table",
  "title": "All HTTP requests per status",
  "gridPos": {
    "x": 0,
    "y": 59,
    "h": 8,
    "w": 12
  },
  "fieldConfig": {
    "defaults": {
      "custom": {
        "align": "auto",
        "footer": {
          "reducers": []
        },
        "cellOptions": {
          "type": "auto"
        },
        "inspect": false
      },
      "mappings": [],
      "thresholds": {
        "mode": "absolute",
        "steps": [
          {
            "color": "green",
            "value": null
          },
          {
            "color": "red",
            "value": 80
          }
        ]
      },
      "color": {
        "mode": "thresholds"
      },
      "unit": "none"
    },
    "overrides": [
      {
        "matcher": {
          "id": "byName",
          "options": "Requests"
        },
        "properties": [
          {
            "id": "custom.width",
            "value": 146
          }
        ]
      },
      {
        "matcher": {
          "id": "byName",
          "options": "request_uri"
        },
        "properties": [
          {
            "id": "custom.width",
            "value": 1017
          }
        ]
      }
    ]
  },
  "transformations": [
    {
      "id": "organize",
      "options": {
        "excludeByName": {
          "Field": false,
          "Time": true
        },
        "includeByName": {},
        "indexByName": {
          "Time": 0,
          "Value #A": 1,
          "request_uri": 2,
          "status": 3
        },
        "renameByName": {
          "Value #A": "Requests"
        }
      }
    }
  ],
  "pluginVersion": "12.3.0",
  "targets": [
    {
      "datasource": {
        "type": "loki",
        "uid": "bf64dm2w8rvggc"
      },
      "direction": "backward",
      "editorMode": "code",
      "expr": "topk(100, sum by(status, request_uri) (count_over_time({hostname=~\".+\", service_name =~ \"(.+)-be-([0-9].+)\"} | json | status != `` [$__auto])))",
      "legendFormat": "{{status}}",
      "queryType": "instant",
      "refId": "A"
    }
  ],
  "datasource": {
    "type": "loki",
    "uid": "bf64dm2w8rvggc"
  },
  "options": {
    "showHeader": true,
    "cellHeight": "sm",
    "sortBy": [
      {
        "desc": true,
        "displayName": "Requests"
      }
    ]
  }
}

Top 100 Important HTTP statuses

{
  "id": 7,
  "type": "table",
  "title": "Top 100 Important HTTP statuses",
  "gridPos": {
    "x": 12,
    "y": 59,
    "h": 8,
    "w": 12
  },
  "fieldConfig": {
    "defaults": {
      "custom": {
        "align": "auto",
        "footer": {
          "reducers": []
        },
        "cellOptions": {
          "type": "auto"
        },
        "inspect": false
      },
      "mappings": [],
      "thresholds": {
        "mode": "absolute",
        "steps": [
          {
            "color": "green",
            "value": null
          },
          {
            "color": "red",
            "value": 80
          }
        ]
      },
      "color": {
        "mode": "thresholds"
      },
      "unit": "none"
    },
    "overrides": [
      {
        "matcher": {
          "id": "byName",
          "options": "Requests"
        },
        "properties": [
          {
            "id": "custom.width",
            "value": 153
          }
        ]
      }
    ]
  },
  "transformations": [
    {
      "id": "organize",
      "options": {
        "excludeByName": {
          "Field": false,
          "Time": true
        },
        "includeByName": {},
        "indexByName": {
          "Time": 0,
          "Value #A": 1,
          "request_uri": 2,
          "status": 3
        },
        "renameByName": {
          "Value #A": "Requests"
        }
      }
    }
  ],
  "pluginVersion": "12.3.0",
  "targets": [
    {
      "datasource": {
        "type": "loki",
        "uid": "bf64dm2w8rvggc"
      },
      "direction": "backward",
      "editorMode": "code",
      "expr": "topk(100, sum by(http_host, status, request_uri) (count_over_time({hostname=~\".+\", service_name =~ \"(.+)-be-([0-9].+)\"} | json | status != `` | status >= 400 [$__auto])))",
      "legendFormat": "{{status}}",
      "queryType": "instant",
      "refId": "A"
    }
  ],
  "datasource": {
    "type": "loki",
    "uid": "bf64dm2w8rvggc"
  },
  "options": {
    "showHeader": true,
    "cellHeight": "sm",
    "sortBy": [
      {
        "desc": true,
        "displayName": "Requests"
      }
    ]
  }
}

11.09.2021 07:08

Комментарии

Комментариев пока нет.


Copyrights © 2007 - 2026 YaPro.Ru