当前位置: 首页 > article >正文

prometheus监控windows主机

本文介绍通过powershell脚本部署windows_exporter并把指标展示在grafana上

1.windows_exporter下载

提前需要在C盘创建exporter_dir目录和logs\node_exporter.log文件

链接:https://pan.baidu.com/s/1wxGpBD_MJFPa942A6mbONQ
提取码:gffo

将下载好的windows_exporter.exe放到C:\exporter_dir下

2.部署脚本

# 文件路径:C:\node_exporter_windows.ps1
#!/bin/bash
param(
    [Parameter()]
    [String]$operateType
)

$LogFile = "C:\logs\node_exporter.log"
$ExporterDir = "C:\exporter_dir"


function PrintLog($log)
{
    $CurDate = Get-Date
    $LogContent = "[$CurDate] [$operateType] [$log]"
    Tee-Object -FilePath $LogFile -InputObject $LogContent -Append
}

function Prepare()
{
    New-Item -Path "C:\logs" -ItemType "directory"
}

function StopNodeExporter()
{
    PrintLog "Start stop node exporter..."
    Get-Process windows_exporter* | Stop-Process
    PrintLog "Finished stop node exporter..."
}

function StartNodeExporter()
{
    PrintLog "Start deploy node exporter..."
    $FilePath = $ExporterDir + "\windows_exporter.exe"
    Start-Process -WindowStyle hidden -FilePath $FilePath --web.listen-address=:49150
    PrintLog "Finished deploy node exporter..."
}

function Install()
{
    PrintLog "Start install node exporter..."
    Prepare
    StopNodeExporter
    StartNodeExporter
    PrintLog "Finished install node exporter..."
}

function Uninstall()
{
    PrintLog "Start uninstall node exporter..."
    StopNodeExporter
    Remove-Item -Path $ExporterDir -Recurse
    PrintLog "Finished uninstall node exporter..."
}

function Main()
{
    If ($operateType -eq "install")
    {
        Install
    }
    ELSEIF($operateType -eq "uninstall")
    {
        Uninstall
    }
}

Main

3.启动windows_exporter

打开电脑powershell执行以下命令

# 启动
C:\node_exporter_windows.ps1 install
# 查看是否启动成功
PS C:\Users\xxx> Get-Process windows_exporter*

Handles  NPM(K)    PM(K)      WS(K)     CPU(s)     Id  SI ProcessName
-------  ------    -----      -----     ------     --  -- -----------
    361      22    28784      30028              4836   2 windows_exporter

4.prometheus配置

