展开菜单
首页 精品内容 本月促销 装机必备 Windows PDF教程 macOS软件 IOS软件 Android AI 专题
全部分类

当前位置:

首页 > 系统应用 > 简单4步,利用PrometheusOperator实现自定义指标监控

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

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

本文目录

    本文来自Rancher Labs

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

    在Rancher 2.5中,新版监控基于Prometheus Operator引入,能提供Prometheus及相关监控组件的原生Kubernetes部署与管理。借助Prometheus Operator,你可对集群节点、Kubernetes组件以及应用程序工作负载的状态和进程进行监控。同时,它还能依据Prometheus收集的指标来定义告警,并创建自定义仪表盘,通过Grafana可轻松实现收集指标的可视化。以下是获取新版监控组件更多细节的链接:

    https://rancher.com/docs/rancher/v2.x/en/monitoring-alerting/v2.5/

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

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

    安装Prometheus

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

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

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

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

    安装完成后,我们可以从Cluster Explorer访问监控组件。

    部署工作负载

    现在让我们部署一个从应用层暴露自定义指标的示例工作负载。该工作负载暴露了一个简单的应用程序,该应用程序已经使用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),可以让我们声明性地定义如何监控一组动态服务。

    你可以访问以下链接查看完整的ServiceMonitor规范:

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

    现在,我们来部署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

    如你所见,现在用户可以在Rancher监控中浏览ServiceMonitor。

    不久之后,新的service monitor和服务相关联的pod应该会反映在Prometheus服务发现中。

    我们也能够在Prometheus中看到指标。

    部署Grafana仪表盘

    在Rancher 2.5中,监控可以让用户将Grafana仪表盘存储为cattle-dashboards命名空间中的ConfigMaps。

    用户或集群管理员现在可以在这一命名空间中添加更多的仪表盘以扩展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": {
    "a vg": 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": {
    "a vg": 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
    }

    现在,用户应该能够在Grafana中访问prometheus example app的仪表盘。

    自定义指标的HPA

    这一部分假设你已经将prometheus-adapter作为监控的一部分安装完毕了。实际上,在默认情况下,监控安装程序会安装prometheus-adapter。

    用户现在可以创建一个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:
    a verageValue: "5"
    type: A verageValue

    你可以查看以下链接获取关于HPA的更多信息:

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

    我们将使用自定义的http_requests_total指标来执行pod自动伸缩。

    现在我们可以生成一个样本负载来查看HPA的运行情况。我可以使用hey进行同样的操作。

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

    总 结

    在本文中,我们探讨了Rancher 2.5中新监控的灵活性。开发人员和集群管理员可以利用该堆栈来监控它们的工作负载,部署可视化,并利用Kubernetes内可用的高级工作负载管理功能。

    本站声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系bd@zhengruan.com
    作者最新文章
    系统应用
    相关文章 更多
    精品专题 更多
    装机必备

    正软商城装机必备专区,精选办公、浏览器、安全防护、影音播放、压缩解压、设计创作和系统工具等电脑常用正版软件,帮助用户快速完成新电脑软件配置。

    Windows

    正软商城Windows软件专区,汇集适用于Windows电脑的办公、设计、安全防护、影音播放、开发工具和系统优化软件,提供软件介绍、系统要求、正版授权及购买下载服务。

    PDF教程

    正软商城PDF教程频道提供PDF编辑、转换、合并、拆分、压缩及格式处理方法,同时介绍常用PDF软件和工具的使用技巧。

    macOS软件

    正软商城macOS软件专区,精选适用于Mac电脑的办公、设计、影音、效率、开发和系统工具,提供软件功能介绍、macOS兼容版本、正版授权及购买下载服务。

    IOS软件

    正软商城iOS软件专区,精选适用于iPhone和iPad的办公、学习、影音、设计、效率及AI应用,提供功能介绍、适用设备、系统要求和正版获取方式等信息。

    AI

    正软商城AI软件专区,汇集AI写作、AI绘画、AI视频、AI办公、AI编程、AI翻译、智能客服和数据分析等人工智能工具,提供功能介绍、适用平台、收费方式及正版购买信息。

    Mac软件 更多
    Aperty macOS版
    Aperty macOS版

    Aperty 是 Skylum 推出的 AI 人像修图软件,支持自然肤质修饰、瑕疵处理、面部与身体调整、预设及批量同步。

    火山引擎 网页版
    火山引擎 网页版

    火山引擎是字节跳动旗下企业级云与AI服务平台。聚焦大模型核心能力,依托字节自研豆包多模态大模型,凭借火山方舟一站式平台,提供模型精调、推理部署、智能应用搭建等全链路服务,结合高性能AI算力,助力各行业快速落地大模型数字化与智能化应用。

    立刻MV 网页版
    立刻MV 网页版

    立刻MV 面向音乐人、内容创作者和品牌团队,帮助用户低成本完成歌曲 MV、歌词视频、AI 分镜、图生视频与最终合成。

    蛙蛙写作 网页版
    蛙蛙写作 网页版

    蛙蛙写作 AI 创作工具,覆盖小说、剧本、文案,一键生成文稿,打通文字转视频全流程,高效解决创作难题。

    讯飞智作 网页版
    讯飞智作 网页版

    讯飞智作是一款基于语音合成技术、虚拟人驱动技术与数字人形象声音构建能力的 AI 数字人音视频创作平台。

    超级简历WonderCV 网页版
    超级简历WonderCV 网页版

    超级简历WonderCV是面向应届生和AI小白的智能求职平台,覆盖简历、面试与职业规划。

    音述AI 网页版
    音述AI 网页版

    音述AI,是一个以“用声音述说故事”为核心的 AI 音乐创作与声音分享社区。

    AionClaw macOS版
    AionClaw macOS版

    AionClaw 是可在桌面端运行的任务型 AI 助手,通过数字专家与技能市场组合办公、创作、数据和开发能力。

    Loomy macOS版
    Loomy macOS版

    Loomy 是科大讯飞推出的桌面 AI 助手,可通过对话、任务与工作目录协助处理办公、内容创作和资料整理。

    AirBuddy 3 macOS版
    AirBuddy 3 macOS版

    AirBuddy 3 是面向 macOS 的蓝牙外设增强工具,可集中查看 AirPods、Beats 与苹果设备电量,提供快速连接、播放控制、电量提醒、桌面小组件和多台 Mac 外设接力等功能。

    AirServer macOS版
    AirServer macOS版

    AirServer macOS版可把 Mac 转换为无线投屏接收端,通过 AirPlay 或 Google Cast 接收手机、平板和电脑画面,并支持多设备同时连接、高清镜像及会话录制,适合家庭娱乐、课堂教学、会议演示和应用展示。

    AnyDesk macOS版
    AnyDesk macOS版

    AnyDesk macOS版是一款适用于远程办公、设备维护和客户支持的远程桌面工具,可连接并操作异地计算机,支持文件传输、无人值守访问、会话权限控制及跨平台协作。

    WINDOWS 更多
    Aperty Windows版
    Aperty Windows版

    Aperty 是 Skylum 推出的 AI 人像修图软件,支持自然肤质修饰、瑕疵处理、面部与身体调整、预设及批量同步。

    火山引擎 网页版
    火山引擎 网页版

    火山引擎是字节跳动旗下企业级云与AI服务平台。聚焦大模型核心能力,依托字节自研豆包多模态大模型,凭借火山方舟一站式平台,提供模型精调、推理部署、智能应用搭建等全链路服务,结合高性能AI算力,助力各行业快速落地大模型数字化与智能化应用。

    立刻MV 网页版
    立刻MV 网页版

    立刻MV 面向音乐人、内容创作者和品牌团队,帮助用户低成本完成歌曲 MV、歌词视频、AI 分镜、图生视频与最终合成。

    蛙蛙写作 网页版
    蛙蛙写作 网页版

    蛙蛙写作 AI 创作工具,覆盖小说、剧本、文案,一键生成文稿,打通文字转视频全流程,高效解决创作难题。

    讯飞智作 网页版
    讯飞智作 网页版

    讯飞智作是一款基于语音合成技术、虚拟人驱动技术与数字人形象声音构建能力的 AI 数字人音视频创作平台。

    超级简历WonderCV 网页版
    超级简历WonderCV 网页版

    超级简历WonderCV是面向应届生和AI小白的智能求职平台,覆盖简历、面试与职业规划。

    音述AI 网页版
    音述AI 网页版

    音述AI,是一个以“用声音述说故事”为核心的 AI 音乐创作与声音分享社区。

    AionClaw Windows版
    AionClaw Windows版

    AionClaw 是可在桌面端运行的任务型 AI 助手,通过数字专家与技能市场组合办公、创作、数据和开发能力。

    Loomy Windows版
    Loomy Windows版

    Loomy 是科大讯飞推出的桌面 AI 助手,可通过对话、任务与工作目录协助处理办公、内容创作和资料整理。

    讯飞绘文 网页版
    讯飞绘文 网页版

    讯飞绘文网页版是科大讯飞推出的AI图文创作与内容运营工具,覆盖热点选题、文章生成、稿件校对、智能配图、排版发布和数据复盘等环节,适合自媒体创作者及内容团队在线使用。

    AirServer Windows版
    AirServer Windows版

    AirServer Windows版可把电脑变成AirPlay、Google Cast和Miracast无线投屏接收端,适合会议演示、课堂教学及家庭大屏分享。发送设备通常无需另装客户端,并可同时接收和智能排列多个镜像会话。

    AlwaysUp Windows版
    AlwaysUp Windows版

    AlwaysUp是一款面向Windows的系统服务注册与程序托管工具,可让普通应用、脚本及批处理在无人登录时随系统启动,并通过状态检测、异常重启、资源监控和邮件通知保障关键任务持续运行。