• 利用grafana&prometheus 快速配置 k8s & 主机监控


    系列文章目录

    1、使用helm快速安装 grafana&prometheus
    2、利用grafana&prometheus 快速配置 k8s & 主机监控
    3、grafana&prometheus 快速配置报警规则及报警接收



    前言

    请先务必参照helm安装grafana教程,准备以上学习内容。
    没有学习本课之前你可能会感觉的制作一个主机监控/k8s监控,监控面板非常耗时,即使别人提供好数据参数,那么组织聚合展示也费劲。学习完毕本课程之后感觉这是一件非常简单的事情。

    设置k8s服务面板

    点击Dashboard在这里插入图片描述
    点击下拉箭头
    在这里插入图片描述
    点击导入dashborad
    在这里插入图片描述
    这里点击设置3119
    在这里插入图片描述
    然后选择prometheus数据源
    在这里插入图片描述
    然后点击导入即可
    在这里插入图片描述

    设置node服务面板

    下载对应export进程
    在这里插入图片描述
    启动服务

     wget https://github.com/prometheus/node_exporter/releases/download/v1.3.1/node_exporter-1.3.1.linux-amd64.tar.gz
    tar xvf node_exporter-1.3.1.linux-amd64.tar.gz
    cd node_exporter-1.3.1.linux-amd64
    nohup ./node_exporter --web.listen-address=":8058" &
    
    • 1
    • 2
    • 3
    • 4

    配置node_exporter
    由于helm install之前安装没有下载源码,所以我们这次需要下载源码,然后解压更改配置后重新配置生效。

    helm pull apphub/prometheus
    tar xvf prometheus-10.4.0.tgz
    cd prometheus/
    vim values.yaml
    #追加以下行
          - job_name: 'host_monitor'
            static_configs:
            - targets: ['10.74.175.24:8058']
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8

    更新配置生效

    helm upgrade my .
    
    • 1

    执行效果

    Release "my" has been upgraded. Happy Helming!
    NAME: my
    LAST DEPLOYED: Sat Jun 25 13:09:55 2022
    NAMESPACE: default
    STATUS: deployed
    REVISION: 2
    TEST SUITE: None
    NOTES:
    The Prometheus server can be accessed via port 80 on the following DNS name from within your cluster:
    my-prometheus-server.default.svc.cluster.local
    
    
    Get the Prometheus server URL by running these commands in the same shell:
      export POD_NAME=$(kubectl get pods --namespace default -l "app=prometheus,component=server" -o jsonpath="{.items[0].metadata.name}")
      kubectl --namespace default port-forward $POD_NAME 9090
    
    
    The Prometheus alertmanager can be accessed via port 80 on the following DNS name from within your cluster:
    my-prometheus-alertmanager.default.svc.cluster.local
    
    
    Get the Alertmanager URL by running these commands in the same shell:
      export POD_NAME=$(kubectl get pods --namespace default -l "app=prometheus,component=alertmanager" -o jsonpath="{.items[0].metadata.name}")
      kubectl --namespace default port-forward $POD_NAME 9093
    #################################################################################
    ######   WARNING: Pod Security Policy has been moved to a global property.  #####
    ######            use .Values.podSecurityPolicy.enabled with pod-based      #####
    ######            annotations                                               #####
    ######            (e.g. .Values.nodeExporter.podSecurityPolicy.annotations) #####
    #################################################################################
    
    
    The Prometheus PushGateway can be accessed via port 9091 on the following DNS name from within your cluster:
    my-prometheus-pushgateway.default.svc.cluster.local
    
    
    Get the PushGateway URL by running these commands in the same shell:
      export POD_NAME=$(kubectl get pods --namespace default -l "app=prometheus,component=pushgateway" -o jsonpath="{.items[0].metadata.name}")
      kubectl --namespace default port-forward $POD_NAME 9091
    
    For more information on running Prometheus, visit:
    https://prometheus.io/
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42

    更改 prometheus 服务暴露方式:参照更改 grafana 服务暴露方式,最后我们通过NodePort方式可进行Prometheus服务访问。
    在这里插入图片描述
    查看Node exporter是否生效
    在这里插入图片描述
    如果这里有host_monitor里显示up表示启动起来了。
    重新配置Node Port 的Dashboard信息。
    在这里插入图片描述
    在这里插入图片描述
    这里填写9276即可。
    一起感受一下grafana的界面之美:
    在这里插入图片描述
    感觉grafana之所以如此流行离不开,它有现成丰富的Dashborad仪表盘可以选择。
    https://grafana.com/grafana/dashboards/
    这里有数千个精美的仪表可以选择。

  • 相关阅读:
    FPGA时序分析
    百度编辑器 Ueditor 视频上传时 目录创建失败 解决办法
    第十五届蓝桥杯物联网试题(省赛)
    C++11常用新特性——右值引用&&
    表名注解/主键注解/字段注解/乐观锁注解[MyBatis-Plus系列] - 第486篇
    wpf devexpress Property Gird管理集合属性
    3. 判断数组的方式有哪些?
    月入3w的大二学生告诉你:副业真的没有那么难搞
    【Java八股文总结】之计算机网络
    再获5G RedCap能力认证!宏电5G RedCap工业智能网关通过中国联通5G物联网OPENLAB开放实验室测试验证
  • 原文地址:https://blog.csdn.net/e421083458/article/details/125458975