diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..6e7e833 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,10 @@ +FROM python:3.11-slim + +WORKDIR /app +COPY requirements.txt . +RUN pip install --no-cache-dir -r requirements.txt + +COPY node_info_daemon.py . + +EXPOSE 8080 +CMD ["python", "node_info_daemon.py"] \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..6e7e833 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,10 @@ +FROM python:3.11-slim + +WORKDIR /app +COPY requirements.txt . +RUN pip install --no-cache-dir -r requirements.txt + +COPY node_info_daemon.py . + +EXPOSE 8080 +CMD ["python", "node_info_daemon.py"] \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..a8336c2 --- /dev/null +++ b/README.md @@ -0,0 +1,13 @@ +# Node State + +This is a custom Docker container that uses a Python script to collect and expose basic system metrics. + +----- + +## How to Use + +To deploy this component to your server, simply run the following command: + +```bash +docker-compose up -d +``` diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..6e7e833 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,10 @@ +FROM python:3.11-slim + +WORKDIR /app +COPY requirements.txt . +RUN pip install --no-cache-dir -r requirements.txt + +COPY node_info_daemon.py . + +EXPOSE 8080 +CMD ["python", "node_info_daemon.py"] \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..a8336c2 --- /dev/null +++ b/README.md @@ -0,0 +1,13 @@ +# Node State + +This is a custom Docker container that uses a Python script to collect and expose basic system metrics. + +----- + +## How to Use + +To deploy this component to your server, simply run the following command: + +```bash +docker-compose up -d +``` diff --git a/docker-compose.yaml b/docker-compose.yaml new file mode 100644 index 0000000..6897bc3 --- /dev/null +++ b/docker-compose.yaml @@ -0,0 +1,9 @@ +version: '3.8' + +services: + node-info: + build: . + container_name: node_stats + ports: + - "8080:8080" + restart: unless-stopped \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..6e7e833 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,10 @@ +FROM python:3.11-slim + +WORKDIR /app +COPY requirements.txt . +RUN pip install --no-cache-dir -r requirements.txt + +COPY node_info_daemon.py . + +EXPOSE 8080 +CMD ["python", "node_info_daemon.py"] \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..a8336c2 --- /dev/null +++ b/README.md @@ -0,0 +1,13 @@ +# Node State + +This is a custom Docker container that uses a Python script to collect and expose basic system metrics. + +----- + +## How to Use + +To deploy this component to your server, simply run the following command: + +```bash +docker-compose up -d +``` diff --git a/docker-compose.yaml b/docker-compose.yaml new file mode 100644 index 0000000..6897bc3 --- /dev/null +++ b/docker-compose.yaml @@ -0,0 +1,9 @@ +version: '3.8' + +services: + node-info: + build: . + container_name: node_stats + ports: + - "8080:8080" + restart: unless-stopped \ No newline at end of file diff --git a/node_info_daemon.py b/node_info_daemon.py new file mode 100644 index 0000000..9aa8d95 --- /dev/null +++ b/node_info_daemon.py @@ -0,0 +1,50 @@ +from flask import Flask, jsonify +import psutil +import time + +app = Flask(__name__) + +# Store previous network I/O to calculate speeds +previous_io = psutil.net_io_counters() +previous_time = time.time() + +@app.route("/stats") +def stats(): + global previous_io, previous_time + + # Gather system info + cpu_usage = psutil.cpu_percent(interval=0.5) + virtual_mem = psutil.virtual_memory() + disk = psutil.disk_usage('/') + current_io = psutil.net_io_counters() + current_time = time.time() + + # Calculate network speeds + time_diff = current_time - previous_time + rx_speed = (current_io.bytes_recv - previous_io.bytes_recv) / time_diff + tx_speed = (current_io.bytes_sent - previous_io.bytes_sent) / time_diff + + # Update history + previous_io = current_io + previous_time = current_time + + return jsonify({ + "cpu_percent": cpu_usage, + "memory": { + "used_mb": virtual_mem.used // (1024 * 1024), + "total_mb": virtual_mem.total // (1024 * 1024), + "percent": virtual_mem.percent + }, + "disk": { + "used_gb": disk.used // (1024 ** 3), + "total_gb": disk.total // (1024 ** 3), + "percent": disk.percent + }, + "network": { + "rx_kbps": round(rx_speed / 1024, 2), + "tx_kbps": round(tx_speed / 1024, 2) + } + }) + +if __name__ == "__main__": + app.run(host="0.0.0.0", port=8080) \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..6e7e833 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,10 @@ +FROM python:3.11-slim + +WORKDIR /app +COPY requirements.txt . +RUN pip install --no-cache-dir -r requirements.txt + +COPY node_info_daemon.py . + +EXPOSE 8080 +CMD ["python", "node_info_daemon.py"] \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..a8336c2 --- /dev/null +++ b/README.md @@ -0,0 +1,13 @@ +# Node State + +This is a custom Docker container that uses a Python script to collect and expose basic system metrics. + +----- + +## How to Use + +To deploy this component to your server, simply run the following command: + +```bash +docker-compose up -d +``` diff --git a/docker-compose.yaml b/docker-compose.yaml new file mode 100644 index 0000000..6897bc3 --- /dev/null +++ b/docker-compose.yaml @@ -0,0 +1,9 @@ +version: '3.8' + +services: + node-info: + build: . + container_name: node_stats + ports: + - "8080:8080" + restart: unless-stopped \ No newline at end of file diff --git a/node_info_daemon.py b/node_info_daemon.py new file mode 100644 index 0000000..9aa8d95 --- /dev/null +++ b/node_info_daemon.py @@ -0,0 +1,50 @@ +from flask import Flask, jsonify +import psutil +import time + +app = Flask(__name__) + +# Store previous network I/O to calculate speeds +previous_io = psutil.net_io_counters() +previous_time = time.time() + +@app.route("/stats") +def stats(): + global previous_io, previous_time + + # Gather system info + cpu_usage = psutil.cpu_percent(interval=0.5) + virtual_mem = psutil.virtual_memory() + disk = psutil.disk_usage('/') + current_io = psutil.net_io_counters() + current_time = time.time() + + # Calculate network speeds + time_diff = current_time - previous_time + rx_speed = (current_io.bytes_recv - previous_io.bytes_recv) / time_diff + tx_speed = (current_io.bytes_sent - previous_io.bytes_sent) / time_diff + + # Update history + previous_io = current_io + previous_time = current_time + + return jsonify({ + "cpu_percent": cpu_usage, + "memory": { + "used_mb": virtual_mem.used // (1024 * 1024), + "total_mb": virtual_mem.total // (1024 * 1024), + "percent": virtual_mem.percent + }, + "disk": { + "used_gb": disk.used // (1024 ** 3), + "total_gb": disk.total // (1024 ** 3), + "percent": disk.percent + }, + "network": { + "rx_kbps": round(rx_speed / 1024, 2), + "tx_kbps": round(tx_speed / 1024, 2) + } + }) + +if __name__ == "__main__": + app.run(host="0.0.0.0", port=8080) \ No newline at end of file diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..6239842 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,2 @@ +flask +psutil \ No newline at end of file