全部文章/监控

apisix-ingress与apisix监控

监控apisix和apisix-ingress组件

apisix

apisix-config配置

plugin_attr:
  prometheus:
    export_uri: /metrics  # 更改默认导出 URI 默认为/apisix/prometheus/metrics
    export_addr:
      ip: 0.0.0.0
      port: 9091 # 默认端口9091

使用podMonitor

deploy添加端口配置

            - containerPort: 9091
              name: metrics
              protocol: TCP

创建podMonitor

apiVersion: monitoring.coreos.com/v1
kind: PodMonitor
metadata:
  name: apisix
  namespace: ingress-apisix
  labels:
    use-for: apisix
spec:
  selector:
    matchLabels:
      app.kubernetes.io/name: apisix
  podMetricsEndpoints:
  - port: metrics

使用serviceMonitor

创建service

apiVersion: v1
kind: Service
metadata:
  labels:
    app.kubernetes.io/instance: apisix
    app.kubernetes.io/managed-by: Helm
    app.kubernetes.io/name: apisix-metrics
    app.kubernetes.io/service: apisix-metrics
    app.kubernetes.io/version: 3.4.0
    helm.sh/chart: apisix-2.1.0
  name: apisix-metrics
  namespace: ingress-apisix
spec:
  ports:
  - name: http
    port: 9091
    protocol: TCP
    targetPort: 9091
  selector:
    app.kubernetes.io/instance: apisix
    app.kubernetes.io/name: apisix
  type: ClusterIP
  clusterIP: None

创建serviceMonitor

apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
  name: apisix
  namespace: ingress-apisix
  labels:
    app: apisix
spec:
  namespaceSelector:
    matchNames:
    - ingress-apisix
  selector:
    matchLabels:
      app.kubernetes.io/instance: apisix
      app.kubernetes.io/name: apisix-metrics
  endpoints:
  - port: http

grafana-dashboard

grafana id :11719

ingress-apisix

使用podMonitor

apiVersion: monitoring.coreos.com/v1
kind: PodMonitor
metadata:
  name: ingress-apisix
  namespace: ingress-apisix
  labels:
    use-for: ingress-apisix
spec:
  selector:
    matchLabels:
      app.kubernetes.io/name: ingress-controller
  podMetricsEndpoints:
  - port: http

使用serviceMonitor

apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
  name: ingress-apisix
  namespace: ingress-apisix
  labels:
    app: ingress-apisix
spec:
  namespaceSelector:
    matchNames:
    - ingress-apisix
  selector:
    matchLabels:
      app.kubernetes.io/instance: apisix
      app.kubernetes.io/name: ingress-controller
  endpoints:
  - port: http

grafana-dashboard

导入dashboard,修改自己的数据源

