Git Product home page Git Product logo

sys_stats_restful's Introduction

Sys Stats Restful

README 中文版

I just simply need a restful API that can tell the HA (Home Assistant) service about CPU temperature of the home router, which is running over KVM virtualization on a compact size SBC with only passive cooling. So the data collected comes directly from the host OS instead of the router (on vm).

screenshot1 screenshot2

So this is it, done in kinda less than 3 hours, not quite sophisticated or flexible though.

What can this offer

curl http://<hostname>:9090/stats/<data_type>

The data_type can be either du, temps, boot_time for now. Then it can returns the sensor data immediately.

curl http://192.168.12.34:9090/stats/temps

{
    "code": 0,
    "status": "success",
    "data": {
        "cpu_thermal": {
            "curr": 57.78,
            "crit": 100.0
        },
        "gpu_thermal": {
            "curr": 57.22,
            "crit": 95.0
        }
    }
}

How To Make This Work

  1. Clone the repo, and set up python3 based virtual env.
  2. Install the pip dependencies using the requirements.txt included.
  3. Run the service with python entry.py.
  4. Check if the service works well through http clients like curl http://<hostname>:9090/stats.
  5. Optional - if it's all good, refer the sys_stats_restful.service to set up systemd service, then the service can survive after reboot.
  6. Optional - integrate the service with HA by the to_be_placed_in_ha_configuration.yaml to show the data on HA dash.

Configuration of my HW/OS

  1. An ARM based SBC (Asus Tinker Board 2s) with Armbian as host OS, kernel version 6.1.x #1 SMP PREEMPT aarch64 GNU/Linux.
  2. OpenWrt Snapshot 23.x runs over KVM on the Armbian, which has 2 virtual eth interfaces bridged with 802.1q VLAN interfaces of Armbian.
  3. The CPU and GPU temperature of the SBC can be viewed by sensors in terminal after apt install lm-sensors.
  4. This service can be deployed either in Armbian (on bare metal hardware) or docker/lxc if you prefer, as long as the code can extract the necessary data from certain paths of host OS. I suppose a deployment in KVM based vm is NOT OK because the data can not be fetched in that level of hardware isolation.

sys_stats_restful's People

Contributors

fisherworks avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.