Skip to content

Commit

Permalink
Merge branch 'main' of github.com:SpikeHD/Procchi
Browse files Browse the repository at this point in the history
  • Loading branch information
SpikeHD committed Sep 29, 2023
2 parents 03fde78 + bdd1fe0 commit 654426c
Show file tree
Hide file tree
Showing 13 changed files with 214 additions and 79 deletions.
13 changes: 7 additions & 6 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ jobs:
fail-fast: false
matrix:
platform: [windows-latest, ubuntu-latest, macos-latest]
feature: ["--no-default-features", "--all-features"]

steps:
- uses: oven-sh/setup-bun@v1
Expand All @@ -50,22 +51,22 @@ jobs:

- name: Build
if: matrix.platform != 'windows-latest'
run: bun run build:bun
run: cd ./frontend && bun run build && cd ../backend && cargo build --release ${{ matrix.feature }}

- name: Build (Windows)
if: matrix.platform == 'windows-latest'
run: npm run build
run: cd ./frontend && npm run build && cd ../backend && cargo build --release ${{ matrix.feature }}

- name: Upload
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v3
if: matrix.platform != 'windows-latest'
with:
name: procchi_${{ matrix.platform }}
name: procchi-${{ matrix.platform }}-${{ matrix.feature == '--no-default-features' && 'minimal' || 'all-features' }}
path: backend/target/release/procchi

