Skip to content

Commit

Permalink
Added usage information as systemd service
Browse files Browse the repository at this point in the history
  • Loading branch information
gridhead committed Jul 7, 2020
1 parent 14ae442 commit 9d4ff09
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 42 deletions.
87 changes: 70 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,64 @@ An intuitive remotely-accessible system performance monitoring and task manageme

## Features
- Simplistic implementation of asynchronous periodic AJAX calls to fetch information
- Relatively low overhead from the server during stat (approx. 4MB over runtime usage)
- Relatively low overhead from the server during stat (approx. 4MB over Python 3 runtime usage)
- Easy and flexible customization of interface by replacing the assets with your own
- Tweakable refresh times for dynamic information with endpoints powered by **`psutil`**
- Report printing and dynamic refreshing buttons available at disposal
- Hybrid cross-client theming engine built with upto 21 supported theming options
- Complex process management with per-task **`TERMINATE`**, **`KILL`**, **`SUSPEND`** and **`RESUME`**

## Usage
1. Install and upgrade virtualenv if not already done by executing `pip3 install virtualenv --user`
2. Clone the repository on your local drive and make it your current working directory
3. Create a virtual environment by executing `virtualenv venv`
4. Activate the virtual environment by executing `source venv/bin/activate`
5. Install all dependencies for the project by executing `pip3 install -r requirements.txt`
6. Run the project server by executing `python3 main.py`
7. Take a note of the computer's IP address and make sure that it is reachable
8. Visit `http://<YOUR-IP-ADDRESS>:9696/primary` from the other device (or `http://localhost:9696/primary` on the same PC)
9. Take a look at the different themes available, refresh the monitor or print reports when needed.
10. When done tinkering, deactivate the virtual environment by executing `deactivate`
11. Give stars to the repository if it was helpful
- Complex process management with per-task **`TERMINATE`**, **`KILL`**, **`SUSPEND`** and **`RESUME`** operations

