日本综合一区二区|亚洲中文天堂综合|日韩欧美自拍一区|男女精品天堂一区|欧美自拍第6页亚洲成人精品一区|亚洲黄色天堂一区二区成人|超碰91偷拍第一页|日韩av夜夜嗨中文字幕|久久蜜综合视频官网|精美人妻一区二区三区

RELATEED CONSULTING
相關咨詢
選擇下列產品馬上在線溝通
服務時間:8:30-17:00
你可能遇到了下面的問題
關閉右側工具欄

新聞中心

這里有您想知道的互聯(lián)網營銷解決方案
如何利用PrometheusOperator實現(xiàn)自定義指標監(jiān)控

如何利用Prometheus Operator實現(xiàn)自定義指標監(jiān)控,很多新手對此不是很清楚,為了幫助大家解決這個難題,下面小編將為大家詳細講解,有這方面需求的人可以來學習下,希望你能有所收獲。

創(chuàng)新互聯(lián)-專業(yè)網站定制、快速模板網站建設、高性價比全州網站開發(fā)、企業(yè)建站全套包干低至880元,成熟完善的模板庫,直接使用。一站式全州網站制作公司更省心,省錢,快速模板網站建設找我們,業(yè)務覆蓋全州地區(qū)。費用合理售后完善,10余年實體公司更值得信賴。

在過去的文章中,我們花了相當大的篇幅來聊關于監(jiān)控的話題。這是因為當你正在管理Kubernetes集群時,一切都會以極快的速度發(fā)生變化。因此有一個工具來監(jiān)控集群的健康狀態(tài)和資源指標極為重要。

在Rancher 2.5中,我們引入了基于Prometheus Operator的新版監(jiān)控,它可以提供Prometheus以及相關監(jiān)控組件的原生Kubernetes部署和管理。Prometheus Operator可以讓你監(jiān)控集群節(jié)點、Kubernetes組件和應用程序工作負載的狀態(tài)和進程。同時,它還能夠通過Prometheus收集的指標來定義告警并且創(chuàng)建自定義儀表盤,通過Grafana可以輕松地可視化收集到的指標。

新版本的監(jiān)控也采用prometheus-adapter,開發(fā)人員可以利用其基于自定義指標和HPA擴展他們的工作負載。

我們將探索如何利用Prometheus Operator來抓取自定義指標并利用這些指標進行高級工作負載管理。

安裝Prometheus

在Rancher 2.5中安裝Prometheus極為簡單。僅需訪問Cluster Explorer -> Apps并安裝rancher-monitoring即可。

如何利用Prometheus Operator實現(xiàn)自定義指標監(jiān)控

你需要了解以下默認設置:

  • prometheus-adapter將會作為chart安裝的一部分啟用

  • ServiceMonitorNamespaceSelector 留為空,允許 Prometheus 在所有命名空間中收集 ServiceMonitors

如何利用Prometheus Operator實現(xiàn)自定義指標監(jiān)控

安裝完成后,我們可以從Cluster Explorer訪問監(jiān)控組件。

如何利用Prometheus Operator實現(xiàn)自定義指標監(jiān)控

部署工作負載

現(xiàn)在讓我們部署一個從應用層暴露自定義指標的示例工作負載。該工作負載暴露了一個簡單的應用程序,該應用程序已經使用Prometheus client_golang庫進行了檢測,并在/metric端點上提供了一些自定義指標。

它有兩個指標:

  • http_requests_total

  • http_request_duration_seconds

以下manifest部署了工作負載、相關服務以及訪問該工作負載的ingress:

apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app.kubernetes.io/name: prometheus-example-app
  name: prometheus-example-app
spec:
  replicas: 1
  selector:
    matchLabels:
      app.kubernetes.io/name: prometheus-example-app
  template:
    metadata:
      labels:
        app.kubernetes.io/name: prometheus-example-app
    spec:
      containers:
      - name: prometheus-example-app
        image: gmehta3/demo-app:metrics
        ports:
        - name: web
          containerPort: 8080
---
apiVersion: v1
kind: Service
metadata:
  name: prometheus-example-app
  labels:
    app.kubernetes.io/name: prometheus-example-app
spec:
  selector:
    app.kubernetes.io/name: prometheus-example-app
  ports:
    - protocol: TCP
      port: 8080
      targetPort: 8080
      name: web