- name: Upload (Windows)
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v3
if: matrix.platform == 'windows-latest'
with:
name: procchi_${{ matrix.platform }}
name: procchi-${{ matrix.platform }}-${{ matrix.feature == '--no-default-features' && 'minimal' || 'all-features' }}
path: backend/target/release/procchi.exe
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
* [Installation](#installation)
* [Usage](#usage)
* [Examples](#examples)
* [Development](#development)
* [Developing](#developing)
* [Prerequisites](#prerequisites)
* [First Time Setup](#first-time-setup)
* [Develop](#develop)
Expand All @@ -42,7 +42,8 @@

<details>
<summary>Click to expand</summary>
<img width="1676" alt="image" src="https://github.com/SpikeHD/Procchi/assets/25207995/6ae92787-b3df-4522-a657-ad79d99c626f">
<img width="1676" alt="image" src="https://github.com/SpikeHD/Procchi/assets/25207995/e06f567f-86f2-4fb7-a375-c4b65a448288">
<img width="1676" alt="image" src="https://github.com/SpikeHD/Procchi/assets/25207995/ebcd8917-c323-4778-96a1-fa04380dab41">
</details>

# Installation
Expand Down
5 changes: 4 additions & 1 deletion backend/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ edition = "2021"
async-std = "1.12.0"
clap = { version = "4.3.21", features = ["derive"] }
include_dir = "0.7.3"
mcping = "0.2.0"
mcping = { version = "0.2.0", optional = true }
mime_guess = "2.0.4"
rpassword = "7.2.0"
serde = "1.0.188"
Expand All @@ -18,3 +18,6 @@ sha2 = "0.10.7"
sysinfo = "0.29.10"
tide = "0.16.0"
tide-http-auth = { git = "https://github.com/Atmelfan/tide-http-auth/", branch = "latest" }

[features]
plugins = ["dep:mcping"]
6 changes: 5 additions & 1 deletion backend/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,16 @@ use std::{io::Write, path::Path};
use tide::utils::async_trait;
use tide_http_auth::{BasicAuthRequest, Storage};

#[cfg(feature = "plugins")]
use crate::plugins::parse_enable_plugins;

mod resource_watcher;
mod util;
mod plugins;
mod web;

#[cfg(feature = "plugins")]
mod plugins;

static FRONTEND_DIR: Dir = include_dir!("../frontend/dist");

#[derive(Clone)]
Expand Down Expand Up @@ -144,6 +147,7 @@ fn main() {
);

// Register plugins
#[cfg(feature = "plugins")]
parse_enable_plugins(&mut app, args.plugins.clone(), args.address.clone());

println!("Starting server on port {}...", args.port);
Expand Down
2 changes: 1 addition & 1 deletion backend/src/plugins/minecraft.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,4 @@ pub async fn minecraft(_req: tide::Request<State>) -> Result<tide::Response, tid
res.set_content_type("application/json");

Ok(res)
}
}
14 changes: 10 additions & 4 deletions backend/src/plugins/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use serde::Serialize;
use crate::State;
use serde::Serialize;

mod minecraft;

Expand All @@ -11,7 +11,11 @@ struct Plugin {

static mut PLUGINS: Vec<Plugin> = vec![];

pub fn parse_enable_plugins(app: &mut tide::Server<State>, plugins: Option<String>, address: String) {
pub fn parse_enable_plugins(
app: &mut tide::Server<State>,
plugins: Option<String>,
address: String,
) {
if plugins.is_none() {
return;
}
Expand All @@ -28,7 +32,9 @@ pub fn parse_enable_plugins(app: &mut tide::Server<State>, plugins: Option<Strin
for plugin in plugins {
let endpoints = match plugin {
"minecraft" => minecraft::register(app, address.clone()),
_ => {vec![]}
_ => {
vec![]
}
};

for endpoint in endpoints {
Expand Down Expand Up @@ -57,4 +63,4 @@ async fn plugins_route(_req: tide::Request<State>) -> Result<tide::Response, tid
res.set_content_type("application/json");

Ok(res)
}
}
46 changes: 24 additions & 22 deletions frontend/src/components/Plugins/Minecraft/Minecraft.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { useEffect, useState } from 'preact/hooks'
import { StatRow } from '../../Stats/StatRow'
import { Stat } from '../../Stats/Stat'

import './Minecraft.css'

interface McData {
Expand All @@ -20,27 +23,26 @@ export function Minecraft() {
}, [])

return (
<div className="quick-stats-outer">
<div className="quick-stats-header">
<span className="quick-stats-title">Minecraft Server ({data.address})</span>
</div>

<div className="quick-stats">
<div className="stat">
<span className="stat-big">{data.players}</span>
<span className="stat-small">Players Online</span>
</div>

<div className="stat">
<span className="stat-big">{data.version}</span>
<span className="stat-small">Version</span>
</div>

<div className="stat">
<span className="stat-big">{data.latency}ms</span>
<span className="stat-small">Latency</span>
</div>
</div>
</div>
<StatRow header={`Minecraft Server (${data.address})`}>
<Stat
big={data.players.toString()}
small="Players Online"
/>

<Stat
big={data.version}
small="Version"
/>

<Stat
big={data.latency + 'ms'}
small="Latency"
/>

<Stat
big={data.description}
small="Description"
/>
</StatRow>
)
}
82 changes: 41 additions & 41 deletions frontend/src/components/QuickStats.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { bytesToReadable } from '../util/byte'
import './QuickStats.css'
import { Stat } from './Stats/Stat'
import { StatRow } from './Stats/StatRow'
import { ArrowDown } from './icons/ArrowDown'
import { ArrowUp } from './icons/ArrowUp'

Expand All @@ -18,45 +20,44 @@ export function QuickStats(props: Props) {
const swapUse = props.swapData[props.swapData.length - 1]?.used
const diskUse = Object.keys(props.diskData).map(d => props.diskData[d][props.diskData[d].length - 1].used).reduce((a, b) => a + b)
const diskTotal = Object.keys(props.diskData).map(d => props.diskData[d][props.diskData[d].length - 1].total).reduce((a, b) => a + b)
const diskDeviceCount = Object.keys(props.diskData).length
const netRecieve = Object.keys(props.networkData).map(n => props.networkData[n][props.networkData[n].length - 1].recieve).reduce((a, b) => a + b)
const netTransmit = Object.keys(props.networkData).map(n => props.networkData[n][props.networkData[n].length - 1].transmit).reduce((a, b) => a + b)
const netDeviceCount = Object.keys(props.networkData).length
const cpuPct = props.cpuData[props.cpuData.length - 1]?.used

return (
<div className="quick-stats-outer">
<div className="quick-stats-header">
<span className="quick-stats-title">Quick Stats</span>
</div>
<StatRow header={'Quick Stats'}>
<Stat
big={bytesToReadable(memoryUse)}
small={
((memoryUse / props.sysinfo.mem_size * 100) || 0).toFixed(2) + '% of total memory (' + bytesToReadable(props.sysinfo.mem_size) + ')'
}
/>

<div className="quick-stats">
<div className="stat">
<span className="stat-big">{bytesToReadable(memoryUse)}</span>
<span className="stat-small">{
((memoryUse / props.sysinfo.mem_size * 100) || 0).toFixed(2)
}% of total memory ({bytesToReadable(props.sysinfo.mem_size)})</span>
</div>
<Stat
big={bytesToReadable(swapUse)}
small={
((swapUse / props.sysinfo.swap_size * 100) || 0).toFixed(2) + '% of total swap (' + bytesToReadable(props.sysinfo.swap_size) + ')'
}
/>

<div className="stat">
<span className="stat-big">{bytesToReadable(swapUse)}</span>
<span className="stat-small">{
((swapUse / props.sysinfo.swap_size * 100) || 0).toFixed(2)
}% of total swap ({bytesToReadable(props.sysinfo.swap_size)})</span>
</div>
<Stat
big={cpuPct.toFixed(2) + '%'}
small={
props.sysinfo.cpu_brand
}
mini={true}
/>

<div className="stat">
<span className="stat-big">{cpuPct.toFixed(2)}%</span>
<span className="stat-small">
<span className="stat-mini">({props.sysinfo.cpu_brand})</span>
</span>
</div>

<div className="stat">
<span className="stat-big">{props.processList.length}</span>
<span className="stat-small">Active Processes</span>
</div>
<Stat
big={props.processList.length.toString()}
small={'Active Processes'}
/>

<div className="stat">
<span className="stat-big network-stat">
<Stat
big={(
<span className="network-stat">
<span>
{bytesToReadable(netRecieve)} <ArrowDown />
</span>
Expand All @@ -67,17 +68,16 @@ export function QuickStats(props: Props) {
{bytesToReadable(netTransmit)} <ArrowUp />
</span>
</span>
<span className="stat-small">Network RX / TX ({props.networkData.length} devices)</span>
</div>

<div className="stat">
<span className="stat-big">{bytesToReadable(diskUse)}</span>
<span className="stat-small">{
(diskUse / diskTotal * 100).toFixed(2)
}% of {props.diskData.length} disks</span>
</div>
</div>
</div>
)}
small={'Network RX / TX (' + netDeviceCount + ' devices)'}
/>

<Stat
big={bytesToReadable(diskUse)}
small={
(diskUse / diskTotal * 100).toFixed(2) + '% of ' + diskDeviceCount + ' disks'
}
/>
</StatRow>
)
}
41 changes: 41 additions & 0 deletions frontend/src/components/Stats/Stat.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@

.stat-mini {
font-size: 12px;
}

.stat {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;

width: 100%;
}

.stat-big {
font-size: 28px;
font-weight: bold;
}

.stat-small {
font-size: 14px;
font-weight: normal;
}

.network-stat {
display: flex;
flex-direction: row;

align-items: center;
}

.network-stat span {
display: flex;
flex-direction: row;

align-items: center;
}

.stat-seperator {
padding: 4px;
}
19 changes: 19 additions & 0 deletions frontend/src/components/Stats/Stat.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { VNode } from 'preact'
import './Stat.css'

interface Props {
big: string | VNode
small?: string
mini?: boolean
}

export function Stat(props: Props) {
return (
<div className="stat">
<span className="stat-big">{props.big}</span>
<span className={'stat-' + (props.mini ? 'mini' : 'small')}>
{props.small}
</span>
</div>
)
}
Loading

0 comments on commit 654426c

Please sign in to comment.