分享

简单4步,利用Prometheus Operator实现自定义指标监控

 可口可爱吧 2021-01-31

在过去的文章中,我们花了相当大的篇幅来聊关于监控的话题。这是因为当你正在管理Kubernetes集群时,一切都会以极快的速度发生变化。因此有一个工具来监控集群的健康状态和资源指标极为重要。

Rancher 2.5中,我们引入了基于Prometheus Operator的新版监控,它可以提供Prometheus以及相关监控组件的原生Kubernetes部署和管理。Prometheus Operator可以让你监控集群节点、Kubernetes组件和应用程序工作负载的状态和进程。同时,它还能够通过Prometheus收集的指标来定义告警并且创建自定义仪表盘,通过Grafana可以轻松地可视化收集到的指标。你可以访问下列链接获取更多关于新版监控组件的细节:

新版本站长交易的监控也采用prometheus-adapter,开发人员可以利用其基于自定义指标和HPA扩展他们的工作负载。

在本文中,我们将探索如何利用Prometheus Operator来抓取自定义指标并利用这些指标进行高级工作负载管理。

安装Prometheus

Rancher 2.5中安装Prometheus极为简单。仅需访问Cluster Explorer -> Apps并安装rancher-monitoring即可。

你需要了解以下默认设置:

prometheus-adapter将会作为chart安装的一部分启用

ServiceMonitorNamespaceSelector 留为空,允许 Prometheus 在所有命名空间中收集 ServiceMonitors

部署工作负载

现在让我们部署一个从应用层暴露自定义指标的示例工作负载。该工作负载暴露了一个简单的应用程序,该应用程序已经使用Prometheus client_golang库进行了检测,并在/metric端点上提供了一些自定义指标。

它有两个指标:

http_requests_total

http_request_duration_seconds

以下manifest部署了工作负载、相关服务以及访问该工作负载的ingress:

apiVersion: apps/v1kind: Deploymentmetadata:

  labels:

    app.kubernetes.io/name: prometheus-example-app

  name: prometheus-example-appspec:

  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: v1kind: Servicemetadata:

  name: prometheus-example-app

  labels:

    app.kubernetes.io/name: prometheus-example-appspec:

  selector:

    app.kubernetes.io/name: prometheus-example-app

  ports:

    - protocol: TCP

      port: 8080

      targetPort: 8080

      name: web---apiVersion: networking.k8s.io/v1beta1kind: Ingressmetadata:

    name: prometheus-example-appspec:

    rules:

    - host: hpa.demo

      http:

        paths:

        - path: /

          backend:

            serviceName: prometheus-example-app

            servicePort: 8080

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多