---
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
    name: prometheus-example-app
spec:
    rules:
    - host: hpa.demo
      http:
        paths:
        - path: /
          backend:
            serviceName: prometheus-example-app
            servicePort: 8080

部署ServiceMonitor

ServiceMonitor是一個自定義資源定義(CRD),可以讓我們聲明性地定義如何監(jiān)控一組動態(tài)服務。

你可以訪問以下鏈接查看完整的ServiceMonitor規(guī)范:

https://github.com/prometheus-operator/prometheus-operator/blob/master/Documentation/api.md#servicemonitor

現(xiàn)在,我們來部署ServiceMonitor,Prometheus用它來收集組成prometheus-example-app Kubernetes服務的pod。

kind: ServiceMonitor
metadata:
  name: prometheus-example-app
spec:
  selector:
    matchLabels:
      app.kubernetes.io/name: prometheus-example-app
  endpoints:
  - port: web

如你所見,現(xiàn)在用戶可以在Rancher監(jiān)控中瀏覽ServiceMonitor。

如何利用Prometheus Operator實現(xiàn)自定義指標監(jiān)控

不久之后,新的service monitor和服務相關聯(lián)的pod應該會反映在Prometheus服務發(fā)現(xiàn)中。

如何利用Prometheus Operator實現(xiàn)自定義指標監(jiān)控

我們也能夠在Prometheus中看到指標。

如何利用Prometheus Operator實現(xiàn)自定義指標監(jiān)控

部署Grafana儀表盤

在Rancher 2.5中,監(jiān)控可以讓用戶將Grafana儀表盤存儲為cattle-dashboards命名空間中的ConfigMaps。

用戶或集群管理員現(xiàn)在可以在這一命名空間中添加更多的儀表盤以擴展Grafana的自定義儀表盤。

Dashboard ConfigMap Example
apiVersion: v1
kind: ConfigMap
metadata:
  name: prometheus-example-app-dashboard
  namespace: cattle-dashboards
  labels:
    grafana_dashboard: "1"
