在Linux系统部署prometheus监控(2) --配置规则

首先确保服务开启

 vim node_rules.yml

注意:编写这个文件注意不要用tab键,只用空格来缩进

 访问localhost:9090/rules

 如果relod发现rules没有生效,可以重启服务

netstate -lntp |grep prom

kill -9 进程号

./prometheus &

再次访问

cpu > 80

100-(avg(irate(node_cup_seconds_total{mode='idle'}[5m]))by(instance)*100) > 80

内存

100 - (node_memory_MemFree_bytes + node_memory_Cached_bytes + node_memory_Buffers_bytes) / node_memory_MemTotal_bytes * 100
 

 

 disk

100 - (((node_filesystem_size_bytes{fstype=~"xfs|ext4"} - node_filesystem_free_bytes{fstype=~"xfs|ext4"}) / node_filesystem_size_bytes{fstype=~"xfs|ext4"}) * 100)

 节点状态

up metric

监视特定节点状态的另一个有用指标:up ,如果实例是健康的,度量就被设置为1 ,失败返回 - 或 0

用来监控节点是否健康,如果健康则为1,不健康的话说明该服务器node服务可能停了,也可能该节点down了需要立马检查

- alert: NodeDown

  expr: node_up == 0

  for: 0m

  labels: 

     severity: serious

  annotations: 

       summary: "NodeDown"

下面都一样的模板配置即可

MysqlDown

RedisDown

NginxDown

JavaDown

 

 

groups: 
- name: Hoststate-alert()
  rules: 
  - alert: RedisDown
    expr: up == 0
    for: 0m
    labels: 
      status: critical
    annotations: 
      summary: "Redisdown"
      description: "Redis instance is down"
  - alert: MysqlDown
    expr: up == 0
    for: 0m
    labels: 
      status: critical
    annotations: 
      summary: "Msqldown"
      description: "Mysql instance is down"
  - alert: NginxDown
    expr: up == 0
    for: 0m
    labels: 
      status: critical
    annotations: 
      summary: "Nginxdown"
      description: "Nginx instance is down"
  - alert: NodeDown
    expr: up == 0
    for: 0m
    labels: 
      status: critical
    annotations: 
      summary: "Nodedown"
      description: "Node instance is down"
  - alert: JavaDown
    expr: up == 0
    for: 0m
    labels: 
      status: critical
    annotations: 
      summary: "Javadown"
      description: "Java instance is down"
  - alert: CPUusage
    expr: 100-(avg(irate(node_cpu_seconds_total{mode='idle'}[5m]))by(instance) * 100) > 80
    for: 5m
    labels: 
      status: critical
    annotations: 
      summary: "{{$labels.mountpoint}} CPU usage high"
      description: "{{$labels.mountpoint}} CPU usage above 80% ( current usage:{{$value}})"
  - alert: Memoryusage
    expr: 100 - (node_memory_MemFree_bytes + node_memory_Cached_bytes + node_memory_Buffers_bytes)/ node_memory_MemTotal_bytes * 100 > 80
    for: 5m
    labels: 
      status: critical
    annotations: 
      summary: " Memory usage high"
      description: "Memory usage above 80%.( current usage:{{$value}})"
  - alert: Diskusage
    expr: 100 - (((node_filesystem_size_bytes{fstype=~"xfs|ext4"} - node_filesystem_free_bytes{fstype=~"xfs|ext4"}) / node_filesystem_size_bytes{fstype=~"xfs|ext4"}) * 100)  > 80
    for: 5m
    labels: 
      status: critical
    annotations: 
      summary: "Disk usage high"
      description: "Disk usage above 80% ( current usage:{{$value}})"
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要在Linux部署Prometheus,可以按照以下步骤进行操作: 1. 首先,确保你的Linux系统已经安装了Docker和Docker Compose。如果没有安装,可以根据系统版本执行相应的安装命令。 2. 创建一个目录来存储Prometheus配置文件和数据。可以使用以下命令创建一个目录: ``` mkdir prometheus cd prometheus ``` 3. 在创建的目录中,创建一个名为`docker-compose.yml`的文件,并将以下内容粘贴到文件中: ```yaml version: '3' services: prometheus: image: prom/prometheus ports: - 9090:9090 volumes: - ./prometheus.yml:/etc/prometheus/prometheus.yml - ./data:/prometheus command: - '--config.file=/etc/prometheus/prometheus.yml' - '--storage.tsdb.path=/prometheus' ``` 这个`docker-compose.yml`文件使用Prometheus的官方Docker镜像,并将端口映射到主机的9090端口。配置文件`prometheus.yml`和数据将存储在当前目录下的`prometheus.yml`和`data`子目录中。 4. 创建一个名为`prometheus.yml`的文件,并将以下内容粘贴到文件中: ```yaml global: scrape_interval: 15s scrape_configs: - job_name: 'prometheus' static_configs: - targets: ['localhost:9090'] ``` 这个配置文件指定了Prometheus的抓取间隔和要监控的目标,这里只监控Prometheus本身。 5. 保存并退出`docker-compose.yml`和`prometheus.yml`文件。 6. 运行以下命令来启动Prometheus容器: ``` docker-compose up -d ``` 这将以后台模式启动Prometheus容器。 7. 访问`http://localhost:9090`即可在浏览器中访问Prometheus的Web界面。 这样,你就成功在Linux部署Prometheus。你可以根据需要修改`prometheus.yml`文件来监控不同的目标。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值