salt 服务器信息收集,使用saltstack自定义模块获取服务器的信息

2023-11-03

1、查看MASTER的BASE路径,在对应的路径建立_modules文件夹,存放.py的模块

[root@v72 _modules]# cat /etc/salt/master | grep file_roots -A 5

--

file_roots:

base:

- /srv/salt

建立目录:

mkdir -p /srv/salt/_modules

2、在/srv/salt/_modules目录下编写python代码

[root@v72 _modules]# pwd

/srv/salt/_modules

[root@v72 _modules]# cat infos.py

#!/usr/bin/env python

#encoding: utf-8

from subprocess import Popen, PIPE

import os,sys

import time

def getipaddr():

p = Popen(['hostname','-I'], stdout = PIPE)

ip=p.stdout.read()

return ip

def gethostname():

p = Popen(['hostname'], stdout = PIPE)

hostname=p.stdout.read()

return hostname

def getdiskinfo():

p = Popen(['df','-h'], stdout = PIPE)

disks=p.stdout.read()

return disks

def getmemoryinfo():

p = Popen(['free','-m'], stdout = PIPE)

memorys=p.stdout.read()

return memorys

def getbiosinfo():

p = Popen(['dmidecode','-t','bios'], stdout = PIPE)

bios=p.stdout.read()

return bios

def getcpu():

p = Popen(['sar','-u','1','3'], stdout = PIPE)

time.sleep(3)

cpus=p.stdout.read()

return cpus

def getallinfos():

ip="IP地址: "+getipaddr()

hostname="主机名: "+gethostname()

disk="磁盘信息: "+getdiskinfo()

memory="内存信息: "+getmemoryinfo()

bios="BIOS信息: "+getbiosinfo()

cpu="CPU信息: "+getcpu()

return ip,hostname,disk,memory,bios,cpu

#getallinfos()

3、同步模块,执行验证

[root@v72 _modules]# salt '*' saltutil.sync_modules

v72:

- modules.infos

v73:

- modules.infos

运行,验证

[root@v72 _modules]# salt '*' infos.getallinfos

v73:

- IP地址: 192.168.156.73 192.168.122.1

- 主机名: v73

- 磁盘信息: 文件系统                 容量  已用  可用 已用% 挂载点

/dev/mapper/centos-root   18G  8.0G  9.5G   46% /

devtmpfs                 903M     0  903M    0% /dev

tmpfs                    914M   92K  914M    1% /dev/shm

tmpfs                    914M  9.1M  905M    1% /run

tmpfs                    914M     0  914M    0% /sys/fs/cgroup

/dev/sda1                497M  127M  370M   26% /boot

//192.168.156.1/d$       201G   98G  103G   49% /shared

tmpfs                    183M   12K  183M    1% /run/user/42

tmpfs                    183M     0  183M    0% /run/user/0

- 内存信息:               total        used        free      shared  buff/cache   available

Mem:           1826         389         357           9        1079        1201

Swap:          2047           0        2047

- BIOS信息: # dmidecode 2.12

SMBIOS 2.7 present.

Handle 0x0000, DMI type 0, 24 bytes

BIOS Information

Vendor: Phoenix Technologies LTD

Version: 6.00

Release Date: 07/02/2015

Address: 0xEA5E0

Runtime Size: 88608 bytes

ROM Size: 64 kB

Characteristics:

ISA is supported

PCI is supported

PC Card (PCMCIA) is supported

PNP is supported

APM is supported

BIOS is upgradeable

BIOS shadowing is allowed

ESCD support is available

Boot from CD is supported

Selectable boot is supported

EDD is supported

Print screen service is supported (int 5h)

8042 keyboard services are supported (int 9h)

Serial services are supported (int 14h)

Printer services are supported (int 17h)

CGA/mono video services are supported (int 10h)

ACPI is supported

Smart battery is supported

BIOS boot specification is supported

Function key-initiated network boot is supported

Targeted content distribution is supported

BIOS Revision: 4.6

Firmware Revision: 0.0

- CPU信息: Linux 3.10.0-229.el7.x86_64 (v73)        2019年02月22日  _x86_64_        (1 CPU)

17时06分18秒     CPU     %user     %nice   %system   %iowait    %steal     %idle

17时06分19秒     all      0.00      0.00      0.00      0.00      0.00    100.00

17时06分20秒     all      1.00      0.00      0.00      0.00      0.00     99.00

