ok-system-helper是一个简单的系统硬件的实时信息收集工具,使用python3.x开发

Overview

ok-system-helper

ok-system-helper是一个简单的系统硬件的实时信息收集工具,使用python3.x开发,支持哪些硬件:CPU、内存、SWAP、磁盘、网卡流量。用户可在自己的项目中直接引入、开箱即用,或者结合flask等web框架轻松做成http接口供前端调用,亦可通过注册中心(Eureka、Consul、Nacos等)的加持,做成微服务供其他系统调用。

提供哪些方法

方法名称 说明
cpu() 获取cpu的使用信息
memory() 获取 '物理内存' 的使用信息
swap() 获取 '交换内存' 的使用信息
disk() 获取磁盘的使用信息
net() 获取自开机以来,网卡的IO信息

提示:具体每个方法使用说明,请参考system_helper.py源码中的注释。

配置说明

配置文件config.conf(如果不需要开启流量统计功能及对外提供HTTP服务,则不需要该配置文件)

[application]
name=ok-system-helper
host=127.0.0.1
port=7002

[webservice]
appid=123456   # 请求HTTP服务时的唯一验证码(作为GET请求的参数携带)

[redis]
host=127.0.0.1
port=6379
password=foobared

[mysql]
host=127.0.0.1
port=3306
dbname=blog
username=root
password=root

使用举例

from core.system_helper import SysInfosCollector

collector = SysInfosCollector()

print(collector.cpu())
'''
{
	'platform': 'windows',
	'physical_count': 4,  # 物理数量
	'logical_count': 8,  # 逻辑数量
	'usage_percent': 6.8,
	'user': 0.4,
	'system': 1.6,
	'idle': 97.7,
	'interrupt': 0.2,
	'dpc': 0.2,
	'boot_time': '2019-09-12 18:49:43'
}
'''

print(collector.memory())
'''
{
	'total': 16331.78,  # 单位MB
	'available': 7945.26,
	'used': 8386.52,
	'free': 7945.26,
	'usage_percent': 51.4
}
'''

print(collector.swap())
'''
{
	'total': 18891.78,  # 单位MB
	'used': 15034.0,
	'free': 3857.78,
	'sin': 0.0,
	'sout': 0.0,
	'usage_percent': 79.6
}
'''

print(collector.disk())
'''
{
	'C:\\': {
		'total': 117.85,  # 单位GB
		'used': 91.86,
		'free': 25.98,
		'usage_percent': 78.0
	},
	'D:\\': {
		'total': 300.03,
		'used': 67.83,
		'free': 232.2,
		'usage_percent': 22.6
	},
	'E:\\': {
		'total': 599.64,
		'used': 185.56,
		'free': 414.07,
		'usage_percent': 30.9
	}
}
'''

print(collector.net())
'''
[{
	'name': '以太网',
	'ip': '192.168.1.4',
	'io_in': 165775.09,  # 单位MB
	'io_out': 26482.64  
}, {
	'name': 'WLAN 2',
	'ip': '169.254.209.196',
	'io_in': 0.0,
	'io_out': 0.0
}, {
	'name': '本地连接* 3',
	'ip': '169.254.211.243',
	'io_in': 0.0,
	'io_out': 0.0
}]
'''

提示:开启流量统计(需先建库建表,脚本tb_net_io.sql)功能及对外提供HTTP服务,请查看scheduled_task.py和web_service.py中的代码。

问题和建议

如果有什么问题、建议、BUG都可以在这个Issue和我讨论

公众号

关注不迷路,微信扫描下方二维码或搜索关键字“spartacus”,关注「spartacus」公众号,时刻收听spartacus更新通知!

在公众号后台回复“加群”,即可加入「spartacus」扯淡交流群!

mp_qrcode

许可证

Copyright [2022] [xlvchao]

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Owner
xlvchao
xlvchao
An arduino/ESP project that can play back G-Force data previously recorded

An arduino/ESP project that can play back G-Force data previously recorded

7 Apr 12, 2022
A python module for interacting with rolimon's, a roblox value site.

rpi - rolimon's python interaction rpi is an open source python-based rolimon's api wrapper. It provides an end-to-end pipeline in which each componen

Acier 11 Nov 08, 2022
It is a serial communicator(controller, receiver...), communicate with sensor LP20 which is a laser ranger.

Intro It is a serial communicator(controller, receiver...), communicate with sensor LP20 which is a laser ranger. Its datasheet is contained in this r

