Prometheus 监控Windows机器

【1】windows采集器:wmi-exporter

在192.168.191.81 上安装,采集器默认端口为 9182

【1.1】下载安装 wmi-exporter

https://github.com/martinlindhe/wmi_exporter/releases

我们在下图中选择这个:windows_exporter-0.13.0-amd64.msi

 

  

 下载好后,传输到被监控的 windows 机器上去运行

  

 运行了之后,我们发现好像什么都没有发生,但实际上可能已经安装好了,我们查看服务

  

 我们来看看它到底是不是,右击查看它的属性,看这描述,就是它了。

  

--  这里推荐把启动类型,修改成自动(延迟启动)

--  或者可以  cmd命令执行  sc config windows_exporter start= delayed-auto

 我们还可以看看它的执行文件路径,里面就是它的启动命令了,原来默认端口是9182啊

"C:\Program Files\windows_exporter\windows_exporter.exe" --log.format logger:eventlog?name=windows_exporter  --telemetry.addr :9182   

从这里可以看出,wim_exporter的日志信息  --log.format logger:eventlog  放入了windows自带的 eventlog中去了;

【1.2】核验 wmi_exporter 是否运行

我们在上一个步骤发现它运行了,那么我们如何确定采集器真的再运行呢?

  根据采集器特性,我们用http(192.168.191.81:9182/metrics)访问它的 metrics 即可。

  这里如果是在客户端机器上,直接输入127.0.0.1:9182/metrics 也可以

    

 

【windows_exporter】高级应用(非必须)

官网:https://github.com/prometheus-community/windows_exporter

【1.1】默认配置:默认采集哪些指标呢?

看官网:https://github.com/prometheus-community/windows_exporter

通过官网我们可以看到,它有非常多的采集器,然后默认只采集了几个分类而已,想知道每个分类指标里面大概采集的那些具体指标,可以点进去看;

  

 

【1.2】额外参数配置

  

 

其实大多都用不到,我们一般只要管

--telemetry.addr :配置自定义端口(当然一般也不用额外配置,默认9182 就不错)

--collectors.enabled :指定额外的采集指标分类,就是我们该分类1.1中的那些了

案例:

仅启用服务收集器并指定自定义查询

.\windows_exporter.exe --collectors.enabled "service" --collector.service.services-where "Name='windows_exporter'"

仅启用流程收集器并指定自定义查询

.\windows_exporter.exe --collectors.enabled "process" --collector.process.whitelist="firefox.+"

当有多个同名进程时,WMI将第一个实例之后的进程表示为process-name#index因此,要获取所有内容,而不仅仅是第一个,则正则表达式必须使用.+有关更多信息,请参见过程

【1.3】最佳实践

  

 

 config.yml

collectors:
  enabled: cpu,cs,logical_disk,net,os,service,system,textfile,mssql
collector:
  service:
    services-where: "Name='windows_exporter'"
log:
  level: warn

start.bat

windows_exporter --config.file=config.yml

 

如果只是简单用一下:推荐

.\windows_exporter.exe --collectors.enabled "cpu,cs,logical_disk,net,os,service,system,textfile,mssql" --collector.service.services-where "Name='windows_exporter'"

 【1.4】windows_exporter.exe安装

直接运行即可用:这个窗口不要关闭

  

 最佳实践,封装成服务;

sc create windows_exporter binpath= "C:\Program Files\windows_exporter\windows_exporter.exe" start= auto displayname= windows_exporter

 

 

【2】prometheus 配置

这里我们的 prometheus 服务器是 192.168.175.131,端口:9090

PS:安装方面的就不讲了(有兴趣的可以看我这个文章分类下的其他文章),这里预设是已经安装好正在运行的 prometheus 服务器

【2.1】修改Prometheus.yml 添加 windows 机器

我在配置文件中添加了下列红框中的代码;

  

【2.2】在线重载 Prometheus 配置文件

在prometheus 服务器端运行,或者直接在外部网页上运行也可以,不过localhost 要改成服务器端的 IP地址

curl -X POST http://localhost:9090/-/reload

【2.3】核验节点与prometheus服务器是否联通

  

【3】Grafana 配置与显示