17时06分21秒     all      0.00      0.00      0.00      0.00      0.00    100.00

平均时间:     all      0.33      0.00      0.00      0.00      0.00     99.67

v72:

- IP地址: 192.168.156.72 192.168.122.1

- 主机名: v72

- 磁盘信息: 文件系统                 容量  已用  可用 已用% 挂载点

/dev/mapper/centos-root   18G   12G  5.7G   68% /

devtmpfs                 903M     0  903M    0% /dev

tmpfs                    914M   96K  914M    1% /dev/shm

tmpfs                    914M  9.2M  905M    2% /run

tmpfs                    914M     0  914M    0% /sys/fs/cgroup

/dev/sda1                497M  127M  370M   26% /boot

//192.168.156.1/d$       201G   98G  103G   49% /shared

tmpfs                    183M   12K  183M    1% /run/user/42

tmpfs                    183M     0  183M    0% /run/user/0

- 内存信息:               total        used        free      shared  buff/cache   available

Mem:           1826         719         316          10         791         871

Swap:          2047           0        2047

- BIOS信息: # dmidecode 2.12

SMBIOS 2.7 present.

Handle 0x0000, DMI type 0, 24 bytes

BIOS Information

Vendor: Phoenix Technologies LTD

Version: 6.00

Release Date: 07/02/2015

Address: 0xEA5E0

Runtime Size: 88608 bytes

ROM Size: 64 kB

Characteristics:

ISA is supported

PCI is supported

PC Card (PCMCIA) is supported

PNP is supported

APM is supported

BIOS is upgradeable

BIOS shadowing is allowed

ESCD support is available

Boot from CD is supported

Selectable boot is supported

EDD is supported

Print screen service is supported (int 5h)

8042 keyboard services are supported (int 9h)

Serial services are supported (int 14h)

Printer services are supported (int 17h)

CGA/mono video services are supported (int 10h)

ACPI is supported

Smart battery is supported

BIOS boot specification is supported

Function key-initiated network boot is supported

Targeted content distribution is supported

BIOS Revision: 4.6

Firmware Revision: 0.0

- CPU信息: Linux 3.10.0-229.el7.x86_64 (v72)        2019年02月22日  _x86_64_        (2 CPU)

17时06分20秒     CPU     %user     %nice   %system   %iowait    %steal     %idle

17时06分21秒     all      0.00      0.00      0.00      0.00      0.00    100.00

17时06分22秒     all      0.51      0.00      0.00      0.00      0.00     99.49

17时06分23秒     all      0.00      0.00      0.51      0.00      0.00     99.49

平均时间:     all      0.17      0.00      0.17      0.00      0.00     99.66

加载哪一部份的信息,只需要在saltstack上面调用对应的方法就可以了

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

salt 服务器信息收集,使用saltstack自定义模块获取服务器的信息 的相关文章

