Skip to content

Commit 6ec53c2

Browse files
committed
update
1 parent 1debd9d commit 6ec53c2

File tree

15 files changed

+1273
-1
lines changed

15 files changed

+1273
-1
lines changed

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2024 a Dark Dev
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 236 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,237 @@
11
# SysSpecter
2-
System analyzer API for linux ! writen in golang.
2+
<div align="center">
3+
<img alt="Linux" src="https://img.shields.io/static/v1?style=for-the-badge&message=Linux&color=222222&logo=Linux&logoColor=FCC624&label=">
4+
<img alt="Go" src="https://img.shields.io/static/v1?style=for-the-badge&message=Go&color=00ADD8&logo=Go&logoColor=FFFFFF&label=">
5+
<img alt="Simple Analytics" src="https://img.shields.io/static/v1?style=for-the-badge&message=Analytics&color=FF4F64&logo=Simple+Analytics&logoColor=FFFFFF&label=">
6+
</div>
7+
8+
<div align="center">
9+
<img alt="GitHub go.mod Go version" src="https://img.shields.io/github/go-mod/go-version/aDarkDev/SysSpecter">
10+
<img alt="GoDoc" src="https://img.shields.io/github/languages/top/aDarkDev/SysSpecter">
11+
<a url="https://pkg.go.dev/github.com/valyala/fasthttp"><img alt="GoDoc" src="https://pkg.go.dev/badge/github.com/valyala/fasthttp"></a>
12+
<img alt="GitHub commits since tagged version (branch)" src="https://img.shields.io/github/commits-since/aDarkDev/SysSpecter/v1.1/main">
13+
<img alt="GitHub Repo stars" src="https://img.shields.io/github/stars/aDarkDev/SysSpecter">
14+
<img alt="GitHub forks" src="https://img.shields.io/github/forks/aDarkDev/SysSpecter">
15+
</div>
16+
17+
<!-- PROJECT LOGO -->
18+
<br />
19+
<div align="center">
20+
<a href="https://github.com/aDarkDev/SysSpecter">
21+
<img src="images/logo.png" alt="Logo" width="300" height="300">
22+
</a>
23+
24+
<h3 align="center">SysSpecter</h3>
25+
26+
<p align="center">
27+
Welcome to SysSpecter - System Analyzer API for linux!
28+
<br />
29+
<br />
30+
·
31+
<a href="https://github.com/aDarkDev/SysSpecter/issues">Report Bug</a>
32+
·
33+
<a href="https://github.com/aDarkDev/SysSpecter/issues">Request Feature</a>
34+
</p>
35+
</div>
36+
37+
SysSpecter is a comprehensive tool designed to monitor and report various aspects of network traffic and system status. It offers real-time insights into network connections, interface lists, system performance, memory usage, disk space, and more, making it an invaluable resource for system administrators and network engineers.
38+
39+
## Features
40+
41+
- **Network Traffic Analysis**: Monitor incoming and outgoing network traffic, including bytes, packets, errors, and dropped packets.
42+
- **System Health Monitoring**: Keep tabs on the overall status of your system, including memory usage and disk space.
43+
- **Real-Time Updates**: Get per-second updates on network traffic to identify potential issues promptly.
44+
45+
46+
To install SysSpecter, clone this repository to your local machine:
47+
48+
```bash
49+
git clone https://github.com/aDarkDev/SysSpecter.git
50+
cd SysSpecter
51+
```
52+
53+
next install golang:
54+
55+
```bash
56+
sudo apt install golang-go
57+
```
58+
59+
next install require libraries:
60+
61+
```bash
62+
go mod tidy
63+
```
64+
65+
ًRun:
66+
```bsah
67+
sudo go run .
68+
```
69+
70+
<div align="center">
71+
<img alt="ScriptPic" src="images/script-image.png">
72+
</div>
73+
74+
Or you can use latest compiled file from [here](https://github.com/aDarkDev/SysSpecter/releases)
75+
## Usage
76+
77+
After installation, you can start the SysSpecter service. Here are some examples of how to use the available endpoints:
78+
79+
80+
### Get Network Traffic per Second
81+
82+
```bash
83+
curl http://localhost:port/network/traffic/per_second
84+
```
85+
86+
Example Response:
87+
```json
88+
{"incoming": 2.51,"outgoing": 0.21}
89+
```
90+
### List Network Interfaces
91+
92+
```bash
93+
curl http://localhost:port/network/interface_list
94+
```
95+
96+
Example Response:
97+
```json
98+
["docker0","lo","nekoray-tun","wlo1"]
99+
```
100+
101+
### Get Network Connections
102+
103+
```bash
104+
curl http://localhost:port/network/connections
105+
```
106+
107+
Example Response:
108+
```json
109+
[
110+
{
111+
"dest_ip": "127.0.0.1",
112+
"dest_port": "8877",
113+
"source_ip": "127.0.0.1",
114+
"source_port": "53492",
115+
"protocol":"tcp"
116+
},
117+
{
118+
"dest_ip": "142.250.185.66",
119+
"dest_port": "443",
120+
"source_ip": "172.19.0.1",
121+
"source_port": "41714",
122+
"protocol":"tcp"
123+
}
124+
...
125+
]
126+
```
127+
128+
### System Status
129+
130+
```bash
131+
curl http://localhost:port/system/status
132+
```
133+
134+
Example Response:
135+
```json
136+
{
137+
"cpu_count": 8,
138+
"cpu_usage": 5.569620253177614,
139+
"mem_size": 15685.328125,
140+
"mem_usage": 25.0707020195027,
141+
"uptime_int": 39155,
142+
"uptime_str": "0 day(s) 10 hour(s) 52 min(s)"
143+
}
144+
```
145+
146+
### Memory info
147+
148+
```bash
149+
curl http://localhost:port/system/memory
150+
```
151+
152+
Example Response:
153+
```json
154+
{
155+
"mem_alloc": 974296,
156+
"mem_heap_alloc": 974296,
157+
"mem_size": 15685.328125,
158+
"mem_swap": 1024454656,
159+
"mem_sys": 13781776,
160+
"mem_total_alloc": 3719680
161+
}
162+
```
163+
164+
### Disks info
165+
166+
```bash
167+
curl http://localhost:port/system/disks
168+
```
169+
170+
Example Response:
171+
```json
172+
{
173+
"/": 25.907221257048235,
174+
"/boot/efi": 36.42069498697917,
175+
"/dev": 0,
176+
"/dev/hugepages": 0,
177+
"/dev/mqueue": 0,
178+
"/dev/pts": 0,
179+
"/dev/shm": 0.8571405802197716,
180+
"/home/ghost": 25.907221257048235,
181+
"/proc": 0,
182+
"/proc/sys/fs/binfmt_misc": 0,
183+
"/run": 0.6352961685489796,
184+
"/run/credentials/systemd-sysusers.service": 0,
185+
"/run/lock": 0.078125,
186+
"/run/user/1000": 0.009214432291355368,
187+
"/run/user/1000/doc": 0,
188+
"/run/user/1000/gvfs": 0,
189+
"/snap/code/149": 100,
190+
}
191+
```
192+
193+
### Network Traffic graph
194+
195+
- `curl http://localhost:port/network/traffic/graph`
196+
- Html live graph, open in browser: `http://localhost:port/network/traffic/live_graph`
197+
198+
<div style="display: flex; justify-content: space-between; align-items: center;">
199+
<img src="https://github.com/aDarkDev/SysSpecter/assets/121636230/721bb665-da5f-4c59-b573-c2d9d91da58b" width="500" height="200">
200+
<img src="https://github.com/aDarkDev/SysSpecter/assets/121636230/106c939b-9e3c-4346-a430-40581123e485" width="500" height="200">
201+
</div>
202+
203+
204+
### Incoming Network Traffic
205+
206+
- **Bytes**: `curl http://localhost:port/network/incoming/bytes?interface=<interface>`
207+
- **Packets**: `curl http://localhost:port/network/incoming/packets?interface=<interface>`
208+
- **Errors**: `curl http://localhost:port/network/incoming/errors?interface=<interface>`
209+
- **Dropped**: `curl http://localhost:port/network/incoming/dropped?interface=<interface>`
210+
211+
### Outgoing Network Traffic
212+
213+
- **Bytes**: `curl http://localhost:port/network/outgoing/bytes?interface=<interface>`
214+
- **Packets**: `curl http://localhost:port/network/outgoing/packets?interface=<interface>`
215+
- **Errors**: `curl http://localhost:port/network/outgoing/errors?interface=<interface>`
216+
- **Dropped**: `curl http://localhost:port/network/outgoing/dropped?interface=<interface>`
217+
218+
## Contributing
219+
220+
Contributions are what make the open-source community such an amazing place to learn, inspire, and create. Any contributions you make are **greatly appreciated**.
221+
222+
1. Fork the Project
223+
2. Create your Feature Branch (`git checkout -b feature/AmazingFeature`)
224+
3. Commit your Changes (`git commit -m 'Add some AmazingFeature'`)
225+
4. Push to the Branch (`git push origin feature/AmazingFeature`)
226+
5. Open a Pull Request
227+
228+
## License
229+
230+
Distributed under the MIT License. See `LICENSE` for more information.
231+
232+
## Contact
233+
234+
Your aDarkDev – [email protected]
235+
236+
Project Link: [https://github.com/aDarkDev/SysSpecter](https://github.com/aDarkDev/SysSpecter)
237+

api.go

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"github.com/valyala/fasthttp"
6+
"net"
7+
"strconv"
8+
)
9+
10+
var DefaultHeaderPassword = ""
11+
var DefaultIpRestrict = ""
12+
13+
// Handlers part
14+
15+
func handle_limits(ctx *fasthttp.RequestCtx) {
16+
if DefaultHeaderPassword != "" {
17+
if string(ctx.Request.Header.Peek("X-Pass")) != DefaultHeaderPassword {
18+
ctx.SetStatusCode(fasthttp.StatusUnauthorized)
19+
ctx.SetBodyString("Unauthorized: Incorrect password")
20+
return
21+
}
22+
}
23+
24+
if DefaultIpRestrict != "" {
25+
if !ctx.RemoteIP().Equal(net.ParseIP(DefaultIpRestrict)) {
26+
ctx.SetStatusCode(fasthttp.StatusForbidden)
27+
ctx.SetBodyString("Forbidden: Access is restricted")
28+
return
29+
}
30+
}
31+
32+
// Continue with the rest of your handler if the checks pass.
33+
}
34+
35+
var request_handler = func(ctx *fasthttp.RequestCtx) {
36+
handle_limits(ctx)
37+
if ctx.Response.StatusCode() != fasthttp.StatusOK {
38+
// The handle_limits function has already set the response, so we just return.
39+
return
40+
}
41+
42+
ctx.SetContentType("application/json")
43+
switch string(ctx.Path()) {
44+
45+
case "/system/status":
46+
handel_get_system_status(ctx)
47+
case "/system/memory":
48+
handel_get_system_mem(ctx)
49+
case "/system/disks":
50+
handel_get_system_disk(ctx)
51+
52+
case "/network/traffic/per_second":
53+
handel_get_per_second(ctx)
54+
case "/network/traffic/graph":
55+
handel_get_graph(ctx)
56+
case "/network/traffic/live_graph":
57+
handel_live_graph(ctx)
58+
case "/network/interface_list":
59+
handel_get_interface_list(ctx)
60+
case "/network/connections":
61+
handel_get_connections(ctx)
62+
63+
case "/network/incoming/bytes":
64+
handel_get_income_bytes(ctx)
65+
case "/network/incoming/packets":
66+
handel_get_income_packets(ctx)
67+
case "/network/incoming/errors":
68+
handel_get_income_erros(ctx)
69+
case "/network/incoming/dropped":
70+
handel_get_income_dropped(ctx)
71+
72+
case "/network/outgoing/bytes":
73+
handel_get_outgo_bytes(ctx)
74+
case "/network/outgoing/packets":
75+
handel_get_outgo_packets(ctx)
76+
case "/network/outgoing/errors":
77+
handel_get_outgo_erros(ctx)
78+
case "/network/outgoing/dropped":
79+
handel_get_outgo_dropped(ctx)
80+
81+
default:
82+
ctx.Error("nothing here, *- check https://github.com/aDarkDev", fasthttp.StatusNotFound)
83+
}
84+
85+
statusCode := ctx.Response.StatusCode()
86+
status_res := ""
87+
if statusCode == 200{
88+
status_res = "\033[92m200\033[0m"
89+
}else{
90+
status_res = "\033[91m"+strconv.Itoa(statusCode)+"\033[0m"
91+
}
92+
93+
ctx.Response.Header.SetServer("SysSpecter/aDarkDev")
94+
fmt.Println("[+] " + ctx.RemoteIP().To4().String() + " \033[96m" + string(ctx.Method()) + "\033[0m " + string(ctx.URI().RequestURI()) + " - " + status_res)
95+
}
96+
97+
func Run(host string, port int) {
98+
fasthttp.ListenAndServe(host+":"+strconv.Itoa(port), request_handler)
99+
}

go.mod

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
module SysSpecter
2+
3+
go 1.18
4+
5+
require (
6+
github.com/andybalholm/brotli v1.1.0 // indirect
7+
github.com/go-ole/go-ole v1.2.6 // indirect
8+
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 // indirect
9+
github.com/klauspost/compress v1.17.6 // indirect
10+
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 // indirect
11+
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c // indirect
12+
github.com/shirou/gopsutil/v3 v3.24.1 // indirect
13+
github.com/shoenig/go-m1cpu v0.1.6 // indirect
14+
github.com/tklauser/go-sysconf v0.3.12 // indirect
15+
github.com/tklauser/numcpus v0.6.1 // indirect
16+
github.com/valyala/bytebufferpool v1.0.0 // indirect
17+
github.com/valyala/fasthttp v1.51.0 // indirect
18+
github.com/wcharczuk/go-chart/v2 v2.1.1 // indirect
19+
github.com/yusufpapurcu/wmi v1.2.3 // indirect
20+
golang.org/x/image v0.11.0 // indirect
21+
golang.org/x/sys v0.16.0 // indirect
22+
)

0 commit comments

Comments
 (0)