通过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 ...
随机推荐
- $identify 的 “identify” 表示一个Perl标识符,即 identifier
$identify 的 “identify” 表示一个Perl标识符,即 identifier
- shell_backup_MySQL
#!/bin/bash #可修改如下参数backup_filename=$(date +%Y%m%d%H%M%S)backup_tmp_dir=/data/backup/ip=10.0.1.182us ...
- Winform下编译Dev控件时提示license.licx文件错误
有时候,用vs2005或2008,用到第3方控件的时候会自动生成licenses.licx.我用的是devexpress.在程序运行的时候总是出现dev的画面,很烦.在网上找了找,找到去掉画面的方法: ...
- python学习笔记(22)-os文件操作模块
疑问: 如果打开操作一个文件,是用绝对路径好还是相对路径好? os模块,在lib下面,可以直接引入的,直接使用import. 一.新建一个目录,新建一个文件夹 import os #新建一个文件夹 o ...
- Miller-Rabin素数检测算法
遇到了一个题: Description: Goldbach's conjecture is one of the oldest and best-known unsolved problems in ...
- SpringBoot 系列 - 自己写starter
原文地址: https://www.xncoding.com/2017/07/22/spring/sb-starter.html 前言: Spring Boot由众多Starter组成,随着版本的推移 ...
- [LC] 437. Path Sum III
You are given a binary tree in which each node contains an integer value. Find the number of paths t ...
- 吴裕雄--天生自然 HADOOP大数据分布式处理:添加主机和服务器的域名映射
- Qt uchar * 转 QImage
QImage(uchar * data, int width, int height, Format format) QImage(const uchar * data, int width, int ...
- WebService如何根据WSDL文件转换成本地的C#类
WebService有两种使用方式,一种是直接通过添加服务引用,另一种则是通过WSDL生成. 添加服务引用大家基本都用过,这里就不讲解了. 那么,既然有直接引用的方式,为什么还要通过WSDL生成呢? ...