跳至主要内容

利用Prometheus+windows_exporter监控windows server的数据

公司现有环境已经有zabbix来监控server的状态,并利用grafana接入zabbix_api来获取更为直观的实时图形数据。
但zabbix的优势是灵活的报警功能,因为依赖于sql数据库,实时大量数据写入在面对较多机器的环境下,会产出很高的性能开销。
因此采用prometheus这种时间序列数据库,利用其高效的数据写入,来获取服务器更为详细的信息。


环境如下:
客户端windows server安装windows_exporter,服务端安装prometheusgrafana

一.服务端安装Grafana。
    这里使用centos 7的环境安装。
    下载最新版的grafana安装包。
    sudo yum install grafana-7.2.2-1.x86_64.rpm
    安装完成后启动服务
    sudo systemctl daemon-reload
    sudo systemctl start grafana-server
    sudo systemctl status grafana-server
    sudo systemctl enable grafana-server
    开启防火墙端口
    firewall-cmd --add-port=3000/tcp --permanent
    systemctl reload firewalld
    打开浏览器输入http://ip:3000就能打开grafana的页面。
二.服务端安装prometheus。
    下载prometheus的二进制安装包
    wget
    https://github.com/prometheus/prometheus/releases/download/v2.22.0/prometheus-2.22.0.linux-amd64.tar.gz
    解压
    tar -xf prometheus-2.22.0.linux-amd64.tar.gz
    移动并创建软连接
    mv prometheus-2.22.0.linux-amd64   /usr/local/
    ln -s /usr/local/prometheus-2.22.0.linux-amd6   /usr/local/prometheus
    创建prometheus用户及数据存储目录
    usradd  -s /sbin/noligin -M prometheus
    mkdir   /data/prometheus -p
    chown -R prometheus:prometheus /usr/local/prometheus
    chown -R prometheus:prometheus /data/prometheus
    创建prometheus的systemd服务启动项
    vim /etc/systemd/system/prometheus.service

[Unit]
Description=Prometheus
Documentation=https://prometheus.io/
After=network.target
[Service]
Type=simple
User=prometheus
ExecStart=/usr/local/prometheus/prometheus --config.file=/usr/local/prometheus/prometheus.yml --storage.tsdb.path=/data/prometheus
Restart=on-failure
[Install]
WantedBy=multi-user.target
    systemctl enable prometheus
    systemctl start prometheus
    开启防火墙端口
    firewall-cmd --add-port=9090/tcp --permanent
    systemctl reload firewalld
    打开浏览器输入http://ip:9090就可以看到prometheus的web页面。
三.客户端安装wmi_exporter。
    下载最新的安装包https://github.com/prometheus-community/windows_exporter/releases
    安装后在防火墙开启9182端口
    打开浏览器输入http://ip:9182就可以看到windows_exporter的页面。
四.配置prometheus抓取客户端信息。
    编辑prometheus的配置文件
    vim /usr/local/prometheus/prometheus.yml
    在scrape_configs中加入客户端信息
    - job_name:  'SHXX01'
      static_configs:
      - targets:  ['10.10.10.121:9182','10.10.10.122:9182']
    完成后重启prometheus服务
    systemctl restart prometheus
    打开浏览器输入http://ip:9090检查target中新增节点的状态是否为UP。
五.在grafana中添加prometheus的数据源。
    在configuration中选中prometheus并点击add data source。
    在配置中填入服务器地址:http://localhost:9090。
    点击save&test。

至此完成grafana导入利用prometheus抓取windows exporter的数据。

评论

此博客中的热门博文

PVE安装Windows 11虚拟机 step by step