## Using the **`sysmon`** binary
- Download the latest binary from the [**releases**](https://github.com/t0xic0der/sysmon/releases) page.
- Make the binary **executable** by running `sudo chmod +x WebStationSYSMON`.
- **Execute** the binary with `./WebStationSYSMON -p 6969 -6`. This runs the webserver at port 6969 and is accessible via all IPv4 and IPv6 addresses.
- **Tweak** the binary to run it with the options of your liking.
```shell script
Options:
-p, --portdata TEXT Set the port value [0-65536]
-6, --ipprotv6 Start the server on an IPv6 address
-4, --ipprotv4 Start the server on an IPv4 address
--version Show the version and exit.
--help Show this message and exit.
```
- Open up a browser in a device reachable to your PC and visit `http://<IP-ADDRESS>:<PORT-NUMBER>/primary` to get started.
- When done tinkering, **shut down** the SYSMON server by pressing `[Ctrl+C]`.
- Give stars to the repository if it was helpful.

## Enabling **`sysmon`** as a `systemd` service
- Download the latest binary from the [**releases**](https://github.com/t0xic0der/sysmon/releases) page.
- Execute `sudo nano /etc/systemd/system/WebStationSYSMON.service` and add the following lines.
```shell script
[Unit]
After=network.target

[Service]
ExecStart=/usr/local/bin/WebStationSYSMON -p 6969 -6

[Install]
WantedBy=default.target
```
The above example is a `systemd` service for the binary which would execute it on boot on port number **6969** and would be accessible to both IPv4 and IPv6 addresses.
- The following options are available for **tweaking** as per your choice.
```shell script
Options:
-p, --portdata TEXT Set the port value [0-65536]
-6, --ipprotv6 Start the server on an IPv6 address
-4, --ipprotv4 Start the server on an IPv4 address
--version Show the version and exit.
--help Show this message and exit.
```
- Copy the downloaded `WebStationSYSMON` file to `/usr/local/bin/` directory.
- Make the binary **executable** by running `sudo chmod 744 /usr/local/bin/disk-space-check.sh`.
- Make the `systemd` service file **executable** by running `sudo chmod 664 /etc/systemd/system/WebStationSYSMON.service`.
- **Reload** new `systemd` service configuration files by running `sudo systemctl daemon-reload`.
- **Enable** the newly created service by running `sudo systemctl enable WebStationSYSMON.service`.
- To **test** the script before a reboot, execute `sudo systemctl start WebStationSYSMON.service`.
- Check the service **status** by running `sudo systemctl status WebStationSYSMON.service`.
- Open up a browser in a device reachable to your PC and visit `http://<IP-ADDRESS>:<PORT-NUMBER>/primary` to get started.
- To **stop** the service, execute `sudo systemctl stop WebStationSYSMON.service` - It will start again on boot.
- To **disable** the service, execute `sudo systemctl disable WebStationSYSMON.service` - It will need **enabling** to work.
- Give stars to the repository if it was helpful.

## Screenshots

Expand Down Expand Up @@ -52,6 +91,20 @@ An intuitive remotely-accessible system performance monitoring and task manageme
### Sensors and Thermal Overview [Maroon]
![](pictures/sensinfo.png)

## Using the script
1. Install and upgrade virtualenv if not already done by executing `pip3 install virtualenv --user`.
2. Clone the repository on your local drive and make it your current working directory.
3. Create a virtual environment by executing `virtualenv venv`.
4. Activate the virtual environment by executing `source venv/bin/activate`.
5. Install all dependencies for the project by executing `pip3 install -r requirements.txt`.
6. Run the project server by executing `python3 main.py`.
7. Take a note of the computer's IP address and make sure that it is reachable.
8. Visit `http://<YOUR-IP-ADDRESS>:9696/primary` from the other device (or `http://localhost:9696/primary` on the same PC).
9. Take a look at the different themes available, refresh the monitor or print reports when needed.
10. Select processes to open up modals - `TERMINATE`, `KILL`, `SUSPEND` and `RESUME` processes at will.
11. When done tinkering, deactivate the virtual environment by executing `deactivate`.
12. Give stars to the repository if it was helpful.

## To-do
- [X] Write driver code and endpoint access code for **Processor** page
- [X] Write client-side Jinja template and AJAX calls for **Processor** information
Expand Down Expand Up @@ -97,8 +150,8 @@ An intuitive remotely-accessible system performance monitoring and task manageme
- [ ] Add functionality to switch the units for thermal data between celsius and fahrenheit
- [ ] Add an obligatory dark mode feature (for everybody else has it now)
- [ ] Change `onclick` highlighting color on dropdown menus (It is by-default `primary` for all accents)
- [ ] Package it in a binary file with [`click`](https://click.palletsprojects.com/en/7.x/) to set command-line options
- [ ] Make the binary (along with command-line options) usable as a `systemd` service
- [X] Package it in a binary file with [`click`](https://click.palletsprojects.com/en/7.x/) to set command-line options
- [X] Make the binary (along with command-line options) usable as a `systemd` service
- [ ] Add user login feature as with complex process management, control cannot be left open
- [X] `[Would not be implemented as it breaks tab-switching feature]` Replace all card tabs `anchors` with `document.location.href` attributes
- [ ] Replace all `getElementById` with JQuery methods for speed up
Expand Down
46 changes: 21 additions & 25 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,34 +1,13 @@
from flask import Flask, render_template, request, redirect, url_for, session, jsonify
import psutil, back
from flask import Flask, render_template, jsonify
import back, click

main = Flask(__name__)


# background process hmainening without any refreshing
@main.route('/background_process_test')
def background_process_test():
print("Hello")
return "nothing"


@main.route('/_stuff', methods= ['GET'])
def stuff():
cpu=str(psutil.cpu_freq(True))
return jsonify(cpu=cpu)
main = Flask(__name__)


@main.route("/virtdata/", methods=["GET"])
def virtdata():
retndata = back.GetVirtualMemoryData()
retnjson = jsonify(virttomr=retndata["Total"],
virtavbl=retndata["Available"],
virtperc=retndata["Percent"],
virtused=retndata["Used"],
virtactv=retndata["Active"],
virtbufr=retndata["Buffers"],
virtcach=retndata["Cached"],
virtshrd=retndata["Shared"],
virtslab=retndata["Slab"])
retnjson = jsonify(virtdata=retndata)
return retnjson

Expand Down Expand Up @@ -154,5 +133,22 @@ def custpage(thmcolor="maroon"):
thmcolor=thmcolor)


@click.command()
@click.option("-p", "--portdata", "portdata", help="Set the port value [0-65536]", default="9696")
@click.option("-6", "--ipprotv6", "netprotc", flag_value="ipprotv6", help="Start the server on an IPv6 address")
@click.option("-4", "--ipprotv4", "netprotc", flag_value="ipprotv4", help="Start the server on an IPv4 address")
@click.version_option(version="0.1.0", prog_name="WebStation SYSMON by t0xic0der")
def mainfunc(portdata, netprotc):
print(" * Starting WebStation SYSMON by t0xic0der...")
print(" * Port number : " + str(portdata))
netpdata = ""
if netprotc == "ipprotv6":
print(" * IP version : 6")
netpdata = "::"
elif netprotc == "ipprotv4":
print(" * IP version : 4")
netpdata = "0.0.0.0"
main.run(port=portdata, host=netpdata)

if __name__ == "__main__":
main.run(port=9696, host="0.0.0.0")
mainfunc()

0 comments on commit 9d4ff09

Please sign in to comment.