# 采集项配置
- job_name: 'node-exporter'
    honor_labels: true
    consul_sd_configs:
      - server: 'xx.xx.xx.xx:8500' # 配置consul服务发现
        services: [ ]
    relabel_configs:
      - source_labels: [ __meta_consul_tags ]
        regex: .*node-exporter.*
        action: keep
      - regex: __meta_consul_service_metadata_(.+)
        action: labelmap![请添加图片描述](https://i-blog.csdnimg.cn/direct/bea5f7f5747a4acf9b36aab484f17a42.png)

# 告警规则配置
# cpu
- alert: vhost-default
    annotations:
      description: windows CPU空闲不足20%
      summary: 'windows CPU空闲不足20%,value: {{ $value | printf "%.2f" }}%'
    expr: avg by (instance) (rate(windows_cpu_time_total{mode="idle"}[1m])) * 100<20
    for: 2m
    labels:
      prom_id: '59'
      rule_type: cpu
      rule_value: '20'
      severity: warning
- alert: vhost-default
    annotations:
      description: windows CPU空闲不足10%
      summary: 'windows CPU空闲不足10%,value: {{ $value | printf "%.2f" }}%'
    expr: avg by (instance) (rate(windows_cpu_time_total{mode="idle"}[1m])) * 100<10
    for: 2m
    labels:
      prom_id: '58'
      rule_type: cpu
      rule_value: '10'
      severity: critical
- alert: vhost-default
    annotations:
      description: windows CPU空闲不足5%
      summary: 'windows CPU空闲不足5%,value: {{ $value | printf "%.2f" }}%'
    expr: avg by (instance) (rate(windows_cpu_time_total{mode="idle"}[1m])) * 100<5
    for: 1m
    labels:
      prom_id: '112'
      rule_type: cpu
      rule_value: '5'
      severity: emergency
# 内存
- alert: vhost-default
    annotations:
      description: windows主机内存不足20%
      summary: windows主机内存不足20%
    expr: (windows_os_physical_memory_free_bytes / windows_cs_physical_memory_bytes)
      * 100<20
    for: 3m
    labels:
      prom_id: '114'
      rule_type: memory
      rule_value: '20'
      severity: warning
- alert: vhost-default
    annotations:
      description: windows内存可用空间不足10%
      summary: windows内存可用空间不足10%
    expr: (windows_os_physical_memory_free_bytes / windows_cs_physical_memory_bytes)
      * 100<10
    for: 30s
    labels:
      prom_id: '61'
      rule_type: memory
      rule_value: '10'
      severity: critical
- alert: vhost-default
    annotations:
      description: windows内存可用空间不足5%
      summary: windows内存可用空间不足5%
    expr: (windows_os_physical_memory_free_bytes / windows_cs_physical_memory_bytes)
      * 100<5
    for: 30s
    labels:
      prom_id: '60'
      rule_type: memory
      rule_value: '5'
      severity: emergency
# 磁盘
- alert: vhost-default
    annotations:
      description: windows磁盘可用空间不足20%
      summary: windows磁盘可用空间不足20%
    expr: 100 * ((windows_logical_disk_free_bytes / 1024 / 1024) / (windows_logical_disk_size_bytes
      / 1024 / 1024))<20
    for: 2m
    labels:
      prom_id: '64'
      rule_type: disk
      rule_value: '20'
      severity: warning
- alert: vhost-default
    annotations:
      description: windows磁盘可用空间不足10%
      summary: windows磁盘可用空间不足10%
    expr: 100 * ((windows_logical_disk_free_bytes / 1024 / 1024) / (windows_logical_disk_size_bytes
      / 1024 / 1024))<10
    for: 30s
    labels:
      prom_id: '63'
      rule_type: disk
      rule_value: '10'
      severity: critical
- alert: vhost-default
    annotations:
      description: windows磁盘可用空间不足10G
      summary: windows磁盘可用空间不足10G
    expr: windows_logical_disk_free_bytes{volume!~"HarddiskVolume1"} / 1024 / 1024
      / 1024<10
    for: 30s
    labels:
      prom_id: '74'
      rule_type: disk
      rule_value: '10'
      severity: emergency

5.grafana展示

模板:Windows Exporter Dashboard 20230531-StarsL.cn | Grafana Labs

请添加图片描述


http://www.kler.cn/a/450994.html

相关文章:

  • 探索多模态大语言模型(MLLMs)的推理能力
  • leetcode-80.删除有序数组的重复项II-day12
  • 网络安全攻防演练中的常见计策
  • 关于uni-forms组件的bug【提交的字段[‘*‘]在数据库中并不存在】
  • CS!GO
  • 1 软件工程——概述
  • Springboot基于Web的高校志愿者服务管理系统81559
  • Git安装及基础学习
  • Blazor 中调用 JavaScript
  • 20241224在ubuntu20.04.6下的终端分屏软件terminator的安装以及使用
  • 网络安全词云图与技术浅谈
  • deepin 安装 zookeeper
  • Git:查看分支、创建分支、合并分支
  • 【漫话机器学习系列】020.正则化强度的倒数C(Inverse of regularization strength)
  • 【CAE开发SDK】CEETRON Envision:适用于桌面端、Web端的数据可视化与分析
  • 【蓝桥杯每日一题】分糖果——DFS
  • Ftp目录整个下载
  • 如何保护你的 iOS 应用免受逆向工程攻击
  • 明厨亮灶系统
  • C++简明教程(9)(多文件编程)
  • 如何提高webpack的构建速度?
  • 设置浏览器声音或视频的自动播放策略
  • Layui数据表格开启前端排序切换功能实现Demo
  • 项目里用到了哪些设计模式是怎么使用的?
  • 【HarmonyOS】HarmonyOS和React Native混合开发 (一)之环境安装
  • 电脑使用CDR时弹出错误“计算机丢失mfc140u.dll”是什么原因?“计算机丢失mfc140u.dll”要怎么解决?