随机推荐

  • Instant-ngp Windows11安装、使用记录

    Instant NeRF Study Debug 本机配置 Y9000P RTX3060 Win11 Instant NeRF Study Debug 1 Git 2 Cmake 3 instant ngp 示例数据 自定义数据 注意事项
  • 一次composer错误使用引发的思考

    一次composer错误使用引发的思考 2019 03 05 12 19 by 轩脉刃 阅读 评论 收藏 编辑 一次composer错误使用引发的思考 这个思考源自于一个事故 让我对版本依赖重新思考了一下 事故现象 一个线上的管理后台 一个
  • LeetCode题解——42.连续子数组的最大和(动态规划思想)

    题目地址 剑指 Offer 42 连续子数组的最大和 力扣 LeetCode 一 解题思路 在这道题中 数组连续是一个很重要的信息 我们可以创建一个数组用于记录每一位对应的最大值 所谓每一位的最大值 意思就是以这一位为结尾的数组的最大值 那
  • 面试过程中会遇到的机器学习教科书中 7 大经典问题

    如果希望了解机器学习 或者已经决定投身机器学习 你会第一时间找到各种教材进行充电 同时在心中默认 书里讲的是牛人大神的毕生智慧 是正确无误的行动指南 认真学习就能获得快速提升 但实际情况是 你很可能已经在走弯路 科技发展很快 数据在指数级增
  • SQL Server 基础语法2(超详细!)

    文章目录 选择数据库school 查询所有学生的学号 姓名和年龄 查询结果列项是中文名 查询 计算机 系的所有学生的基本信息 查询所有女同学的姓名及所在的系 显示结果不允许重复出现 查询课程号不为 1 4 或 7 的课程的信息 查询课程号不
  • 处理Matlab Coder之后, Compiler can't find "tmwtypes.h"问题

    作为一个强大的科学计算软件 matlab广泛应用于较多领域 以其简单的编程风格 便利的调试环境等众多优点 在编写算法与测试的时候通常用到 然而很多的实际运用上matlab毕竟还不是很普及 相反还是c与c 更多 同时正版matlab这样一个昂
  • Hive表的分区与分桶

    1 Hive分区表 Hive使用select语句进行查询的时候一般会扫描整个表内容 会消耗很多时间做没必要的工作 Hive可以在创建表的时候指定分区空间 这样在做查询的时候就可以很好的提高查询的效率 创建分区表的语法 create tabl
  • 论文阅读记录: Automatic Image Colorization sig16

    sig论文阅读记录 Let there be Color Joint End to end Learning of Global and Local Image Priorsfor Automatic Image Colorization
  • JSP、servlet运行原理

    一 jsp和servlet的区别 servlet是用Java编写的服务器端程序 其主要功能在于交互式地浏览和修改数据 生成动态Web内容 狭义的Servlet是指Java语言实现的一个接口 广义的Servlet是指任何实现了这个Servle
  • es-5数据同步

    向ES里面添加数据 logstash kabina javaapi restful api 重点介绍一下logstash 是一个数据同步工具 可以动态地将来自不同数据源的数据统一起来 并将数据标准化到其他任何数据源 其实最常见的使用场景是将
  • 思考::战略藐视:RTOS 高级多任务调度器 (***)

    战略藐视 RTOS 高级任务调度器 压力大 将 RTOS 视为操作系统 则似乎有很大的学习心里压力 复杂 耗时 有难度 减压 将它们视为是 某种 高级多任务调度器 来学习 就好了 这样似乎就简单了 心里压力也就小了 或者 将它们视为是 某种
  • 基于Python生成Markdown的标题序号

    import sys import os import time import re headline title sign list 用于判断标题产生环境 titles added number 保存嵌入了编号的标题 用于产生新编号 is
  • Java的内部类

    学习笔记 内部类 内部类访问特点 1 内部类可以直接访问外部类中的成员 2 外部类要访问内部类 必须建立内部类的对象 一般用于类的设计 分析事物时 发现该事物描述中还有事物 而且这个事物还在访问被描述事物的内容 这时就是 还有的事物 定义成
  • iOS进阶_多线程(二.线程间的状态)

    ViewController m 004 NSThread状态 Created by mac on 2018 4 27 Copyright 2018年 mac All rights reserved import ViewControlle
  • TencentOS-tiny 时间管理(十 六)- 时间片轮转机制

    一 时间管理 时间片轮转机制 概述 TencentOS tiny操作系统内核是一个抢占式内核 抢占式内核的特点是 如果最高优先级的任务不放弃CPU 调用tos task delay tos task yeild等主动放权 或者任务间同步通信
  • 深度学习:不平衡的二分类,precise与recall

    在不平衡的二分类问题中 一般数量较少的样本标签为1 precise 预测为正样本中真实为正样本的比例 recall 真实为正样本中预测为正样本的比例 f1 score precise与recall的调和平均 两者中较小值的起决定性作用
  • 配置防火墙,开启80端口、3306端口 & iptables 使用详解

    1 配置防火墙 开启80端口 3306端口 vi etc sysconfig iptables A INPUT m state state NEW m tcp p tcp dport 80 j ACCEPT 允许80端口通过防火墙 A IN
  • GIT常用命令大全——赶紧收藏

    史上最全的GIT常用命令都在这里啦 全是干货 建议收藏起来 反复观看 一 git安装后 指定名称和邮箱 git config global user name Your Name git config global user email e
  • Linux cache介绍及控制

    有关Cache 文件缓存是提升性能的重要手段 毋庸置疑 读缓存 Read caching 在绝大多数情况下是有益无害的 程序可以直接从RAM中读取数据 而写缓存 Write caching 则相对复杂 Linux内核将写磁盘的操作分解成了
  • salt 服务器信息收集,使用saltstack自定义模块获取服务器的信息

    1 查看MASTER的BASE路径 在对应的路径建立 modules文件夹 存放 py的模块 root v72 modules cat etc salt master grep file roots A 5 file roots base