{  
  "annotations": {  
    "list": [  
      {  
        "builtIn": 1,  
        "datasource": "prometheus",  
        "enable": true,  
        "hide": true,  
        "iconColor": "rgba(0, 211, 255, 1)",  
        "limit": 100,  
        "name": "Annotations & Alerts",  
        "showIn": 0,  
        "type": "dashboard"  
      }  
    ]  
  },  
  "description": "Ingress Controller of Apache APISIX",  
  "editable": true,  
  "gnetId": 11719,  
  "graphTooltip": 0,  
  "id": 9,  
  "iteration": 1632975622801,  
  "links": [],  
  "panels": [  
    {  
      "collapsed": false,  
      "datasource": "prometheus",  
      "gridPos": {  
        "h": 1,  
        "w": 24,  
        "x": 0,  
        "y": 0  
      },  
      "id": 10,  
      "panels": [],  
      "title": "APISIX Ingress controller",  
      "type": "row"  
    },  
    {  
      "datasource": "prometheus",  
      "description": "Whether the role of controller instance is leader",  
      "fieldConfig": {  
        "defaults": {  
          "color": {  
            "mode": "thresholds"  
          },  
          "mappings": [  
            {  
              "from": "",  
              "id": 1,  
              "text": "Candidate",  
              "to": "",  
              "type": 1,  
              "value": "0"  
            },  
            {  
              "from": "",  
              "id": 2,  
              "text": "Leader",  
              "to": "",  
              "type": 1,  
              "value": "1"  
            }  
          ],  
          "thresholds": {  
            "mode": "absolute",  
            "steps": [  
              {  
                "color": "green",  
                "value": null  
              },  
              {  
                "color": "red",  
                "value": 80  
              }  
            ]  
          }  
        },  
        "overrides": []  
      },  
      "gridPos": {  
        "h": 5,  
        "w": 8,  
        "x": 0,  
        "y": 1  
      },  
      "id": 33,  
      "options": {  
        "colorMode": "value",  
        "graphMode": "area",  
        "justifyMode": "auto",  
        "orientation": "auto",  
        "reduceOptions": {  
          "calcs": [  
            "lastNotNull"  
          ],  
          "fields": "",  
          "values": false  
        },  
        "text": {},  
        "textMode": "auto"  
      },  
      "pluginVersion": "7.5.6",  
      "targets": [  
        {  
          "exemplar": true,  
          "expr": "apisix_ingress_controller_is_leader",  
          "instant": false,  
          "interval": "",  
          "legendFormat": "",  
          "refId": "A"  
        }  
      ],  
      "title": "Is Leader",  
      "type": "stat"  
    },  
    {  
      "cacheTimeout": null,  
      "datasource": "prometheus",  
      "description": "",  
      "fieldConfig": {  
        "defaults": {  
          "color": {  
            "mode": "thresholds"  
          },  
          "mappings": [],  
          "thresholds": {  
            "mode": "absolute",  
            "steps": [  
              {  
                "color": "green",  
                "value": null  
              },  
              {  
                "color": "red",  
                "value": 80  
              }  
            ]  
          },  
          "unit": "none"  
        },  
        "overrides": []  
      },  
      "gridPos": {  
        "h": 5,  
        "w": 8,  
        "x": 8,  
        "y": 1  
      },  
      "id": 16,  
      "interval": null,  
      "links": [],  
      "maxDataPoints": 100,  
      "options": {  
        "colorMode": "value",  
        "graphMode": "area",  
        "justifyMode": "auto",  
        "orientation": "auto",  
        "reduceOptions": {  
          "calcs": [  
            "lastNotNull"  
          ],  
          "fields": "",  
          "values": false  
        },  
        "text": {},  
        "textMode": "auto"  
      },  
      "pluginVersion": "7.5.6",  
      "targets": [  
        {  
          "exemplar": true,  
          "expr": "irate(apisix_ingress_controller_cache_sync_total[5m])",  
          "interval": "",  
          "intervalFactor": 2,  
          "legendFormat": "{{result}}",  
          "refId": "A"  
        }  
      ],  
      "timeFrom": null,  
      "timeShift": null,  
      "title": "Cache Sync Operations",  
      "type": "stat"  
    },  
    {  
      "cacheTimeout": null,  
      "datasource": "prometheus",  
      "description": "",  
      "fieldConfig": {  
        "defaults": {  
          "color": {  
            "mode": "thresholds"  
          },  
          "mappings": [],  
          "thresholds": {  
            "mode": "absolute",  
            "steps": [  
              {  
                "color": "green",  
                "value": null  
              }  
            ]  
          },  
          "unit": "none"  
        },  
        "overrides": []  
      },  
      "gridPos": {  
        "h": 5,  
        "w": 8,  
        "x": 16,  
        "y": 1  
      },  
      "id": 11,  
      "interval": null,  
      "links": [],  
      "maxDataPoints": 100,  
      "options": {  
        "colorMode": "value",  
        "graphMode": "area",  
        "justifyMode": "auto",  
        "orientation": "auto",  
        "reduceOptions": {  
          "calcs": [  
            "lastNotNull"  
          ],  
          "fields": "",  
          "values": false  
        },  
        "text": {},  
        "textMode": "auto"  
      },  
      "pluginVersion": "7.5.6",  
      "targets": [  
        {  
          "exemplar": true,  
          "expr": "irate(apisix_ingress_controller_sync_operation_total[5m])",  
          "interval": "",  
          "intervalFactor": 2,  
          "legendFormat": "{{resource}}-{{result}}",  
          "refId": "A"  
        }  
      ],  
      "timeFrom": null,  
      "timeShift": null,  
      "title": "Sync Operations",  
      "type": "stat"  
    },  
    {  
      "datasource": "prometheus",  
      "description": "Number of events handled by the controller",  
      "fieldConfig": {  
        "defaults": {  
          "color": {  
            "mode": "thresholds"  
          },  
          "mappings": [],  
          "thresholds": {  
            "mode": "absolute",  
            "steps": [  
              {  
                "color": "green",  
                "value": null  
              }  
            ]  
          },  
          "unit": "none"  
        },  
        "overrides": []  
      },  
      "gridPos": {  
        "h": 7,  
        "w": 8,  
        "x": 0,  
        "y": 6  
      },  
      "id": 35,  
      "options": {  
        "colorMode": "value",  
        "graphMode": "area",  
        "justifyMode": "auto",  
        "orientation": "auto",  
        "reduceOptions": {  
          "calcs": [  
            "lastNotNull"  
          ],  
          "fields": "",  
          "values": false  
        },  
        "text": {},  
        "textMode": "auto"  
      },  
      "pluginVersion": "7.5.6",  
      "targets": [  
        {  
          "exemplar": true,  
          "expr": "irate(apisix_ingress_controller_events_total[5m])",  
          "interval": "",  
          "legendFormat": "{{resource}}-{{operation}}",  
          "refId": "A"  
        }  
      ],  
      "timeFrom": null,  
      "timeShift": null,  
      "title": "Total Events",  
      "type": "stat"  
    },  
    {  
      "datasource": "prometheus",  
      "fieldConfig": {  
        "defaults": {  
          "color": {  
            "mode": "thresholds"  
          },  
          "mappings": [],  
          "thresholds": {  
            "mode": "absolute",  
            "steps": [  
              {  
                "color": "green",  
                "value": null  
              }  
            ]  
          },  
          "unit": "none"  
        },  
        "overrides": []  
      },  
      "gridPos": {  
        "h": 7,  
        "w": 8,  
        "x": 8,  
        "y": 6  
      },  
      "id": 29,  
      "options": {  
        "colorMode": "value",  
        "graphMode": "area",  
        "justifyMode": "auto",  
        "orientation": "auto",  
        "reduceOptions": {  
          "calcs": [  
            "lastNotNull"  
          ],  
          "fields": "",  
          "values": false  
        },  
        "text": {},  
        "textMode": "auto"  
      },  
      "pluginVersion": "7.5.6",  
      "targets": [  
        {  
          "exemplar": true,  
          "expr": "irate(apisix_ingress_controller_check_cluster_health_total[5m])",  
          "interval": "",  
          "legendFormat": "{{result}}",  
          "refId": "A"  
        }  
      ],  
      "timeFrom": null,  
      "timeShift": null,  
      "title": "Cluster Health Check",  
      "type": "stat"  
    },  
    {  
      "datasource": "prometheus",  
      "fieldConfig": {  
        "defaults": {  
          "color": {  
            "mode": "thresholds"  
          },  
          "mappings": [],  
          "thresholds": {  
            "mode": "absolute",  
            "steps": [  
              {  
                "color": "green",  
                "value": null  
              },  
              {  
                "color": "red",  
                "value": 80  
              }  
            ]  
          },  
          "unit": "percentunit"  
        },  
        "overrides": []  
      },  
      "gridPos": {  
        "h": 7,  
        "w": 8,  
        "x": 16,  
        "y": 6  
      },  
      "id": 6,  
      "options": {  
        "colorMode": "value",  
        "graphMode": "area",  
        "justifyMode": "auto",  
        "orientation": "auto",  
        "reduceOptions": {  
          "calcs": [  
            "lastNotNull"  
          ],  
          "fields": "",  
          "values": false  
        },  
        "text": {},  
        "textMode": "auto"  
      },  
      "pluginVersion": "7.5.6",  
      "targets": [  
        {  
          "exemplar": true,  
          "expr": "sum(apisix_ingress_controller_apisix_bad_status_codes{status_code =~ \"[4-5].*\"}) / sum(apisix_ingress_controller_apisix_requests)",  
          "hide": false,  
          "interval": "",  
          "legendFormat": "",  
          "refId": "A"  
        }  
      ],  
      "timeFrom": null,  
      "timeShift": null,  
      "title": "Response Error Rate",  
      "type": "stat"  
    },  
    {  
      "collapsed": false,  
      "datasource": "prometheus",  
      "gridPos": {  
        "h": 1,  
        "w": 24,  
        "x": 0,  
        "y": 13  
      },  
      "id": 31,  
      "panels": [],  
      "title": "Apisix Requests",  
      "type": "row"  
    },  
    {  
      "aliasColors": {},  
      "bars": false,  
      "cacheTimeout": null,  
      "dashLength": 10,  
      "dashes": false,  
      "datasource": "prometheus",  
      "description": "",  
      "fieldConfig": {  
        "defaults": {  
          "unit": "none"  
        },  
        "overrides": []  
      },  
      "fill": 1,  
      "fillGradient": 0,  
      "gridPos": {  
        "h": 6,  
        "w": 24,  
        "x": 0,  
        "y": 14  
      },  
      "hiddenSeries": false,  
      "id": 8,  
      "interval": null,  
      "legend": {  
        "avg": false,  
        "current": false,  
        "max": false,  
        "min": false,  
        "show": true,  
        "total": false,  
        "values": false  
      },  
      "lines": true,  
      "linewidth": 1,  
      "links": [],  
      "maxDataPoints": 100,  
      "nullPointMode": "null",  
      "options": {  
        "alertThreshold": true  
      },  
      "percentage": false,  
      "pluginVersion": "7.5.6",  
      "pointradius": 2,  
      "points": false,  
      "renderer": "flot",  
      "seriesOverrides": [],  
      "spaceLength": 10,  
      "stack": false,  
      "steppedLine": false,  
      "targets": [  
        {  
          "exemplar": true,  
          "expr": "apisix_ingress_controller_apisix_requests",  
          "interval": "",  
          "intervalFactor": 2,  
          "legendFormat": "{{resource}}",  
          "refId": "A"  
        }  
      ],  
      "thresholds": [],  
      "timeFrom": null,  
      "timeRegions": [],  
      "timeShift": null,  
      "title": "Total Requests",  
      "tooltip": {  
        "shared": true,  
        "sort": 0,  
        "value_type": "individual"  
      },  
      "type": "graph",  
      "xaxis": {  
        "buckets": null,  
        "mode": "time",  
        "name": null,  
        "show": true,  
        "values": []  
      },  
      "yaxes": [  
        {  
          "$$hashKey": "object:1442",  
          "format": "none",  
          "label": null,  
          "logBase": 1,  
          "max": null,  
          "min": "0",  
          "show": true  
        },  
        {  
          "$$hashKey": "object:1443",  
          "format": "short",  
          "label": null,  
          "logBase": 1,  
          "max": null,  
          "min": null,  
          "show": true  
        }  
      ],  
      "yaxis": {  
        "align": false,  
        "alignLevel": null  
      }  
    },  
    {  
      "aliasColors": {},  
      "bars": false,  
      "dashLength": 10,  
      "dashes": false,  
      "datasource": "prometheus",  
      "fieldConfig": {  
        "defaults": {  
          "links": []  
        },  
        "overrides": []  
      },  
      "fill": 1,  
      "fillGradient": 0,  
      "gridPos": {  
        "h": 7,  
        "w": 24,  
        "x": 0,  
        "y": 20  
      },  
      "hiddenSeries": false,  
      "id": 17,  
      "legend": {  
        "alignAsTable": false,  
        "avg": false,  
        "current": false,  
        "max": false,  
        "min": false,  
        "rightSide": false,  
        "show": true,  
        "total": false,  
        "values": false  
      },  
      "lines": true,  
      "linewidth": 1,  
      "nullPointMode": "null",  
      "options": {  
        "alertThreshold": true  
      },  
      "percentage": false,  
      "pluginVersion": "7.5.6",  
      "pointradius": 2,  
      "points": false,  
      "renderer": "flot",  
      "seriesOverrides": [],  
      "spaceLength": 10,  
      "stack": false,  
      "steppedLine": false,  
      "targets": [  
        {  
          "exemplar": true,  
          "expr": "apisix_ingress_controller_apisix_bad_status_codes",  
          "instant": false,  
          "interval": "",  
          "intervalFactor": 1,  
          "legendFormat": "{{resource}}-{{status_code}}",  
          "refId": "A"  
        }  
      ],  
      "thresholds": [],  
      "timeFrom": null,  
      "timeRegions": [],  
      "timeShift": null,  
      "title": "Status Codes",  
      "tooltip": {  
        "shared": true,  
        "sort": 0,  
        "value_type": "individual"  
      },  
      "type": "graph",  
      "xaxis": {  
        "buckets": null,  
        "mode": "time",  
        "name": null,  
        "show": true,  
        "values": []  
      },  
      "yaxes": [  
        {  
          "$$hashKey": "object:567",  
          "decimals": null,  
          "format": "short",  
          "label": "",  
          "logBase": 1,  
          "max": null,  
          "min": null,  
          "show": true  
        },  
        {  
          "$$hashKey": "object:568",  
          "decimals": null,  
          "format": "Misc",  
          "label": "",  
          "logBase": 1,  
          "max": null,  
          "min": null,  
          "show": true  
        }  
      ],  
      "yaxis": {  
        "align": false,  
        "alignLevel": null  
      }  
    },  
    {  
      "aliasColors": {},  
      "bars": false,  
      "cacheTimeout": null,  
      "dashLength": 10,  
      "dashes": false,  
      "datasource": "prometheus",  
      "description": "Request latencies with APISIX",  
      "fieldConfig": {  
        "defaults": {  
          "unit": "short"  
        },  
        "overrides": []  
      },  
      "fill": 1,  
      "fillGradient": 0,  
      "gridPos": {  
        "h": 6,  
        "w": 24,  
        "x": 0,  
        "y": 27  
      },  
      "hiddenSeries": false,  
      "id": 2,  
      "interval": "",  
      "legend": {  
        "avg": false,  
        "current": false,  
        "max": false,  
        "min": false,  
        "show": true,  
        "total": false,  
        "values": false  
      },  
      "lines": true,  
      "linewidth": 1,  
      "links": [],  
      "nullPointMode": "null",  
      "options": {  
        "alertThreshold": true  
      },  
      "percentage": false,  
      "pluginVersion": "7.5.6",  
      "pointradius": 2,  
      "points": false,  
      "renderer": "flot",  
      "seriesOverrides": [],  
      "spaceLength": 10,  
      "stack": false,  
      "steppedLine": false,  
      "targets": [  
        {  
          "exemplar": true,  
          "expr": "sum (\n  rate(\n      apisix_ingress_controller_apisix_request_latencies_sum{}[1m]\n)) / sum (\n  rate(\n      apisix_ingress_controller_apisix_request_latencies_count{}[1m]\n  )\n)",  
          "instant": false,  
          "interval": "",  
          "intervalFactor": 1,  
          "legendFormat": "average",  
          "refId": "A"  
        }  
      ],  
      "thresholds": [],  
      "timeFrom": null,  
      "timeRegions": [],  
      "timeShift": null,  
      "title": "Requests Latencies",  
      "tooltip": {  
        "shared": true,  
        "sort": 0,  
        "value_type": "individual"  
      },  
      "type": "graph",  
      "xaxis": {  
        "buckets": null,  
        "mode": "time",  
        "name": null,  
        "show": true,  
        "values": []  
      },  
      "yaxes": [  
        {  
          "$$hashKey": "object:439",  
          "format": "short",  
          "label": null,  
          "logBase": 1,  
          "max": null,  
          "min": null,  
          "show": true  
        },  
        {  
          "$$hashKey": "object:440",  
          "format": "short",  
          "label": null,  
          "logBase": 1,  
          "max": null,  
          "min": null,  
          "show": true  
        }  
      ],  
      "yaxis": {  
        "align": false,  
        "alignLevel": null  
      }  
    }  
  ],  
  "refresh": "5m",  
  "schemaVersion": 27,  
  "style": "dark",  
  "tags": [],  
  "templating": {  
    "list": [  
      {  
        "allValue": ".*",  
        "current": {  
          "selected": false,  
          "text": "All",  
          "value": "$__all"  
        },  
        "datasource": "prometheus",  
        "definition": "label_values(resource)",  
        "description": null,  
        "error": null,  
        "hide": 0,  
        "includeAll": true,  
        "label": null,  
        "multi": true,  
        "name": "resource",  
        "options": [],  
        "query": {  
          "query": "label_values(resource)",  
          "refId": "StandardVariableQuery"  
        },  
        "refresh": 2,  
        "regex": ".*",  
        "skipUrlSync": false,  
        "sort": 1,  
        "tagValuesQuery": "",  
        "tags": [],  
        "tagsQuery": "",  
        "type": "query",  
        "useTags": false  
      },  
      {  
        "allValue": ".*",  
        "current": {  
          "selected": false,  
          "text": "All",  
          "value": "$__all"  
        },  
        "datasource": "prometheus",  
        "definition": "label_values(operation)",  
        "description": null,  
        "error": null,  
        "hide": 0,  
        "includeAll": true,  
        "label": null,  
        "multi": true,  
        "name": "operation",  
        "options": [],  
        "query": {  
          "query": "label_values(operation)",  
          "refId": "StandardVariableQuery"  
        },  
        "refresh": 2,  
        "regex": "",  
        "skipUrlSync": false,  
        "sort": 1,  
        "tagValuesQuery": "",  
        "tags": [],  
        "tagsQuery": "",  
        "type": "query",  
        "useTags": false  
      }  
    ]  
  },  
  "time": {  
    "from": "now-5m",  
    "to": "now"  
  },  
  "timepicker": {  
    "refresh_intervals": [  
      "5s",  
      "10s",  
      "30s",  
      "1m",  
      "5m",  
      "15m",  
      "30m",  
      "1h",  
      "2h",  
      "1d"  
    ]  
  },  
  "timezone": "",  
  "title": "Apache APISIX Ingress Controller",  
  "uid": "cJp7SjHnk",  
  "version": 1  
}

其他

参考链接: apisix-apache.org dashboard podMonitor和serviceMonitor