ITPub博客

首页 > 数据库 > Oracle > 简单4步,利用Prometheus Operator实现自定义指标监控

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

Oracle 作者:勾魂大猩猩 时间:2021-01-31 19:10:28 0 删除 编辑

在过去的文章中,我们花了相当大的篇幅来聊关于监控的话题。这是因为当你正在管理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

 


来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/69993970/viewspace-2754880/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2021-01-26

  • 博文量
    8
  • 访问量
    4506