3 Sep 19, 2022
Smart Tech Automation Remote via Kinematics Gesture control for IoT devices

STARK Smart Tech Automation Remote via Kinematics Gesture control for IoT devices View Demo · Report Bug · Request Feature Table of Contents About The

Juseong (Joe) Kim 1 Jan 29, 2022
Home solar infrastructure (with Peimar Inverter) monitoring based on Raspberry Pi 3 B+ using Grafana, InfluxDB, Custom Python Collector and Shelly EM.

raspberry-solar-mon Home solar infrastructure (with Peimar Inverter) monitoring based on Raspberry Pi 3 B+ using Grafana, InfluxDB, Custom Python Coll

cislow 10 Dec 23, 2022
Home Assistant custom integration for e-distribución

e-Distribución is an energy distribution company that covers most of South Spain area. If you live in this area, you probably are able to register into their website to get some information about you

VMG 17 Sep 07, 2022
Run this code to blink your ThinkPad LED with a hidden mysterious Morse code! ;)

TMorse Run this code to blink your ThinkPad LED with a hidden mysterious Morse code! ;) Compatible with python3.9+. No third-party library is required

Mahyar 2 Jul 11, 2022
Modi2-firmware-updater - MODI+ Firmware Updater With Python

MODI+ Firmware Updater 실행 준비 python3(파이썬3.9 혹은 그 이상의 버전)를 컴퓨터에 설치 python3 -m pip

LUXROBO 1 Feb 04, 2022
Setup DevTerm to be a cool non-GUI device

DevTerm hobby project I bought this amazing device: DevTerm A-0604. It has a beefy ARM processor, runs a custom version of Armbian, embraces Open Sour

Alex Shteinikov 9 Nov 17, 2022
LUNA: a USB multitool & nMigen library

LUNA is a full toolkit for working with USB using FPGA technology; and provides hardware, gateware, and software to enable USB applications.

Great Scott Gadgets 750 Dec 28, 2022
This is a Virtual Keyboard which is simple yet effective to use.

Virtual-Keyboard This is a Virtual KeyBoard which can track finger movements and lets you type anywhere ranging from notepad to even web browsers. It

Jehan Patel 3 Oct 01, 2021
Various programs in Atari BASIC for #FujiNet for Atari 8-bit

FujiNet Various programs in Atari BASIC for #FujiNet for Atari 8-bit FujiNet-3D Tic Tac Toe In 1978, Scott Adams wrote a 3-D Tic Tac Toe game, for pla

Kay Savetz 2 Jan 01, 2022
Designed and coded a password manager in Python with Arduino integration

Designed and coded a password manager in Python with Arduino integration. The Program uses a master user to login, and stores account data such as usernames and passwords to the master user. While lo

Noah Colbourne 1 Jan 16, 2022
Water quality integration for Home Assistant with data provided by Budapest FVM

Water Quality FVM (Budapest, HU) custom integration for Home Assistant This custom component integrates water quality information provided by Budapest

Atticus Maximus 3 Dec 23, 2021
Alternative firmware for ESP8266 with easy configuration using webUI, OTA updates, automation using timers or rules, expandability and entirely local control over MQTT, HTTP, Serial or KNX. Full documentation at

Alternative firmware for ESP8266/ESP32 based devices with easy configuration using webUI, OTA updates, automation using timers or rules, expandability

Theo Arends 59 Dec 26, 2022
Yet another automation project because a smart light is more than just on or off.

Automate home Yet another home automation project because a smart light is more than just on or off. Overview When talking about home automation there

Maja Massarini 62 Oct 10, 2022
Like htop (CPU and memory usage), but for your case LEDs. 😄

Like htop (CPU and memory usage), but for your case LEDs. 😄

Derek Anderson 3 Dec 08, 2021
Hourglass on the pi pico using circuitpython

hourglass-on-pico "Hourglass" on the raspberry pi pico using circuitpython circuitpython version 7.0.0 Components used: Raspberry Pi Pico ADXL345 acce

4 Jul 18, 2022
DongshanPI Seven for STM32MP157DAC.

STM32MP1 Buildroot External Tree

DongshanPI 14 May 06, 2022
Keystroke logging, often referred to as keylogging or keyboard capturing

Keystroke logging, often referred to as keylogging or keyboard capturing, is the action of recording the keys struck on a keyboard, typically covertly, so that a person using the keyboard is unaware

Bhumika R 2 Jan 11, 2022