【问题标题】:How do I write Playbooks to check Cpu Usage and Memory in Windows Server?如何编写剧本来检查 Windows Server 中的 Cpu 使用情况和内存?
【发布时间】:2019-09-17 08:03:17
【问题描述】:

找到适用于 unix/linux 的 playbook 更容易,但我正在尝试为 Windows Sever 编写 playbook

【问题讨论】:

  • 我不确定你的目标是什么,但也许你不想用 Ansible 做这个,而是一个监控系统。看看 Zabbix 或 ELK 堆栈。跨度>

标签: windows memory ansible cpu


【解决方案1】:

请尝试以下方法

- name: CPU usage
  win_command: wmic cpu get loadpercentage
  register: cpu_results

- name: Memory
  win_command: wmic OS get FreePhysicalMemory /Value
  register: mem_results

- name: Memory
  win_command: systeminfo
  register: memory_results  

【讨论】:

  • 好的,明白了,谢谢!
【解决方案2】:

在使用 Ansible 管理 Windows 时,适用于 Unix/Linux 主机的许多语法和规则也适用于 Windows,但在路径分隔符和特定于操作系统的任务等组件方面仍然存在一些差异。本文档包含特定于使用 Ansible for Windows 的详细信息。

使用win_commandwin_shell 模块在目标主机上通过shell(默认为PowerShell)运行命令。

您可以简单地运行您想要运行的任何命令,并可以检查有关目标主机的任何详细信息。

以下是进一步阅读的链接:

Using Ansible and Windows

【讨论】:

  • 我无法找到剧本的 CPU 使用率和内存。我不知道如何编写 Windows 中 CPU 使用率的剧本。如果你能帮助我,那就太好了
猜你喜欢
  • 2015-05-23
  • 2010-09-09
  • 2016-09-26
  • 1970-01-01
  • 1970-01-01
  • 2021-06-20
  • 1970-01-01
  • 1970-01-01
  • 2013-04-25
相关资源
最近更新 更多