Win 11已经发布有两周多了,因为引进了tpm机制,只支持较新的设备安装,对于虚拟机的支持不高。 目前各个虚拟化平台针对win 11已经有对应的方案,今天来介绍一下PVE 7.0安装win 11虚拟机。 提前下载win11和virtio win 11的镜像。 win 11镜像下载这里就不说了,很多途径。 virtio的镜像在这里下载https://github.com/virtio-win/virtio-win-pkg-scripts,下载最新的virtio win iso。 新建和配置虚拟机 点击新建虚拟机 给虚拟机起名,然后下一步。 选择加载win 11镜像文件,系统类型选择windows。 系统配置这里: bios选择OVMF(UEFI);机器选择q35;勾选TPM,并选择TPM版本为v2.0;然后存储的位置选择同一个存储。 硬盘设备选择VirtIO,磁盘大小选择64G,32G其实也可以,但是微软要求最低64G。 设置CPU和内存,微软要求最低2核8G,这里我们给4核8G,因为是单节点,所以CPU类型勾选host。 配置网卡信息后继续。 这里不要勾选自动创建后启动,确认配置信息后点击完成。 到新建的虚拟机这里,新建光驱。 选择下载的驱动镜像,点击创建。 完成后点击启动。 启动后进入windows安装界面,这里照一般操作进行。 到安装类型这里选择 自定义安装。 到选择安装位置这里会无法显示硬盘信息,因为缺少驱动,点击加载驱动程序。 然后点击浏览。 选择驱动镜像下的amd64下的w10文件夹,点击确定。 加载驱动后磁盘控制器能够显示,点击下一页。 选中显示的磁盘后点击下一步进行安装。 文件复制完后会重启几次。 安装完成后会启动第一次配置界面。 输入账户信息后进行系统配置。 配置完成后进入桌面。 在设备管理器中有一些设备未能正确识别。 进入驱动镜像,运行virtio-win-ge-x64安装文件安装驱动。 安装完成后,所有设备都能正确识别。 至此win11虚拟机安装完成。

安装部署JumpServer

 最近遭遇一起云主机因安全防护措施不到位被安装挖矿程序的情况。 为提高云主机的安全性和考虑搭建一台跳板机来访问云主机以提高安全性。 目前主流且还在维护的JumpServer是比较好的解决方案,搭建一台JumpServer做测试。 这里使用ubuntu 20.04 lts作为OS。 安装操作系统后先修改软件仓库为国内163源。 sudo cp /etc/apt/sources.list    /etc/apt/sources.list.bak sudo nano /etc/apt/sources.list 注释掉原来的内容 添加网易源 #网易源 deb http://mirrors.163.com/ubuntu/ focal main restricted universe multiverse deb-src http://mirrors.163.com/ubuntu/ focal main restricted universe multiverse deb http://mirrors.163.com/ubuntu/ focal-security main restricted universe multiverse deb-src http://mirrors.163.com/ubuntu/ focal-security main restricted universe multiverse deb http://mirrors.163.com/ubuntu/ focal-updates main restricted universe multiverse deb-src http://mirrors.163.com/ubuntu/ focal-updates main restricted universe multiverse deb http://mirrors.163.com/ubuntu/ focal-backports main restricted universe multiverse deb-src http://mirrors.163.com/ubuntu/ focal-backports main restricted universe multiverse 执行更新 sudo apt-g...

为阿里云ecs创建自定义快照脚本

阿里云的ecs自动快照功能只支持最长一周的间隔,而有些生产环境不太需要如此频繁的备份。 因此写了一个每月备份一次的脚本来解决这个问题 一共分五个步骤,分别是创建执行快照的账号,分配账号权限,安装阿里云cli,创建脚本,编辑计划任务。 一.创建账号。 为降低安全风险,这里新创建一个账号用于执行生成快照的脚本。 在创造账号时,只勾选api访问。 记录下创建完成后的token信息。 二.分配账号权限。 创建一个自定义的访问权限策略。 {     "Statement": [         {             "Effect": "Allow",             "Action": "ecs:*Snapshot*",             "Resource": "*"         }     ],     "Version": "1" } 然后将这个策略套给新创建的账号,同时赋予这个账号ecs的只读权限。 三.安装阿里云cli客户端,这里就不做赘述,直接看阿里云的文档就好。 https://help.aliyun.com/document_detail/139508.html?spm=a2c4g.139508.0.0.3c18337a5eCaya 四.创建脚本。 aliyun configure set \   --profile bkadminprofile \   --mode AK \   --region cn-shanghai \   --access-key-id ************************ \   --access-key-secret ********************** 先获取ecs的实例id   aliyun ecs DescribeInstances --RegionId cn-shanghai --output c...