通过python脚本读取多台虚机硬件信息
主要通过fabric模块实现
import fabric '''
hosts = []
for i in range(,):
host = "192.168.75." + str(i)
hosts.append(host)
''' def getcpu(c):
''' 取cpu核数'''
result = c.run("grep -i processor /proc/cpuinfo |wc -l")
return result.stdout.strip()
def getmem(c):
''' 取内存大小'''
mem_result = c.run("free -h|grep -i mem|awk '{print $2}'")
return mem_result.stdout.strip()
def getdisk(c):
'''取第二磁盘vdb大小'''
disk_result = c.run("fdisk -l|grep -w vdb|awk '{print $3}'")
return disk_result.stdout.strip() def myconnect():
hosts = ['192.168.75.2', '192.168.75.3', '192.168.75.4', '192.168.75.5', '192.168.75.6', '192.168.75.7', '192.168.75.8', '192.168.75.9', '192.168.75.10', '192.168.75.11', '192.168.75.12', '192.168.75.13', '192.168.75.14', '192.168.75.15']
#hosts = ['192.168.75.2']
for host in hosts:
conn = fabric.Connection(host,user='root',connect_kwargs={"password":"yourpass"})
print("{}: cpu {}核 mem {} disk {}G".format(host,getcpu(conn),getmem(conn),getdisk(conn))) if __name__ == '__main__':
myconnect()
通过python脚本读取多台虚机硬件信息的更多相关文章
- 多台虚机redis cluster集群
用到的安装包 https://pan.baidu.com/s/1wwLm3C7oWcM9ptwMjRltGA 提取码:vdfp 系统环境:centos7 ----------------------- ...
- Delphi中使用python脚本读取Excel数据
Delphi中使用python脚本读取Excel数据2007-10-18 17:28:22标签:Delphi Excel python原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 . ...
- python脚本 读取excel格式文件 并进行处理的方法
一.安装xlrd模块 pip install xlrd 二.读取excel文件 try: excel_obj = xlrd.open_workbook("文件路径") except ...
- Python脚本抓取京东手机的配置信息
以下代码是使用python抓取京东小米8手机的配置信息 首先找到小米8商品的链接:https://item.jd.com/7437788.html 然后找到其配置信息的标签,我们找到其配置信息的标签为 ...
- shell脚本批量收集linux服务器的硬件信息快速实现
安装ansible批量管理系统.(没有的话,ssh远程命令循环也可以) 在常用的数据库里面新建一张表,用你要收集的信息作为列名,提供可以用shell插入.
- Web系统如何做到读取客户电脑MAC等硬件信息且兼容非IE浏览器
我们在实际Web应用中,可能会遇到“需要限定特定的电脑或用户才能使用系统”的问题. 对于一般情况来说,我们用得最多的可能是使用ActiveX控件的方法来实现,但此方案只适用于IE浏览器.为了能兼容不同 ...
- 用 Python 脚本实现对 Linux 服务器的监控
目前 Linux 下有一些使用 Python 语言编写的 Linux 系统监控工具 比如 inotify-sync(文件系统安全监控软件).glances(资源监控工具)在实际工作中,Linux 系统 ...
- 无法与域Active Directory域控制器(AD DC)连接(虚机加域出错问题)
今天建了两台虚机用的VMWARE,一台做域控,一台做应用服务器,但是部署好域控要把应用服务器加入域时候报错 虚机网卡设置桥接并设置好IP使两台虚机在同一个局域网内,通过ip地址互ping能ping通, ...
- Terraform:创建 Azure 虚机
笔者在前文<Terraform 简介>中简单介绍了 Terraform 相关的概念,本文让我们使用 Terraform 在 Azure 上创建一个虚机,以此来直观体验一下 Terrafor ...
随机推荐
- v-cloak使用
v-cloak:保持和元素实例的关联,直到结束编译后自动消失. v-cloak指令和CSS 规则一起用的时候,能够解决差值表达式闪烁的问题(即:可以隐藏未编译的标签直到实例准备完毕). 就拿上一段代码 ...
- Linux 运维命令及知识
1.查找当前目录下所有以.tar结尾的文件然后移动到指定目录: find . -name “*.tar” -exec mv {}./backup/ ; 注解:find –name 主要用于查找某个文件 ...
- 吴裕雄--天生自然python学习笔记:python 用 Open CV 进行人脸识别
要对特定图像进行识别,最关键的是要有识别对象的特征文件, OpenCV 己内置 了人脸识别特征文件,我们只需使用 OpenCV 的 CascadeClassifier 类即可进行识别 . 创建 Cas ...
- svn http
yum install -y httpd subversion mod_dav_svn mkdir -p /var/lib/svn cd /var/lib/svn svnadmin create de ...
- 网站爬取-案例一:猫眼电影TOP100
今天有小朋友说想看一下猫眼TOP100的爬取数据,要TOP100的名单,让我给发过去,其实很简单,先来看下目标网站: 建议大家都用谷歌浏览器: 这是我们要抓取的内容,100个数据,很少 我们看一下页面 ...
- TZOJ-STL系列题
C++实验:STL之vector #include <bits/stdc++.h> using namespace std; void Input(vector<int>&am ...
- [LC] 112. Path Sum
Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all ...
- [LC] 76. Minimum Window Substring
Given a string S and a string T, find the minimum window in S which will contain all the characters ...
- python后端面试第二部分:网络编程和并发编程--长期维护
1. 简述 OSI 七层协议. 2. 什么是C/S和B/S架构? 3. 简述 三次握手.四次挥手的流程. 4. 什么是arp协议? 5. TCP和UDP的区别? 6. 什么是局域网和广域网? 7. 为 ...
- [LC] 225. Implement Stack using Queues
Implement the following operations of a stack using queues. push(x) -- Push element x onto stack. po ...