mirror of
https://github.com/JonasunderscoreJones/PI-server-rack.git
synced 2025-10-22 17:29:17 +02:00
Preparing for v0.1.1
This commit is contained in:
parent
6a8e2379e9
commit
59c3b90e0b
3 changed files with 74 additions and 43 deletions
|
@ -1,6 +1,9 @@
|
|||
# PI-MC-WATCHER
|
||||
A system that allows Monitoring of Raspberry PI('s) and it's running Minecraft Server(s) on PC and Mac
|
||||
|
||||
## Why?
|
||||
Because I can. Overcomplicated stupid projects are a lot of fun.
|
||||
|
||||
## What it is about
|
||||
The system contains of three parts. Those are the **PC Module**, **RPi Master Module** and ** RPi Slave Module**
|
||||
|
||||
|
|
92
pc/main.py
92
pc/main.py
|
@ -1,23 +1,40 @@
|
|||
VERSION = "0.1.1"
|
||||
|
||||
from ftplib import FTP
|
||||
from io import BytesIO
|
||||
from time import sleep, time
|
||||
from xml.sax.handler import feature_namespace_prefixes
|
||||
|
||||
launch_time = time()
|
||||
|
||||
print("Starting PI-MC-WATCHER v" + VERSION + " for PC and Mac")
|
||||
print("Initializing...")
|
||||
|
||||
# wehther or not to print the stats to the console
|
||||
print_stats = True
|
||||
|
||||
# The credentials for the ftp server. These must be tweaked.
|
||||
hostname = "172.24.1.193"
|
||||
username = "testuser"
|
||||
password = "uwu"
|
||||
|
||||
# defining the name of the file the stats are saved to
|
||||
filename = "output.txt"
|
||||
|
||||
print("Connecting to FTP server...")
|
||||
|
||||
ftp = FTP(hostname, username, password)
|
||||
ftp.encoding = "utf-8"
|
||||
|
||||
filename = "output.txt"
|
||||
print("Connected!")
|
||||
|
||||
start_time = time()
|
||||
|
||||
print("All setup!")
|
||||
|
||||
# permits user to read console logs from above. Can be removed to accelerate start.
|
||||
sleep(3)
|
||||
|
||||
while True:
|
||||
start_time = time()
|
||||
|
||||
with open(filename, "wb") as file:
|
||||
# use FTP's RETR command to download the file
|
||||
|
@ -26,39 +43,46 @@ while True:
|
|||
file = open(filename, 'r')
|
||||
content = file.read()
|
||||
content = content.split(";")
|
||||
# it is possible for the program to fetch the output text file right inbetween when the program on the Master PI cleared it and before it writes the stats.
|
||||
# This sends an error message in the rare case of this occuring.
|
||||
try:
|
||||
fanmode = content[0]
|
||||
slave_fanmode = content[1]
|
||||
fanspeed = content[2]
|
||||
fanspeed2 = content[3]
|
||||
thermal = content[4]
|
||||
slave_thermal = content[5]
|
||||
cpu_usage = content[6]
|
||||
cpu_freq = content[7]
|
||||
cpu_up = content[8]
|
||||
total_ram = content[9]
|
||||
ram_usage = content[10]
|
||||
ram_free = content[11]
|
||||
ram_percent = content[12]
|
||||
swap_percent = content[13]
|
||||
disk_percent = content[14]
|
||||
|
||||
fanmode = content[0]
|
||||
slave_fanmode = content[1]
|
||||
fanspeed = content[2]
|
||||
fanspeed2 = content[3]
|
||||
thermal = content[4]
|
||||
slave_thermal = content[5]
|
||||
cpu_usage = content[6]
|
||||
cpu_freq = content[7]
|
||||
cpu_up = content[8]
|
||||
total_ram = content[9]
|
||||
ram_usage = content[10]
|
||||
ram_free = content[11]
|
||||
ram_percent = content[12]
|
||||
swap_percent = content[13]
|
||||
disk_percent = content[14]
|
||||
mc_motd = content[15]
|
||||
mc_version = content[16]
|
||||
mc_players_max = content[17]
|
||||
mc_players_on = content[18]
|
||||
mc_version_brand = content[19]
|
||||
mc_plugins = content[20]
|
||||
mc_playerlist = content[21]
|
||||
except:
|
||||
# The error message to display if the above explained happens
|
||||
print("WARNING: Couldn't read the file's data. If this doesn't happen a lot, just ignore this warning.")
|
||||
|
||||
mc_motd = content[15]
|
||||
mc_version = content[16]
|
||||
mc_players_max = content[17]
|
||||
mc_players_on = content[18]
|
||||
mc_version_brand = content[19]
|
||||
mc_plugins = content[20]
|
||||
mc_playerlist = content[21]
|
||||
|
||||
sleep(2)
|
||||
|
||||
stop_time = time()
|
||||
|
||||
if print_stats:
|
||||
print("---------- Uptime: " + str(cpu_up) + " ----------")
|
||||
print("Loop time:\t" + str(round(stop_time - start_time, 2)) + "\ts")
|
||||
print("CMD Uptime:\t" + str(round(stop_time - launch_time, 2)) + "\ts")
|
||||
# loop_time and stop_time won't be available on the first run as they haven't been measured yet. Therefore this fallback is needed.
|
||||
try:
|
||||
print("Loop time:\t" + str(round(loop_time, 2)) + "\ts")
|
||||
print("CMD Uptime:\t" + str(round(stop_time - launch_time, 2)) + "\ts")
|
||||
except:
|
||||
print("Loop time:\t--.--\ts")
|
||||
print("CMD Uptime:\t--.--\ts")
|
||||
print("CPU")
|
||||
print("\tusage:\t" + str(cpu_usage) + "\t%")
|
||||
print("\tfreq:\t" + str(cpu_freq) + "\tMHz")
|
||||
|
@ -74,6 +98,8 @@ while True:
|
|||
print("\tglobal:\t" + str(fanspeed) + "\t%")
|
||||
print("\t2ndary:\t" + str(fanspeed2) + "\t%")
|
||||
|
||||
sleep(2)
|
||||
|
||||
# Close the Connection
|
||||
ftp.quit()
|
||||
stop_time = time()
|
||||
loop_time = stop_time - start_time
|
||||
start_time = time()
|
|
@ -1,3 +1,5 @@
|
|||
VERSION = "0.1.1"
|
||||
|
||||
from http import server
|
||||
import RPi.GPIO as GPIO
|
||||
import subprocess, os, time, psutil
|
||||
|
@ -10,7 +12,7 @@ print_stats = True
|
|||
ignore_slave = True
|
||||
|
||||
# Starting Messages
|
||||
print("Starting PI-MC-WATCHER v0.0.1 for RPi")
|
||||
print("Starting PI-MC-WATCHER v" + VERSION + " for RPi")
|
||||
print("Processing first loop. Each loop takes 5 seconds...")
|
||||
print("\n")
|
||||
if print_stats:
|
||||
|
@ -42,7 +44,7 @@ GPIO.setup(17, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
|
|||
GPIO.setup(18, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
|
||||
|
||||
# setting up control pin for fancontrol
|
||||
GPIO.setup(244, GPIO.OUT)
|
||||
GPIO.setup(4, GPIO.OUT)
|
||||
|
||||
# setting up power pin for second fancontrol
|
||||
GPIO.setup(25, GPIO.OUT)
|
||||
|
@ -218,31 +220,31 @@ while True:
|
|||
|
||||
|
||||
if fanmode == 100:
|
||||
GPIO.output(24, True)
|
||||
GPIO.output(4, True)
|
||||
time.sleep(2)
|
||||
elif fanmode == 75:
|
||||
while i < 6:
|
||||
GPIO.output(24, True)
|
||||
GPIO.output(4, True)
|
||||
time.sleep(0.3)
|
||||
GPIO.output(24, False)
|
||||
GPIO.output(4, False)
|
||||
time.sleep(0.1)
|
||||
i = i + 1
|
||||
elif fanmode == 50:
|
||||
while i < 6:
|
||||
GPIO.output(24, True)
|
||||
GPIO.output(4, True)
|
||||
time.sleep(0.2)
|
||||
GPIO.output(24, False)
|
||||
GPIO.output(4, False)
|
||||
time.sleep(0.2)
|
||||
i = i + 1
|
||||
elif fanmode == 25:
|
||||
while i < 6:
|
||||
GPIO.output(24, True)
|
||||
GPIO.output(4, True)
|
||||
time.sleep(0.1)
|
||||
GPIO.output(24, False)
|
||||
GPIO.output(4, False)
|
||||
time.sleep(0.3)
|
||||
i = i + 1
|
||||
else:
|
||||
GPIO.output(24, True)
|
||||
GPIO.output(4, True)
|
||||
time.sleep(2)
|
||||
|
||||
# write all data to list
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue