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
What if home automation was homoiconic? Just transformations of data? No more YAML!

radiale what if home-automation was also homoiconic? The upper or proximal row contains three bones, to which Gegenbaur has applied the terms radiale,

Felix Barbalet 21 Mar 26, 2022
Simple Microservice to control 433Mhz wireless sockets over HTTP, e.g. on a RaspberryPi

REST-light is a simple microservice to control 433Mhz wireless sockets over HTTP, e.g. on a RaspberryPi. The main usage is an easy integration of 433M

Pascal Höhnel 1 Jan 09, 2022
A flexible data historian based on InfluxDB, Grafana, MQTT and more. Free, open, simple.

Kotori Telemetry data acquisition and sensor networks for humans. Documentation: https://getkotori.org/ Source Code: https://github.com/daq-tools/koto

83 Nov 26, 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
Imbalaced Classification and Robust Semantic Segmentation

Imbalaced Classification and Robust Semantic Segmentation This repo implements two algoritms. The imbalance clibration (IC) algorithm for image classi

24 Jul 23, 2022
Homeautomation system created with Raspberry Pi 3 and Firebase.

Homeautomation System - Raspberry Pi 3 Desenvolvido com Python, Flask com AJAX e Firebase permite o controle local e remoto Itens necessários Raspberr

Joselino Santos 0 Mar 09, 2022
AERO 421: Spacecraft Attitude, Dynamics, and Control Final Project.

AERO - 421 Final Project Redevelopment Spacecraft Attitude, Dynamics, and Control: Simulation to determine and control a satellite's attitude in LEO.

Gagandeep Thapar 3 Dec 16, 2022
Raspberry Pi Pico support for VS Code

Pico-Go VS Code Extension Pico-Go provides code auto-completion and allows you to communicate with your Raspberry Pi Pico board using the built-in REP

Chris Wood 114 Dec 28, 2022
Smart EQ connect - Custom Integration for Home Assistant

Smart EQ Connect platform as a Custom Component for Home Assistant.

Rene Nulsch 2 Jan 04, 2022
A install script for installing qtile and my configs on Raspberry Pi OS

QPI OS - Qtile + Raspberry PI OS Qtile + Raspberry Pi OS :) Installation Run this command in the terminal

RPICoder 3 Dec 19, 2021
Provide Unifi device info via api to Home Assistant that will give ap sensors

Unifi AP Device info Provide Unifi device info via api to Home Assistant that will give ap sensors

12 Jan 07, 2023
Play music on Raspberry Pi Pico Without CPU involvement

MicroPython_PIO_Music_DMA Play music on Raspberry Pi Pico Without CPU involvement This is based on PIOBeep (https://github.com/benevpi/pico_pio_buzz)

3 Nov 27, 2022
This repo uses a stereo camera and gray-code-based structured light to realize dense 3D reconstruction.

Structured-light-stereo This repo uses a stereo camera and gray-code-based structured light to realize dense 3D reconstruction. . How to use: STEP 1:

FEI 20 Dec 31, 2022
PyTorch implementation of paper "MT-ORL: Multi-Task Occlusion Relationship Learning" (ICCV 2021)

MT-ORL: Multi-Task Occlusion Relationship Learning Official implementation of paper "MT-ORL: Multi-Task Occlusion Relationship Learning" (ICCV 2021) P

Panhe Feng 12 Oct 11, 2022
A LiteX project which builds a SoC with DRAM / HDIM output via the GPDI SYZYGY addon.

ButterStick GPDI LiteX demo A LiteX project which builds a SoC with DRAM / HDIM output via the GPDI SYZYGY addon. Getting started Connect GPDI board t

4 Nov 21, 2021
DOS-like OS for RP2040 basic microcontroller boards

Micropython DOS-like OS for RP2040 microcontroller boards. Check out the demo video at https://www.youtube.com/watch?v=Az_oiq8GE4Y To start the OS typ

RetiredWizard 58 Dec 27, 2022
A python library written for the raspberry pi.

A python package for using certain components on the raspberry pi.

Builder212 1 Nov 09, 2021
My 500 LED xmas tree

xmastree2020 This repository contains the code used for Matt's Christmas tree, as featured in "I wired my tree with 500 LED lights and calculated thei

Stand-up Maths 581 Jan 07, 2023
A versatile program that uses the raspberry pi camera and provides it as a service

PiCameleon Is a daemon program meant to provide the RaspberryPi Camera as a service while running according to a configuration.

André Esser 52 Oct 16, 2022
a library for using WS2812b leds (aka neopixels) with Raspberry Pi Pico

pico_ws2812b a library for using WS2812b leds (aka neopixels) with Raspberry Pi Pico You'll first need to save the ws2812b.py file to your device (for

76 Nov 25, 2022