Prometheus告警系统alertmanager之邮件告警
Alertmanager主要用于接收Prometheus发送的告警信息,它支持丰富的告警通知渠道,并且可以对告警信息进行分组、抑制、静默。
在prometheus配置中配置alertmanager地址alerting: alertmanagers: - static_configs: - targets: # 这边配置alertmanager地址喝端口,alertmanager默认端口是9093 - 127.0.0.1:9093
编写报警规则rule_files:- "rules/*.yml"
# 创建rules目录mkdir rules
[root@localhost prometheus-2.8.1.linux-amd64]# cat rules/test.yml groups:- name: general rules: - alert: instance down # 可以在prometheus页面查看up,0表示instance已经down,也就是prometheus无法获取被监控端数据 ...
Prometheus标签管理
在Prometheus监控体系中,标签 label 是一个非常重要的参数,使用标准的标签有利于我们对整个集群进行控制管理,便于我们在复杂的环境中能够精确查询metrics。
标签管理honor_labels在之前,我们使用pushgateway上报监控数据,在shell脚本里面我们发送数据给pushgateway时,其实标签也一并发了出去。
在element那里,有2个exported_*开头的labels,其实就是我们定义的labels。
honor_labels主要用于解决prometheus server的label与exporter端用户自定义label冲突的问题。honor_labels默认是false,当出现冲突,会将冲突的标签以exported重新命名;当honor_labels为true,只保留用户自定义的label。
- job_name: 'pushgateway' honor_labels: true static_configs: - targets: ['localhost:9091','localhost:90 ...
Prometheus使用PushGateway上报数据采集
下载PushGateway地址:https://github.com/prometheus/pushgateway
启动PushGatewayPushGateway不需要安装的被监控的机器上,只需要安装在任意机器启动即可
tar zxvf pushgateway-1.0.1.linux-amd64.tar.gzcd pushgateway-1.0.1.linux-amd64./pushgateway
使用PushGateway上报采集数据首先先在prometheus.yml添加job,然后重新启动prometheus
- job_name: 'pushgateway' static_configs: - targets: ['localhost:9091','localhost:9092']
编写shell脚本监控机器内网延迟和丢包率
#!/bin/bashhostname=$(hostname | awk -F '.' '{print $1 ...
Prometheus监控磁盘
监控磁盘使用率磁盘使用率=100*(node_filesystem_size_bytes{mountpoint=”/“} - node_filesystem_free_bytes{mountpoint=”/“} )/node_filesystem_size_bytes{mountpoint=”/“}
predict_linear函数predict_linear函数可以对曲线变化速率进行计算,然后根据这个变化速度推测未来的变化走向。
predict_linear( node_filesystem_free_bytes{mountpoint=”/“}[1h],4*3600 ) < 0
上面的这个公式表示对过去1小时的曲线进行计算,然后推测未来4小时的趋势,可以通过 <0 来实现提前报警
Prometheus监控内存
内存是系统重要的指标之一,内存是监控必不可少的指标之一。
监控内存使用率内存使用率=100*(total-free-buffers-cached)/total
100*(node_memory_MemTotal_bytes-node_memory_MemFree_bytes-node_memory_Cached_bytes-node_memory_Buffers_bytes)/node_memory_MemTotal_bytes
Prometheus监控CPU
CPU是我们系统最重要的指标之一,它主要提供系统计算功能,所有CPU的状态能够反映了系统的健康状态,CPU是监控必不可少的指标之一。
CPU概念user time:cpu执行用户进程消耗的时间
system time:cpu在内核运行的时间
io wait:cpu在等待I/O操作完成的时间
idle time:系统处于空闲的时间
nice time:系统调整进程优先级的时间
lrq time:系统处理赢中断花费的时间
softlrq time:系统处理软中断花费的时间
steal time:被强制等待虚拟cpu时间
监控CPU使用率在上面8个CPU时间中,除了idle time反映的是CPU空闲时间,其余7个都包含在CPU使用时间里面,也就是CPU使用率=100*(1-idle time/CPU时间)
在之前我们已经部署了prometheus和node_exporter了,node_exporter需要部署在被监控端。
我们先查询 node_cpu_seconds_total ,这个可以统计cpu时间,因为是2核的,所以可以看到labels里面是有cpu=”0”和cpu=”1”标签的, ...
node_exporter安装和配置
下载地址:https://github.com/prometheus/node_exporter/releases
安装tar zxvf node_exporter-1.0.0-rc.0.linux-amd64.tar.gzcd node_exporter-1.0.0-rc.0.linux-amd64#运行./node_exporter
访问通过curl访问采集的数据
curl 192.168.1.114:9100/metrics
在prometheus.yml配置node_exporter目标地址,使得prometheus搜集到node_exporter采集的数据
static_configs: - targets: ['localhost:9090','192.168.1.114:9100']
Prometheus安装部署
Prometheus基本概念Prometheus是使用Go语言开发的一款开源监控报警系统,它存储的是时序数据,简单的说就是按照相同的名称盒标签以时间维度存储连续的数据集合
时序(time series)以名称(metric)和一组key/value标签定义
Prometheus架构Prometheus通过HTTP协议周期性抓取被监控组件的状态,任意组件只要提供对应的HTTP接口就可以接入监控。输出被监控组件信息的HTTP接口叫做exporter,目前互联网已经有很多exporter可以直接使用,比如node、nginx、mysql等等。
安装prometheus下载地址:https://github.com/prometheus/prometheus/releases
下载 prometheus-2.8.1.linux-amd64.tar.gz 二进制包
#解压tar zxvf prometheus-2.8.1.linux-amd64.tar.gz#进入目录cd prometheus-2.8.1.linux-amd64#启动./prometheus --config.fil ...
Istio-Kiali
Kiali为网格管理和可观察性提供了良好的用户体验的可视化工具。
Kiali访问查看Kiali服务
kubectl get pods -n istio-systemkubectl get svc -n istio-system
修改kiali的svc类型为NodePort,修改type字段为type: NodePort
kubectl edit svc kiali -n istio-system
通过浏览器访问,username和password均为admin
登录后进入首页,Overview页面展示了所有名称空间下的应用数量、服务流量、配置状态以及监控检查状态
点击一个名称空间进入Applications页面,kiali独有的概念
下面就是Workloads页面,它展示了各个名称空间下的pods的状态
Services对应的就是Kubernetes中的svc
最后Istio Config页面展示了服务网格下的各个类型的资源配置信息
给bookinfo注入流量while true; do curl http://192.168.1.110:31514& ...
Istio-Egress发起HTTPS请求
创建sleep客户端apiVersion: v1kind: ServiceAccountmetadata: name: sleep---apiVersion: v1kind: Servicemetadata: name: sleep labels: app: sleepspec: ports: - port: 80 name: http selector: app: sleep---apiVersion: apps/v1kind: Deploymentmetadata: name: sleepspec: selector: matchLabels: app: sleep template: metadata: labels: app: sleep spec: serviceAccountName: sleep containers: - name: sleep image: pstauffer/curl ...