Skip to content

Commit

Permalink
Final release
Browse files Browse the repository at this point in the history
  • Loading branch information
kwaitsing committed Oct 29, 2024
1 parent 84e19c0 commit ffd4795
Show file tree
Hide file tree
Showing 11 changed files with 178 additions and 89 deletions.
4 changes: 2 additions & 2 deletions build.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
mkdir dist
#cd client && bun build --compile --minify --target=bun-linux-x64 --sourcemap ./index.ts --outfile ./ArtemisClient
#mv ArtemisClient ../dist
cd client-go && go build -o ArtemisClient && mv ArtemisClient ../dist
cd client-go && CGO_ENABLED=0 go build -o ArtemisClient && mv ArtemisClient ../dist
cd ..
cd server && bun build --compile --minify --target=bun-linux-x64 --sourcemap ./src/index.ts --outfile ./ArtemisServer
mv ArtemisServer ../dist
cd ..
cd frontend && bunx --bun vite build && mv ./dist ../dist/frontend
cd frontend && bunx --bun vite build && mv ./dist ../dist/frontend && cd ../dist && tar zcvf frontend.tar.gz frontend/ && rm -rf ./frontend
43 changes: 0 additions & 43 deletions client-go/command.go

This file was deleted.

2 changes: 1 addition & 1 deletion client-go/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func get_location() {
func getOneTimeData() {
hi, err := host.Info()
if err == nil {
serverData.Uptime = uint64(time.Now().Unix()) - hi.BootTime
serverData.Uptime = hi.BootTime
}
}

Expand Down
49 changes: 42 additions & 7 deletions client-go/main.go
Original file line number Diff line number Diff line change
@@ -1,22 +1,57 @@
package main

import (
"fmt"
"os"
"os/signal"
"syscall"

"github.com/spf13/cobra"
)

var GlobalConfiguration GlobalConfigure

var serverData ServerObj

func main() {
var rootCmd = &cobra.Command{
Use: "ArtemisClient",
Short: "ArtemisClient - HPFS server monitor",
Long: `
ArtemisClient [email protected]
Artemis is an HPFS server monitor
for more information please checkout
https://github.com/kwaitsing/Artemis`,
Run: func(cmd *cobra.Command, args []string) {

serverData = ServerObj{
Name: GlobalConfiguration.Name,
Location: "trans",
}

interrupt := make(chan os.Signal, 1)
signal.Notify(interrupt, os.Interrupt, syscall.SIGTERM)
interrupt := make(chan os.Signal, 1)
signal.Notify(interrupt, os.Interrupt, syscall.SIGTERM)
go socket()

initVar()
go socket()
// Die Brutally
<-interrupt
os.Exit(0)
},
}
rootCmd.SilenceUsage = true
rootCmd.SilenceErrors = true
rootCmd.PersistentFlags().StringVarP(&GlobalConfiguration.Remote, "remote", "r", "ws://127.0.0.0:9702", "Remote WS Server")
rootCmd.PersistentFlags().StringVarP(&GlobalConfiguration.Key, "key", "k", "oATqKPjF72wau8MdJPhV", "Auth key")
rootCmd.PersistentFlags().StringVarP(&GlobalConfiguration.Name, "name", "n", "Infra", "Name of the server")
rootCmd.PersistentFlags().Float32VarP(&GlobalConfiguration.UpdInterval, "updateInterval", "u", 1.2, "Update interval in seconds")
rootCmd.PersistentFlags().BoolVarP(&GlobalConfiguration.Verbose, "verbose", "v", false, "Enable verbose")

// Die Brutally
<-interrupt
os.Exit(2)
if err := rootCmd.Execute(); err != nil {
if rootCmd.Flags().Lookup("help").Changed {
fmt.Println(rootCmd.Long)
return
} else {
fmt.Println("Error:", err)
}
}
}
31 changes: 28 additions & 3 deletions documents/enduser.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
If you get Illegal instruction then simple build the executable you need like this
`bun build --compile --minify --target=bun-linux-x64-baseline --sourcemap ./src/index.ts --outfile ./ArtemisServer`

# Client args
# Client

> Args
|arg|default|desc|
| :----: | :----: | :----: |
Expand All @@ -19,11 +21,24 @@ If you get Illegal instruction then simple build the executable you need like th
|-u/--updateinterval|1.2|Report Interval|
|-v/--verbose|false|Enable Verbose|

> Deployment with script
```bash
curl -fsSL https://github.com/kwaitsing/Artemis/releases/download/pkg/install_client.sh >install_client.sh

# arg1: Server WS Addr
# arg2: Server Name(shouldn't be the same with any other servers)
# arg3: passkey
bash install_client.sh ws://example.com MyServer EPdnpTjAr0EV5yuDXFf5
```

> Example cmdline
`./client -r ws://example.com:9702 -k 'meowmeowmeow' -n 'NyaServer' -u 2.1 -v`

# Server args
# Server

> Args
|arg|default|desc|
| :----: | :----: | :----: |
Expand All @@ -32,4 +47,14 @@ If you get Illegal instruction then simple build the executable you need like th

> Example cmdline
`./server -p 9011 -k 'meowmeowmeow'`
`./server -p 9011 -k 'meowmeowmeow'`

> Deployment
1. make sure `caddy` is installed in your system
2. Navi to ../setup and execute `./install_server.sh`
3. `nano /opt/Artemis/ArtemisServer.service` to modify the config file
4. Navi to ../server/Caddyfile, read the comments in it
5. Copy or rewrite the configuration to your Caddyfile/Nginx conf
6. Download `frontend.tar.gz` and configure it as the example Caddyfile described
7. do `systemctl enable --now ArtemisServer.service` to launch the server
14 changes: 12 additions & 2 deletions frontend/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ function App() {
timestamp: number
}>()

const [currentTS, setCurrentTS] = useState(Math.floor(new Date().getTime() / 1000));

useEffect(() => {
setInterval(async () => {
try {
Expand All @@ -28,6 +30,14 @@ function App() {
}, 1000)
}, [])

useEffect(() => {
const int = setInterval(() => {
setCurrentTS(Math.floor(new Date().getTime() / 1000));
}, 1000);

return () => clearInterval(int);
}, []);

if (loading || !data) return <Loading msg={'Loading data from artemis server'} />

return (
Expand All @@ -37,15 +47,15 @@ function App() {
</header>
<article className='no-round no-margin'>
<div className='large-margin' style={{ overflowX: 'auto' }}>
<ServerTable servers={data.servers} />
<ServerTable currentTS={currentTS} servers={data.servers} />
</div>
</article>


<div className='medium-padding center-align' style={{ display: 'flex' , gap: '20px', flexWrap: 'wrap'}}>
{
data.servers.map((server) => {
return <ServerCard key={server.name} data={server} />
return <ServerCard currentTS={currentTS} key={server.name} data={server} />
})
}
</div>
Expand Down
21 changes: 5 additions & 16 deletions frontend/src/components/ServerCard.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,11 @@
import { hread, secondsToTime } from "toolbx"
import { serverInStore } from "../../../server/src/type"
import { useEffect, useState } from "react";

export const ServerCard = (props: {
currentTS: number
data: serverInStore
}) => {

const [currentTS, setCurrentTS] = useState(Math.floor(new Date().getTime() / 1000));

useEffect(() => {
const int = setInterval(() => {
setCurrentTS(Math.floor(new Date().getTime() / 1000));
}, 1000);

return () => clearInterval(int);
}, []);

const Huptime = secondsToTime(props.data.uptime)
const Huptime = secondsToTime(props.currentTS - props.data.uptime)

const CPUusage = Math.round(props.data.cpu * 100) / 100

Expand All @@ -43,18 +32,18 @@ export const ServerCard = (props: {
<div className="row">
<div>
<img className="large" src={`/client/${props.data.location}.svg`} /><br />
<div className={`chip responsive no-margin ${currentTS - props.data.timestamp > 60 ? 'red' : 'green'}`}><i>{currentTS - props.data.timestamp > 60 ? 'close' : 'verified'}</i></div>
<div className={`chip responsive no-margin ${props.currentTS - props.data.timestamp > 60 ? 'red' : 'green'}`}><i>{props.currentTS - props.data.timestamp > 60 ? 'close' : 'verified'}</i></div>
</div>
<div className="max">
<h5>{props.data.name}</h5>
<i>snowing_heavy</i><br /><span>Load: {props.data.loadAVG}</span><br />
<i>restart_alt</i><br /><span>Uptime: {Huptime.num} {Huptime.unit}</span>
</div>
<div className="max">
<span><i>wifi</i> NW Total: </span><br />
<span><i>bar_chart</i> NW Tot: </span><br />
<span>{HnetworkTX.num}{HnetworkTX.unit}</span><br />
<span>{HnetworkRX.num}{HnetworkRX.unit}</span><br />
<span><i>public</i> NW Current: </span><br />
<span><i>settings_ethernet</i> NW RT: </span><br />
<span>{HCnetworkTX.num}{HCnetworkTX.unit}</span><br />
<span>{HCnetworkRX.num}{HCnetworkRX.unit}</span><br />
</div>
Expand Down
16 changes: 4 additions & 12 deletions frontend/src/components/ServerTable.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { secondsToTime, hread } from "toolbx"
import { serverInStore } from "../../../server/src/type"
import { useState, useEffect } from "react"

export const ServerTable = (props: {
currentTS: number
servers: serverInStore[]
}) => {

Expand Down Expand Up @@ -35,16 +35,8 @@ export const ServerTable = (props: {
<tbody>
{
props.servers.map((server) => {
const [currentTS, setCurrentTS] = useState(Math.floor(new Date().getTime() / 1000));

useEffect(() => {
const int = setInterval(() => {
setCurrentTS(Math.floor(new Date().getTime() / 1000));
}, 1000);

return () => clearInterval(int);
}, []);
const Huptime = secondsToTime(server.uptime)

const Huptime = secondsToTime(props.currentTS - server.uptime)

const CPUusage = Math.round(server.cpu * 100) / 100

Expand All @@ -62,7 +54,7 @@ export const ServerTable = (props: {
return (
<tr key={server.name} onClick={() => jumpToSrvCard(server.name)}>
<td>
<div className={`chip no-margin ${currentTS - server.timestamp > 60 ? 'red' : 'green'}`}><i>{currentTS - server.timestamp > 60 ? 'close' : 'verified'}</i></div>
<div className={`chip no-margin ${props.currentTS - server.timestamp > 60 ? 'red' : 'green'}`}><i>{props.currentTS - server.timestamp > 60 ? 'close' : 'verified'}</i></div>
</td>
<td><img className="large" src={`/client/${server.location}.svg`} /></td>
<td>{server.name}</td>
Expand Down
10 changes: 7 additions & 3 deletions server/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,11 @@ const serverConf: IgniteConf = {
}

urn.igniteInstance(serverConf)

logger(`+ Artemis running on ${serverConf.hostname}:${serverConf.port}`, 0)

logger(`
ArtemisServer [email protected]
Artemis is an HPFS server monitor
for more information please checkout
https://github.com/kwaitsing/Artemis
`, 0)
logger(` Artemis running on ${serverConf.hostname}:${serverConf.port}\n`, 3)
export type App = typeof instance
41 changes: 41 additions & 0 deletions setup/install_client.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
$!/bin/bash

if [[ $EUID -ne 0 ]]; then
echo "Error: This script must be run as root."
exit 1
fi

if [ -z "$1" ]; then
echo "Error: No WSremote supplied."
exit 1
fi

if [ -z "$2" ]; then
echo "Error: No name supplied."
exit 1
fi

if [ -z "$3" ]; then
echo "Error: No Passkey supplied."
exit 1
fi

# Create Folder
mkdir -p /opt/Artemis/

# Copy Service
echo -n "[Unit]
Description=ArtemisClient
After=multi-user.target
Wants=multi-user.target
[Service]
User=root
ExecStart=/opt/Artemis/ArtemisClient -r \"$1\" -n \"$2\" -k \"$3\"
Restart=on-failure
[Install]
WantedBy=multi-user.target" >/opt/ArtemisArtemisClient.service

# Download Core and
cd /opt/Artemis && curl -L 'https://github.com/kwaitsing/Artemis/releases/download/pkg/ArtemisClient' >ArtemisClient && chmod +x ArtemisClient && ln -sf /opt/Artemis/ArtemisClient.service /etc/systemd/system/
Loading

0 comments on commit ffd4795

Please sign in to comment.