【3.1】windows 仪表盘模板

官网:https://grafana.com/grafana/dashboards?dataSource=prometheus

  

 

 我的prometheus 服务器端 可以联网,我就直接用这个仪表盘ID了。如下图,ID是 10467

  

 

【3.2】导入windows仪表盘模板

  

 

输入仪表盘ID,然后点击 Load

   

 

 选择好数据源然后导入

  

 

【3.3】查看新导入的windows仪表盘

   

到这里,就完成成功了!

 

【参数解析】

参数解析转自:https://blog.csdn.net/qq_38311845/article/details/105279963

GO参数

参数名参数解释
go_gc_duration_seconds GC调用持续时间的摘要
go_goroutines 当前存在的goroutine数量
go_info 有关Go环境的信息
go_memstats_alloc_bytes 已分配且仍在使用的字节数
go_memstats_alloc_bytes_total 已分配的总字节数,即使已释放也是如此
go_memstats_buck_hash_sys_bytes 分析存储桶哈希表使用的字节数(标尺)
go_memstats_frees_total 空闲总数(计数器)
go_memstats_gc_cpu_fraction 自程序启动以来,GC使用该程序的可用CPU时间的分数
go_memstats_gc_sys_bytes 用于垃圾回收系统元数据的字节数
go_memstats_heap_alloc_bytes 已分配且仍在使用的堆字节数
go_memstats_heap_idle_bytes 等待使用的堆字节数
go_memstats_heap_inuse_bytes 正在使用的堆字节数
go_memstats_heap_objects 分配的对象数
go_memstats_heap_released_bytes 已释放到OS的堆字节数
go_memstats_heap_sys_bytes 从系统获取的堆字节数
go_memstats_last_gc_time_seconds 自1970年以来的最后一次垃圾回收的秒数
go_memstats_lookups_total 指针查找总数
go_memstats_mallocs_total malloc总数
go_memstats_mcache_inuse_bytes mcache结构正在使用的字节数
go_memstats_mcache_sys_bytes 用于从系统获取的mcache结构的字节数
go_memstats_mspan_inuse_bytes mspan结构使用的字节数
go_memstats_mspan_sys_bytes 用于从系统获取的mspan结构的字节数
go_memstats_next_gc_bytes 下一次垃圾回收发生时的堆字节数
go_memstats_other_sys_bytes 用于其他系统分配的字节数
go_memstats_stack_inuse_bytes 堆栈分配器正在使用的字节数
go_memstats_stack_sys_bytes 从系统获取的用于堆栈分配器的字节数
go_memstats_sys_bytes 从系统获取的字节数
go_threads 创建的OS线程数
   

 

process参数

参数名参数解释
process_start_time_seconds 自unix纪元以来的进程开始时间(以秒为单位)

 

cpu参数

参数名参数解释
wmi_cpu_clock_interrupts_total 接收和服务的时钟滴答中断总数
wmi_cpu_core_frequency_mhz 核心频率(兆赫)
wmi_cpu_cstate_seconds_total 在低功耗空闲状态下花费的时间
wmi_cpu_dpcs_total 接收和服务的延迟过程调用(DPC)总数
wmi_cpu_idle_break_events_total 处理器从空闲状态唤醒的总时间
wmi_cpu_interrupts_total 接收和服务的硬件中断总数
wmi_cpu_parking_status 停车状态表示处理器是否已停车
wmi_cpu_processor_performance 处理器性能是处理器执行指令时的平均性能,占处理器标称性能的百分比
wmi_cpu_time_total 处理器在不同模式(空闲,用户,系统等)上花费的时间
   

 

ComputerSystem参数

参数名参数解释
wmi_cs_hostname 由ComputerSystem.DNSHostName和ComputerSystem.Domain提供的带标签的系统主机名信息
wmi_cs_logical_processors ComputerSystem.NumberOfLogicalProcessors
wmi_cs_physical_memory_bytes ComputerSystem.TotalPhysicalMemory
   

 

wmi_exporter参数

