Get_Stat is a monitoring system designed to track computer usage, application activity, and system metrics (e.g., CPU and RAM usage) across multiple machines. It features a Django-based backend server, a Python client-side agent for data collection, and a lightweight HTML dashboard for visualization for testing.
- Real-Time Monitoring: Captures and displays CPU, RAM, and application usage data with minimal latency.
- Multi-Computer Tracking: Supports monitoring multiple machines, each identified by a unique ID.
- Secure API: Provides authenticated endpoints for data ingestion and retrieval using API keys.
- Cross-Platform Agent: Written in Python, the agent runs on any platform with Python support (Windows executable also available).
- Extensible: Easily adaptable for additional metrics or integrations.
- Backend (Django): Manages data storage, processing, and API interactions.
- Models:
Computer
,AppUsage
,SystemMetrics
. - Endpoints:
/api/data
(data submission),/api/stats
(data retrieval).
- Models:
- Agent (Python): Collects system metrics and application data, sending it to the backend periodically.
- Frontend (HTML/JS): A simple dashboard (
data.html
) using Chart.js and Axios for visualization.
- Python 3.8+: Required for both server and agent.
- Django: Installed via
requirements.txt
. - Git: For cloning the repository.
-
Clone the Repository:
git clone https://github.com/BotirBakhtiyarov/Get_Stat.git cd Get_Stat
-
Set Up a Virtual Environment:
python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate
-
Install Dependencies:
pip install -r requirements.txt
-
Apply Database Migrations:
cd StatsProject python manage.py migrate
-
Generate an API Key:
python manage.py createapikey
- Save the generated API key; it’s required for authenticating requests to
/api/stats
.
- Save the generated API key; it’s required for authenticating requests to
-
Run the Server:
python manage.py runserver
- Access the server at
http://localhost:8000
.
- Access the server at
The agent collects and sends metrics to the server every 5 minutes.
-
Install Dependencies:
pip install psutil requests pywin32 # Omit pywin32 on non-Windows platforms
-
Configure the Server URL:
- In
agent.py
, setSERVER_URL
to your server’s/api/data
endpoint (e.g.,http://your-server-ip:8000/api/data
).
- In
-
Launch the Agent:
python agent.py
- Download
setup.exe
from the latest release. - Install and run
setup.exe
. - Note: The default
SERVER_URL
ishttp://192.168.1.6:8000
. Update the source and rebuild the executable if your server uses a different address.
- Open
data.html
in a browser. - Input the API key from the server setup.
- Select a time filter (e.g., "Last 5 Minutes", "Last 1 Hour").
- Click "Load Data" to view metrics.
- Displays CPU, RAM, and app usage per computer.
- Note: Update the URL in
data.html
’sloadData()
function if the server isn’t onlocalhost:8000
.
-
POST /api/data
- Purpose: Submits metrics from the agent.
- Payload: JSON with
computer_id
,username
,timestamp
,cpu
,ram
, andapps
. - Authentication: None (open for agents).
-
GET /api/stats
- Purpose: Retrieves aggregated stats.
- Query Params:
time_filter
(optional;latest
,1h
,1d
). - Authentication: Requires
Authorization: Api-Key YOUR_API_KEY
header.
curl -H "Authorization: Api-Key YOUR_API_KEY" "http://localhost:8000/api/stats?time_filter=1h"
- Agent: Edit
agent.py
to add metrics or adjust the polling interval. - Backend: Modify
models.py
to store additional data. - Frontend: Enhance
data.html
with new visualizations for testing API.
- API Key: Keep it confidential to secure
/api/stats
. - CORS: In production, disable
CORS_ALLOW_ALL_ORIGINS
insettings.py
and whitelist specific origins. - HTTPS: Use HTTPS in production to encrypt traffic.
- Agent Issues: Verify
SERVER_URL
and server accessibility. - API Key Problems: Ensure the key matches the one generated and is correctly entered in
data.html
. - Time Zones: Default is UTC+8 (Asia/Shanghai); adjust in
settings.py
andagent.py
if needed.
This project is licensed under the MIT License - see LICENSE for details.