diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..e69de29 diff --git a/.gitignore b/.gitignore index 64d49ae..70a2d38 100644 --- a/.gitignore +++ b/.gitignore @@ -1,216 +1,23 @@ -# Byte-compiled / optimized / DLL files +# Python +*.pyc __pycache__/ -*.py[codz] -*$py.class - -# C extensions -*.so - -# Distribution / packaging -.Python -build/ -develop-eggs/ -dist/ -downloads/ -eggs/ -.eggs/ -lib/ -lib64/ -parts/ -sdist/ -var/ -wheels/ -share/python-wheels/ -*.egg-info/ -.installed.cfg -*.egg -MANIFEST - -# PyInstaller -# Usually these files are written by a python script from a template -# before PyInstaller builds the exe, so as to inject date/other infos into it. -*.manifest -*.spec - -# Installer logs -pip-log.txt -pip-delete-this-directory.txt - -# Unit test / coverage reports -htmlcov/ -.tox/ -.nox/ -.coverage -.coverage.* -.cache -nosetests.xml -coverage.xml -*.cover -*.py.cover -.hypothesis/ -.pytest_cache/ -cover/ - -# Translations -*.mo -*.pot - -# Django stuff: -*.log -local_settings.py -db.sqlite3 -db.sqlite3-journal - -# Flask stuff: -instance/ -.webassets-cache - -# Scrapy stuff: -.scrapy - -# Sphinx documentation -docs/_build/ - -# PyBuilder -.pybuilder/ -target/ - -# Jupyter Notebook -.ipynb_checkpoints - -# IPython -profile_default/ -ipython_config.py - -# pyenv -# For a library or package, you might want to ignore these files since the code is -# intended to run in multiple environments; otherwise, check them in: -# .python-version - -# pipenv -# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. -# However, in case of collaboration, if having platform-specific dependencies or dependencies -# having no cross-platform support, pipenv may install dependencies that don't work, or not -# install all needed dependencies. -# Pipfile.lock - -# UV -# Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control. -# This is especially recommended for binary packages to ensure reproducibility, and is more -# commonly ignored for libraries. -# uv.lock - -# poetry -# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control. -# This is especially recommended for binary packages to ensure reproducibility, and is more -# commonly ignored for libraries. -# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control -# poetry.lock -# poetry.toml - -# pdm -# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control. -# pdm recommends including project-wide configuration in pdm.toml, but excluding .pdm-python. -# https://pdm-project.org/en/latest/usage/project/#working-with-version-control -# pdm.lock -# pdm.toml -.pdm-python -.pdm-build/ - -# pixi -# Similar to Pipfile.lock, it is generally recommended to include pixi.lock in version control. -# pixi.lock -# Pixi creates a virtual environment in the .pixi directory, just like venv module creates one -# in the .venv directory. It is recommended not to include this directory in version control. -.pixi - -# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm -__pypackages__/ - -# Celery stuff -celerybeat-schedule -celerybeat.pid - -# Redis -*.rdb -*.aof -*.pid - -# RabbitMQ -mnesia/ -rabbitmq/ -rabbitmq-data/ - -# ActiveMQ -activemq-data/ - -# SageMath parsed files -*.sage.py - -# Environments -.env -.envrc -.venv -env/ venv/ -ENV/ -env.bak/ -venv.bak/ +.env +db.sqlite3 -# Spyder project settings -.spyderproject -.spyproject +# Django +media/ +staticfiles/ -# Rope project settings -.ropeproject +# Compiled CSS +watcher_visio/static/css/output.css +watcher_visio/static/css/tailwindcss +watcher_visio/static/css/tailwindcss.exe -# mkdocs documentation -/site +# IDE +.vscode/ +.idea/ -# mypy -.mypy_cache/ -.dmypy.json -dmypy.json - -# Pyre type checker -.pyre/ - -# pytype static type analyzer -.pytype/ - -# Cython debug symbols -cython_debug/ - -# PyCharm -# JetBrains specific template is maintained in a separate JetBrains.gitignore that can -# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore -# and can be added to the global gitignore or merged into this file. For a more nuclear -# option (not recommended) you can uncomment the following to ignore the entire idea folder. -# .idea/ - -# Abstra -# Abstra is an AI-powered process automation framework. -# Ignore directories containing user credentials, local state, and settings. -# Learn more at https://abstra.io/docs -.abstra/ - -# Visual Studio Code -# Visual Studio Code specific template is maintained in a separate VisualStudioCode.gitignore -# that can be found at https://github.com/github/gitignore/blob/main/Global/VisualStudioCode.gitignore -# and can be added to the global gitignore or merged into this file. However, if you prefer, -# you could uncomment the following to ignore the entire vscode folder -# .vscode/ - -# Ruff stuff: -.ruff_cache/ - -# PyPI configuration file -.pypirc - -# Marimo -marimo/_static/ -marimo/_lsp/ -__marimo__/ - -# Streamlit -.streamlit/secrets.toml \ No newline at end of file +# DaisyUI +static/css/output.css +static/css/tailwindcss \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 1f17f74..ace7053 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,12 @@ -FROM alpine:3 AS build +FROM node:25-alpine AS node-build-stage + +COPY ./watcher_visio/static ./ +RUN npx tailwindcss \ + -i input.css \ + -o ./tailwind.css --minify + + +FROM alpine:3 AS venv-build-stage RUN apk update && \ apk add --no-cache --virtual .build-deps \ @@ -25,7 +33,7 @@ RUN apk add --no-cache --update python3 COPY --from=build /venv /venv RUN mkdir /app -COPY ./watcher_visio/ /app +COPY --from=build /app /app WORKDIR /app -CMD [ "python", "manage.py", "runserver", "0.0.0.0:5000" ] \ No newline at end of file +CMD [ "python", "manage.py", "runserver", "0.0.0.0:8000" ] \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..e69de29 diff --git a/docker-compose.yml b/docker-compose.yml index 7670ec8..de10ab0 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -2,6 +2,6 @@ services: watcher-visio: build: . ports: - - "5000:5000" + - "8000:8000" volumes: - ./watcher_visio:/app \ No newline at end of file diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh new file mode 100644 index 0000000..de27d23 --- /dev/null +++ b/docker-entrypoint.sh @@ -0,0 +1,12 @@ +#!/bin/sh + +set -e + +echo "Applying database migrations..." +python manage.py migrate --noinput + +echo "Collecting static files..." +python manage.py collectstatic --noinput + +echo "Starting Django application..." +exec "$@" \ No newline at end of file diff --git a/watcher_visio/dashboard/templatetags/__init__.py b/watcher_visio/dashboard/templatetags/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/watcher_visio/dashboard/templatetags/mathfilters.py b/watcher_visio/dashboard/templatetags/mathfilters.py new file mode 100644 index 0000000..4037010 --- /dev/null +++ b/watcher_visio/dashboard/templatetags/mathfilters.py @@ -0,0 +1,17 @@ +from django import template + +register = template.Library() + +@register.filter +def div(a, b): + try: + return float(a) / float(b) + except: + return 0 + +@register.filter +def mul(a, b): + try: + return float(a) * float(b) + except: + return 0 diff --git a/watcher_visio/dashboard/urls.py b/watcher_visio/dashboard/urls.py new file mode 100644 index 0000000..c486297 --- /dev/null +++ b/watcher_visio/dashboard/urls.py @@ -0,0 +1,6 @@ +from django.urls import path +from . import views + +urlpatterns = [ + path('', views.index, name='index'), +] \ No newline at end of file diff --git a/watcher_visio/dashboard/views.py b/watcher_visio/dashboard/views.py new file mode 100644 index 0000000..e5cac5a --- /dev/null +++ b/watcher_visio/dashboard/views.py @@ -0,0 +1,174 @@ +import json +from django.shortcuts import render + +_BASE = { + "region_name": "ct3k1ldt" +} + +def index(request): + context = {**_BASE, + # CPU and RAM utilization data + 'cpu_used': 42, + 'cpu_free': 58, + 'cpu_used_percentage': 42.0, + 'ram_used': 128, + 'ram_free': 256, + 'ram_used_percentage': 33.3, + + # Instance summary data + 'vm_count': 47, + 'vm_active': 42, + 'vm_stopped': 5, + 'vm_error': 0, + 'common_flavor': 'm1.medium', + 'common_flavor_count': 18, + 'second_common_flavor': { + 'name': 'm1.small', + 'count': 12 + }, + 'third_common_flavor': { + 'name': 'm1.large', + 'count': 8 + }, + + # Resource allocation data + 'cpu_allocated': 94, + 'cpu_total': 160, + 'cpu_overcommit_ratio': 1.5, + 'ram_allocated': 384, + 'ram_total': 512, + 'ram_overcommit_ratio': 1.2, + + # Quick stats + 'avg_cpu_per_vm': 2.0, + 'avg_ram_per_vm': 8.2, + 'vm_density': 9.4, + + # Audit data + 'audits': [ + { + 'id': 'audit_001', + 'name': 'Weekly Optimization', + 'created_at': '2024-01-15', + 'cpu_weight': 1.2, + 'ram_weight': 0.8, + 'scope': 'Full Cluster', + 'strategy': 'Load Balancing', + 'goal': 'Optimize CPU distribution across all hosts', + 'migrations': [ + { + 'instanceName': 'web-server-01', + 'source': 'compute-02', + 'destination': 'compute-05', + 'flavor': 'm1.medium', + 'impact': 'Low' + }, + { + 'instanceName': 'db-replica-03', + 'source': 'compute-01', + 'destination': 'compute-04', + 'flavor': 'm1.large', + 'impact': 'Medium' + }, + { + 'instanceName': 'api-gateway', + 'source': 'compute-03', + 'destination': 'compute-06', + 'flavor': 'm1.small', + 'impact': 'Low' + }, + { + 'instanceName': 'cache-node-02', + 'source': 'compute-01', + 'destination': 'compute-07', + 'flavor': 'm1.small', + 'impact': 'Low' + }, + { + 'instanceName': 'monitoring-server', + 'source': 'compute-04', + 'destination': 'compute-02', + 'flavor': 'm1.medium', + 'impact': 'Low' + } + ], + 'host_labels': ['compute-01', 'compute-02', 'compute-03', 'compute-04', 'compute-05', 'compute-06', 'compute-07'], + 'cpu_current': [78, 65, 42, 89, 34, 56, 71], + 'cpu_projected': [65, 58, 45, 72, 48, 61, 68] + }, + { + 'id': 'audit_002', + 'name': 'Emergency Rebalance', + 'created_at': '2024-01-14', + 'cpu_weight': 1.0, + 'ram_weight': 1.0, + 'scope': 'Overloaded Hosts', + 'strategy': 'Hotspot Reduction', + 'goal': 'Reduce load on compute-01 and compute-04', + 'migrations': [ + { + 'instanceName': 'app-server-02', + 'source': 'compute-01', + 'destination': 'compute-06', + 'flavor': 'm1.medium', + 'impact': 'Medium' + }, + { + 'instanceName': 'file-server-01', + 'source': 'compute-04', + 'destination': 'compute-07', + 'flavor': 'm1.large', + 'impact': 'High' + } + ], + 'host_labels': ['compute-01', 'compute-02', 'compute-03', 'compute-04', 'compute-05', 'compute-06', 'compute-07'], + 'cpu_current': [92, 65, 42, 85, 34, 56, 71], + 'cpu_projected': [72, 65, 42, 65, 34, 66, 81] + }, + { + 'id': 'audit_003', + 'name': 'Pre-Maintenance Planning', + 'created_at': '2024-01-10', + 'cpu_weight': 0.8, + 'ram_weight': 1.5, + 'scope': 'Maintenance Zone', + 'strategy': 'Evacuation', + 'goal': 'Empty compute-03 for maintenance', + 'migrations': [ + { + 'instanceName': 'test-vm-01', + 'source': 'compute-03', + 'destination': 'compute-02', + 'flavor': 'm1.small', + 'impact': 'Low' + }, + { + 'instanceName': 'dev-server', + 'source': 'compute-03', + 'destination': 'compute-05', + 'flavor': 'm1.medium', + 'impact': 'Low' + }, + { + 'instanceName': 'staging-db', + 'source': 'compute-03', + 'destination': 'compute-07', + 'flavor': 'm1.large', + 'impact': 'High' + } + ], + 'host_labels': ['compute-01', 'compute-02', 'compute-03', 'compute-04', 'compute-05', 'compute-06', 'compute-07'], + 'cpu_current': [78, 65, 56, 89, 34, 56, 71], + 'cpu_projected': [78, 75, 0, 89, 54, 56, 81] + } + ] + } + + # Serialize lists for JavaScript + for audit in context['audits']: + audit['migrations'] = json.dumps(audit['migrations']) + audit['host_labels'] = json.dumps(audit['host_labels']) + audit['cpu_current'] = json.dumps(audit['cpu_current']) + audit['cpu_projected'] = json.dumps(audit['cpu_projected']) + + return render(request, 'index.html', context) \ No newline at end of file diff --git a/watcher_visio/metrics/templates/dashboard.html b/watcher_visio/metrics/templates/dashboard.html deleted file mode 100644 index 3d223e0..0000000 --- a/watcher_visio/metrics/templates/dashboard.html +++ /dev/null @@ -1,52 +0,0 @@ - - -
- -| Instance | +Source Host | +Destination Host | +Flavor | +Impact | +
|---|---|---|---|---|
| + Select an audit to view migration actions + | +||||