参数名参数解释
wmi_exporter_build_info 带有常量'1'值的度量标准,用于构建wmi_exporter
wmi_exporter_collector_duration_seconds wmi_exporter:收集的持续时间
wmi_exporter_collector_success wmi_exporter:收集器是否成功
wmi_exporter_collector_timeout wmi_exporter:收集器是否超时
wmi_exporter_perflib_snapshot_duration_seconds perflib快照捕获的持续时间
   

 

logical(磁盘)参数

参数名参数解释
wmi_logical_disk_free_bytes 以字节为单位的可用空间
wmi_logical_disk_idle_seconds_total 磁盘空闲的秒数(可以用irate表示磁盘空闲率)
wmi_logical_disk_read_bytes_total 读取操作期间从磁盘传输的字节数
wmi_logical_disk_read_latency_seconds_total 显示从磁盘进行读取操作的平均时间(以秒为单位)
wmi_logical_disk_read_seconds_total 磁盘正在忙于处理读取请求的秒数
wmi_logical_disk_read_write_latency_seconds_total 显示以秒为单位的平均磁盘传输时间
wmi_logical_disk_reads_total 磁盘上的读取操作数
wmi_logical_disk_requests_queued 排队到磁盘的请求数
wmi_logical_disk_size_bytes 总空间(以字节为单位)
wmi_logical_disk_split_ios_total 磁盘的I / O数量分为多个I / O
wmi_logical_disk_write_bytes_total 写入操作期间传输到磁盘的字节数
wmi_logical_disk_write_latency_seconds_total 显示对磁盘执行写入操作的平均时间(以秒为单位)
wmi_logical_disk_write_seconds_total 磁盘忙于处理写请求的秒数
wmi_logical_disk_writes_total 磁盘上的写操作数
   

 

net 参数

参数名参数解释
wmi_net_bytes_received_total 接收的网络字节数
wmi_net_bytes_sent_total 发送的网络字节数
wmi_net_bytes_total 网络字节总数
wmi_net_current_bandwidth 网络当前带宽
wmi_net_packets_outbound_discarded 网络丢弃出站的数据包
wmi_net_packets_outbound_errors 网络数据包出站错误
wmi_net_packets_received_discarded 网络丢弃接收的数据包
wmi_net_packets_received_errors 网络数据包接收错误
wmi_net_packets_received_total 接收到的包
wmi_net_packets_received_unknown 网络收到未知的数据包
wmi_net_packets_sent_total 网络发送的数据包
wmi_net_packets_total 网络包总数
   

 

OS 系统参数

参数名参数解释
wmi_os_info 操作系统-标题 操作系统-版本
wmi_os_paging_free_bytes 分页文件中的空闲空间
wmi_os_paging_limit_bytes 存储在分页文件中的大小
wmi_os_physical_memory_free_bytes 释放物理内存
wmi_os_process_memory_limix_bytes 最大进程内存大小
wmi_os_processes 进程数
wmi_os_processes_limit 最大进程数
wmi_os_time 本地日期时间
wmi_os_users 用户数
wmi_os_virtual_memory_bytes 总虚拟内存大小
wmi_os_virtual_memory_free_bytes 空闲虚拟内存
wmi_os_visible_memory_bytes 总可见内存大小
   

 

service 系统服务参数

参数名参数解释
wmi_service_start_mode 服务的启动模式(StartMode)
wmi_service_state 服务状态(状态)
wmi_service_status wmi_服务状态
   

 

service 参数

参数名参数解释
wmi_system_context_switches_total 上下文开关总数(WMI源:PerfOS_System.contextswitchessepersec)
wmi_system_exception_dispatches_total 调度的异常总数(WMI源:PerfOS_System.ExceptionDispatchesPersec)
wmi_system_processor_queue_length 处理器队列的长度(WMI源:PerfOS_System.processor queue Length)
wmi_system_system_calls_total 系统调用总数(WMI源:PerfOS_system.SystemCallsPersec)
wmi_system_system_up_time 系统启动时间(WMI源:PerfOS_System.SystemUpTime)
wmi_system_threads wmi_system_线程
wmi_textfile_scrape_error 如果打开或读取文件时出错,则为1;否则为0
posted @ 2020-08-18 14:36  郭大侠1  阅读(12883)  评论(0编辑  收藏  举报