A modular, extensible, and production-ready Streamlit application for real-time monitoring of SQL Server instances. This dashboard fetches and displays key performance metrics (CPU, Memory, TempDB, Disk, Backup, and Activity) from multiple SQL Server instances, leveraging stored procedures for data retrieval.
- Multi-Instance Support: Monitor multiple SQL Server instances configured via
config.ini. - Real-Time Updates: Auto-refresh every
60seconds with a manual refresh option. - Tabular UI: Organized metrics in tabs (CPU, Memory, TempDB, Disk, Backup, Activity) with timestamped entries.
- Data Limiting: Retains up to 10 recent records per metric, preventing overload.
- Duplicate Prevention: Ensures no duplicate records during rapid updates.
- Modular Design: Separates configuration, database logic, UI, and app orchestration for maintainability and scalability.
- Error Handling: Graceful handling of connection and query failures with user feedback.
sqlmonlit/
├── app.py # Main application logic and orchestration
├── config.py # Configuration loading and management
├── database.py # Database connection and data fetching logic
├── ui.py # Streamlit UI components and rendering
├── config.ini # Sample configuration file (edit with your DB details)
├── requirements.txt # Python dependencies
└── README.md # This file
- Python: 3.8 or higher
- SQL Server: Accessible instances with the following stored procedures:
usp_SQLMonLit_CPUusp_SQLMonLit_Memoryusp_SQLMonLit_Tempdbusp_SQLMonLit_Batchusp_SQLMonLit_Activity
- Dependencies: Listed in
requirements.txt
- Clone the Repository:
git clone https://github.com/peandaddy/sqlmonlit.git cd sqlmonlit - Set Up a Virtual Environment (recommended):
python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate
- Install Dependencies:
pip install -r requirements.txt
- Configure config.ini:
- Copy the sample
config.iniand edit it with your SQL Server credentials:[database1] host=your_sql_server_host user=your_username password=your_password database=your_database_name [database2] host=another_sql_server_host user=another_username password=another_password database=another_database_name
- Add as many
[databaseX]sections as needed.
- Run the Application:
streamlit run app.py
- Interact with the Dashboard:
- Select an instance from the sidebar.
- View metrics in the tabs (
auto-refreshes every 60 seconds). - Use buttons: "
Refresh Now" (manual update), "Stop" (pause monitoring), "Clear" (reset data).
- Edit
config.ini: Modify instance details (host, user, password, database). - Customize Metrics: Update
SQLMonitorDB.METRICSindatabase.pyto add or change stored procedures. - Refresh Interval: Adjust the
60inapp.pycurrent_time - st.session_state["last_update"] >= 60to change the auto-refresh timing.
- Add the metric key and stored procedure to
SQLMonitorDB.METRICSindatabase.py. - Update
render_dashboardinui.pyto display the new metric in a tab.
- Install
pytest:pip install pytest
- Write tests in a
tests/directory (not included) to validateconfig.py,database.py, etc.
Contributions are welcome!
These samples and templates are all licensed under the MIT license. See the LICENSE file in the root.
- Ji Wang - https://github.com/peandaddy
Created to demonstrate advanced Python, Streamlit, and SQL Server monitoring skills. Contact me for collaboration or inquiries!
- Built with
Streamlitandpymssql. - Inspired by the need for robust SQL Server monitoring tools.