data:
  prometheus-example-app.json: |
    {
    "annotations": {
        "list": [
        {
            "builtIn": 1,
            "datasource": "-- Grafana --",
            "enable": true,
            "hide": true,
            "iconColor": "rgba(0, 211, 255, 1)",
            "name": "Annotations & Alerts",
            "type": "dashboard"
        }
        ]
    },
    "editable": true,
    "gnetId": null,
    "graphTooltip": 0,
    "links": [],
    "panels": [
        {
        "aliasColors": {},
        "bars": false,
        "dashLength": 10,
        "dashes": false,
        "datasource": null,
        "fieldConfig": {
            "defaults": {
            "custom": {}
            },
            "overrides": []
        },
        "fill": 1,
        "fillGradient": 0,
        "gridPos": {
            "h": 9,
            "w": 12,
            "x": 0,
            "y": 0
        },
        "hiddenSeries": false,
        "id": 2,
        "legend": {
            "avg": false,
            "current": false,
            "max": false,
            "min": false,
            "show": true,
            "total": false,
            "values": false
        },
        "lines": true,
        "linewidth": 1,
        "nullPointMode": "null",
        "percentage": false,
        "pluginVersion": "7.1.5",
        "pointradius": 2,
        "points": false,
        "renderer": "flot",
        "seriesOverrides": [],
        "spaceLength": 10,
        "stack": false,
        "steppedLine": false,
        "targets": [
            {
            "expr": "rate(http_requests_total{code=\"200\",service=\"prometheus-example-app\"}[5m])",
            "instant": false,
            "interval": "",
            "legendFormat": "",
            "refId": "A"
            }
        ],
        "thresholds": [],
        "timeFrom": null,
        "timeRegions": [],
        "timeShift": null,
        "title": "http_requests_total_200",
        "tooltip": {
            "shared": true,
            "sort": 0,
            "value_type": "individual"
        },
        "type": "graph",
        "xaxis": {
            "buckets": null,
            "mode": "time",
            "name": null,
            "show": true,
            "values": []
        },
        "yaxes": [
            {
            "format": "short",
            "label": null,
            "logBase": 1,
            "max": null,
            "min": null,
            "show": true
            },
            {
            "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": null,
        "description": "",
        "fieldConfig": {
            "defaults": {
            "custom": {}
            },
            "overrides": []
        },
        "fill": 1,
        "fillGradient": 0,
        "gridPos": {
            "h": 8,
            "w": 12,
            "x": 0,
            "y": 9
        },
        "hiddenSeries": false,
        "id": 4,
        "legend": {
            "avg": false,
            "current": false,
            "max": false,
            "min": false,
            "show": true,
            "total": false,
            "values": false
        },
        "lines": true,
        "linewidth": 1,
        "nullPointMode": "null",
        "percentage": false,
        "pluginVersion": "7.1.5",
        "pointradius": 2,
        "points": false,
        "renderer": "flot",
        "seriesOverrides": [],
        "spaceLength": 10,
        "stack": false,
        "steppedLine": false,
        "targets": [
            {
            "expr": "rate(http_requests_total{code!=\"200\",service=\"prometheus-example-app\"}[5m])",
            "interval": "",
            "legendFormat": "",
            "refId": "A"
            }
        ],
        "thresholds": [],
        "timeFrom": null,
        "timeRegions": [],
        "timeShift": null,
        "title": "http_requests_total_not_200",
        "tooltip": {
            "shared": true,
            "sort": 0,
            "value_type": "individual"
        },
        "type": "graph",
        "xaxis": {
            "buckets": null,
            "mode": "time",
            "name": null,
            "show": true,
            "values": []
        },
        "yaxes": [
            {
            "format": "short",
            "label": null,
            "logBase": 1,
            "max": null,
            "min": null,
            "show": true
            },
            {
            "format": "short",
            "label": null,
            "logBase": 1,
            "max": null,
            "min": null,
            "show": true
            }
        ],
        "yaxis": {
            "align": false,
            "alignLevel": null
        }
        }
    ],
    "schemaVersion": 26,
    "style": "dark",
    "tags": [],
    "templating": {
        "list": []
    },
    "time": {
        "from": "now-15m",
        "to": "now"
    },
    "timepicker": {
        "refresh_intervals": [
        "5s",
        "10s",
        "30s",
        "1m",
        "5m",
        "15m",
        "30m",
        "1h",
        "2h",
        "1d"
        ]
    },
    "timezone": "",
    "title": "prometheus example app",
    "version": 1
    }

現(xiàn)在,用戶應該能夠在Grafana中訪問prometheus example app的儀表盤。

如何利用Prometheus Operator實現(xiàn)自定義指標監(jiān)控

自定義指標的HPA

這一部分假設你已經將prometheus-adapter作為監(jiān)控的一部分安裝完畢了。實際上,在默認情況下,監(jiān)控安裝程序會安裝prometheus-adapter。

用戶現(xiàn)在可以創(chuàng)建一個HPA spec,如下所示:

apiVersion: autoscaling/v2beta2
kind: HorizontalPodAutoscaler
metadata:
  name: prometheus-example-app-hpa
spec:
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: prometheus-example-app
  minReplicas: 1
  maxReplicas: 5
  metrics:
  - type: Object
    object:
        describedObject:
            kind: Service
            name: prometheus-example-app
        metric:
            name: http_requests
        target:
            averageValue: "5"
            type: AverageValue

你可以查看以下鏈接獲取關于HPA的更多信息:

https://kubernetes.io/docs/tasks/run-application/horizontal-pod-autoscale/

我們將使用自定義的http_requests_total指標來執(zhí)行pod自動伸縮。

如何利用Prometheus Operator實現(xiàn)自定義指標監(jiān)控

現(xiàn)在我們可以生成一個樣本負載來查看HPA的運行情況。我可以使用hey進行同樣的操作。

hey -c 10 -n 5000 http://hpa.demo

如何利用Prometheus Operator實現(xiàn)自定義指標監(jiān)控

開發(fā)人員和集群管理員可以利用該堆棧來監(jiān)控它們的工作負載,部署可視化,并利用Kubernetes內可用的高級工作負載管理功能。

看完上述內容是否對您有幫助呢?如果還想對相關知識有進一步的了解或閱讀更多相關文章,請關注創(chuàng)新互聯(lián)行業(yè)資訊頻道,感謝您對創(chuàng)新互聯(lián)的支持。


網站題目:如何利用PrometheusOperator實現(xiàn)自定義指標監(jiān)控
網站URL:http://www.dlmjj.cn/article/psogdj.html