Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v0.8 #1

Merged
merged 4 commits into from
Jan 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
[![Stargazers][stars-shield]][stars-url]
[![Issues][issues-shield]][issues-url]

### Simple cli system monitor written in Go
### Simple System monitor written in Go

![Sample](contents/tittle.png)
![SampleWeb](contents/webscreen.png)
Expand All @@ -21,6 +21,10 @@ On cmd mode it uses a time interval for refreshing detail and its helpful for be

for webserver mode, you can pass port argument to set your own port. by default the port is 8080

## Releases

go to the releases page to download the right binary for your Operating system

## Requirements

- go1.18 or above is required.
Expand All @@ -35,6 +39,8 @@ go build .

## Usage

ProcTop by default runs web server mode, for running cli mode pass the -cli to the program

`proc-top` arguments

```
Expand Down Expand Up @@ -64,5 +70,5 @@ Licensed under the [GPL-3][license] license.
[issues-url]: https://github.com/SonyaCore/proc-top/issues
[goversion]: https://img.shields.io/github/go-mod/go-version/SonyaCore/proc-top/master
[go]: https://img.shields.io/badge/Go-cyan?logo=go
[version]: https://img.shields.io/badge/Version-0.7-blue
[version]: https://img.shields.io/badge/Version-0.8-blue
[license]: LICENSE
Binary file modified contents/webscreen.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 5 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ import (
"flag"
"fmt"
"os"
"proc-top/colors"
"proc-top/src/host"
"proc-top/src/cli/host"
"proc-top/utils"
"proc-top/utils/colors"
"runtime"
"strings"
"time"

cpu "proc-top/src/cpu"
disk "proc-top/src/disk"
memory "proc-top/src/memory"
cpu "proc-top/src/cli/cpu"
disk "proc-top/src/cli/disk"
memory "proc-top/src/cli/memory"
procserver "proc-top/src/server"
)

Expand Down
2 changes: 1 addition & 1 deletion src/cpu/cpu.go → src/cli/cpu/cpu.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package cpu
import (
"fmt"
"log"
"proc-top/colors"
"proc-top/utils/colors"

"github.com/shirou/gopsutil/v3/cpu"
)
Expand Down
2 changes: 1 addition & 1 deletion src/disk/disk.go → src/cli/disk/disk.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package disk
import (
"fmt"
"log"
"proc-top/colors"
"proc-top/utils"
"proc-top/utils/colors"

"github.com/shirou/gopsutil/v3/disk"
)
Expand Down
2 changes: 1 addition & 1 deletion src/host/host.go → src/cli/host/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package host
import (
"fmt"
"log"
"proc-top/colors"
"proc-top/utils/colors"
"strconv"

"github.com/shirou/gopsutil/load"
Expand Down
2 changes: 1 addition & 1 deletion src/memory/memory.go → src/cli/memory/memory.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package memory
import (
"fmt"
"log"
"proc-top/colors"
"proc-top/utils"
"proc-top/utils/colors"

"github.com/shirou/gopsutil/v3/mem"
)
Expand Down
3 changes: 1 addition & 2 deletions src/proc/proc.go → src/cli/proc/proc.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@ package proc
import (
"fmt"
"log"
"proc-top/colors"
"proc-top/utils/colors"

"github.com/shirou/gopsutil/v3/process"
)

var (
g = colors.Green
r = colors.Reset
p = colors.Purple
)

func Proc() {
Expand Down
6 changes: 6 additions & 0 deletions src/server/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,12 @@
<canvas id="c_swapusage" width="240" height="96"></canvas>
</div>
</div>
<footer class="footer">
<div>
<p class="kernelinfo" id="kernel"></p>
<p class="avg" id="loadaverage"></p>
</div>
</footer>
<script src="jquery-3.6.3.min.js"></script>
<script src="https://rawcdn.githack.com/joewalnes/smoothie/e269d8b81b03752c865a4b852f7d094091bfcd85/smoothie.js"></script>
<script src="script.js"></script>
Expand Down
6 changes: 6 additions & 0 deletions src/server/public/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,12 @@
$("#swapusage").text(util.bytes(n[1]));
g.swapusage.t.append(+new Date(), n[3]);
};
handler.kernel = function (s) {
$("#kernel").text(s);
};
handler.loadaverage = function (s) {
$("#loadaverage").text(s);
};
var count = 0,
errors = 0;
var latency = 0;
Expand Down
34 changes: 34 additions & 0 deletions src/server/public/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,37 @@ body {
padding-top: 0;
padding-bottom: 2%;
}
.footer {
font-size: 12px;
position: fixed;
bottom: 0;
left: 0;
width: 100%;
text-decoration: none;
min-height: 2.1em;
height: 2.1em;
background-color: rgb(44, 41, 41);
color: white;
text-align: center;
border-top: 3px solid rgb(54, 54, 57);
justify-content: space-between;
}
.kernelinfo {
padding-right: 30px;
font-size: 1em;
margin-top: 0.5em;
float: right;
text-align: center;
text-decoration: none;
border-radius: 50%;
margin-bottom: 1em;
}
.avg {
font-size: 1em;
margin-top: 0.5em;
text-align: left;
padding-left: 30px;
float: left;
word-spacing: 2px;
margin-bottom: 0.5em;
}
10 changes: 10 additions & 0 deletions src/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"github.com/shirou/gopsutil/cpu"
"github.com/shirou/gopsutil/disk"
"github.com/shirou/gopsutil/host"
"github.com/shirou/gopsutil/load"
"github.com/shirou/gopsutil/mem"
"github.com/shirou/gopsutil/net"
)
Expand Down Expand Up @@ -78,6 +79,12 @@ func Start(port int) {
var stats = make(map[string]interface{})

func update() {
platfrom, _, _, _ := host.PlatformInformation()
kernel_version, _ := host.KernelVersion()
kernel_arch, _ := host.KernelArch()
platfrominfo := fmt.Sprintf("%v %v %v", platfrom, kernel_version, kernel_arch)

stats["kernel"] = platfrominfo
for {
diskused := uint64(0)
disktotal := uint64(0)
Expand All @@ -95,6 +102,8 @@ func update() {
nio, _ := net.IOCounters(false)
niodict := nio[0]
swap, _ := mem.SwapMemory()
load, _ := load.Avg()
loadstatus := fmt.Sprintf("%.2f %.2f %.2f", load.Load1, load.Load5, load.Load15)

stats["uptime"] = uptime
stats["fqdn"], _ = os.Hostname()
Expand All @@ -113,6 +122,7 @@ func update() {
stats["swapusage"] = [6]uint64{swap.Total, swap.Used,
swap.Free, uint64(swap.UsedPercent),
swap.Sin, swap.Sout}
stats["loadaverage"] = loadstatus
time.Sleep(1 * time.Second)
}
}
27 changes: 27 additions & 0 deletions utils/colors/colors.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package colors

import "runtime"

var Reset = "\033[0m"
var Red = "\033[31m"
var Green = "\033[32m"
var Yellow = "\033[33m"
var Blue = "\033[34m"
var Purple = "\033[35m"
var Cyan = "\033[36m"
var Gray = "\033[37m"
var White = "\033[97m"

func init() {
if runtime.GOOS == "windows" {
Reset = ""
Red = ""
Green = ""
Yellow = ""
Blue = ""
Purple = ""
Cyan = ""
Gray = ""
White = ""
}
}