93 Commits

Author SHA1 Message Date
f360e13ca3 feat(metrics): optimize stats collection and enhance error handling
- Refactored the GetStats method to improve memory management by utilizing an object pool for stats initialization.
- Enhanced error rate calculation and added average response time metrics for better performance insights.
- Streamlined path and referer statistics collection, ensuring only relevant data is processed and displayed.
- Improved sorting and selection logic for top paths and referers, enhancing the clarity of metrics reporting.
- Updated comments for better code readability and understanding of the metrics collection process.

These changes enhance the efficiency and accuracy of the metrics collector, providing more reliable performance data and insights.
2024-12-05 10:37:47 +08:00
14843301f7 feat(metrics): enhance initialization process in metrics collector
- Improved the initialization sequence by clearly defining steps for cache, monitoring, and object pool setup.
- Enabled Feishu webhook alerts for real-time notifications based on configuration.
- Ensured last save time is set during initialization to maintain accurate data persistence.
- Streamlined historical data loading process to enhance metrics accuracy.

These changes improve the organization and functionality of the metrics collector, ensuring better performance and alerting capabilities.
2024-12-05 10:33:55 +08:00
c71da4c1fe feat(metrics): initialize cache and object pool in metrics collector
- Added cache initialization to enhance performance and data retrieval efficiency.
- Introduced an object pool for managing statistics, optimizing memory usage during metrics processing.
- Improved code organization by clarifying initialization steps for cache and monitoring components.

These changes enhance the metrics collector's efficiency and resource management, ensuring better performance in data handling.
2024-12-05 10:30:10 +08:00
ef3bc0c5a6 feat(metrics): enhance metrics initialization and consistency checks
- Added initialization of last save time during collector setup to ensure timely data persistence.
- Implemented immediate saving of metrics after loading historical data to maintain accurate statistics.
- Improved error handling in SaveMetrics by validating input types before updating persistent stats.
- Modified CheckDataConsistency logic to allow for a tolerance of 5% in total request comparisons, enhancing reliability in metrics validation.

These changes improve the accuracy and reliability of the metrics collection process, ensuring better monitoring and data integrity.
2024-12-05 10:26:09 +08:00
1c22e4c020 栈溢出 2024-12-05 10:21:50 +08:00
e275326d91 feat(metrics): enhance configuration and metrics validation
- Added new configuration structures for loading, saving, and validation settings in MetricsConfig.
- Introduced constants for load retry counts, intervals, and validation parameters to improve configurability.
- Enhanced metrics collector with data validation and consistency checks during metrics loading.
- Implemented backup and restore functionality for metrics data, ensuring data integrity and recoverability.
- Improved logging for metrics operations, providing better insights into the metrics collection process.

These changes enhance the flexibility and reliability of the metrics system, ensuring accurate data handling and improved monitoring capabilities.
2024-12-05 10:15:20 +08:00
8c266a1ec2 feat(metrics): enhance metrics collection and monitoring capabilities
- Added new performance monitoring thresholds for maximum requests and data transfer rates.
- Introduced dynamic save interval adjustments based on data change rates to optimize database writes.
- Implemented a retry mechanism for loading recent statistics, improving reliability in data retrieval.
- Consolidated metrics saving into a single method, SaveAllMetrics, to streamline database transactions and improve performance.
- Enhanced error handling and logging throughout the metrics collection process for better monitoring.

These changes improve the efficiency and reliability of the metrics system, ensuring more accurate and timely data collection.
2024-12-05 09:51:43 +08:00
ad4211fd6f refactor(metrics): streamline recent stats loading and remove deprecated function
- Replaced the deprecated loadRecentStatusStats function with a new LoadRecentStats method in the MetricsDB, consolidating recent statistics loading for status codes, paths, and referers.
- Improved error handling and logging for loading recent stats, enhancing monitoring capabilities.
- This refactor simplifies the codebase and improves the efficiency of metrics collection, ensuring more accurate and timely data retrieval.
2024-12-05 09:35:11 +08:00
79abb4089f 历史数据问题 2024-12-05 09:29:55 +08:00
8df86387ac refactor(metrics): enhance dashboard styles and optimize SQL queries
- Updated CSS styles for the metrics dashboard, improving layout with flex properties and enhanced item presentation.
- Modified the status code display to use a more organized structure, allowing for better alignment and spacing.
- Changed the data type for avgLatency in SaveMetrics to int64 for consistency.
- Implemented a context with timeout for database queries in GetRecentMetrics, improving performance and reliability.
- Optimized SQL queries to limit result sets and enhance data retrieval efficiency.

These changes improve the user experience and data presentation in the metrics dashboard, providing clearer insights into performance metrics.
2024-12-05 09:22:33 +08:00
7cca4bab95 fix css bug 2024-12-05 08:58:42 +08:00
1140062afb 修改metrics状态码样式 2024-12-05 08:52:25 +08:00
d69d34bb5d fix(metrics): update metrics dashboard styles and improve status code display 2024-12-05 08:48:00 +08:00
3270bb5f36 fix(metrics): update metrics dashboard styles and optimize SQL queries
- Changed text color in the metrics dashboard from white to black for better visibility.
- Modified the layout of status codes to display in a row with improved alignment and spacing.
- Enhanced CSS styles for the metrics dashboard, including adjustments to flex properties and background settings.
- Updated SQL query in GetRecentMetrics to sort status codes, ensuring a more organized display of metrics.

These changes improve the user experience and data presentation in the metrics dashboard, providing clearer insights into performance metrics.
2024-12-05 08:37:51 +08:00
ba691431f4 状态码统计数组越界 2024-12-05 08:27:19 +08:00
864ebcc610 test 2024-12-05 08:23:38 +08:00
97a195c9dd feat(metrics): add recent status stats loading and optimize database transaction settings
- Implemented a new function to load recent status statistics from the database, enhancing the collector's ability to track real-time metrics.
- Added error logging for failed status stats loading to improve monitoring and debugging capabilities.
- Moved database transaction optimization settings outside of the transaction scope in SaveMetrics, improving performance during metric saving operations.
- Updated SQL queries in GetRecentMetrics to streamline time filtering logic, ensuring accurate retrieval of recent metrics.

These changes enhance the metrics collection process and improve the overall performance and reliability of the metrics dashboard.
2024-12-05 08:15:18 +08:00
96a792abf2 fix(metrics): update metrics dashboard styles and SQL query
- Enhanced CSS styles for the metrics dashboard, improving layout and visual presentation with new flex properties and background adjustments.
- Modified the SQL query in GetRecentMetrics to include an additional interval parameter, ensuring more accurate data retrieval for recent metrics.
- These changes improve the user experience and data accuracy in the metrics dashboard, providing a more robust framework for performance monitoring.
2024-12-05 08:03:03 +08:00
e286fa9eaf feat(metrics): enhance metrics retention and improve data handling
- Introduced new constants for data retention periods, specifying retention for metrics, status codes, paths, and referers to improve data management.
- Updated the MetricsHistoryHandler to accept floating-point hours for more precise time queries, enhancing the flexibility of historical data retrieval.
- Enhanced the metrics dashboard layout with additional CSS styles for better visual presentation and user experience.
- Improved error handling in the response writing process to ensure robust logging of connection issues.
- Implemented a new function to check for connection closure errors, improving the reliability of the proxy handler.

These changes significantly enhance the metrics collection, retention, and user interface, providing a more robust framework for performance monitoring and data analysis.
2024-12-05 07:57:02 +08:00
26c945a3f9 feat(metrics): enhance metrics dashboard and data handling
- Improved the metrics dashboard layout with new styles for better visual presentation, including enhanced chart and control elements.
- Added functionality for auto-refreshing metrics and exporting data to CSV, improving user interaction and data accessibility.
- Implemented persistent statistics tracking in the collector, allowing for historical data retrieval and better performance monitoring.
- Enhanced database operations with optimizations for saving metrics and cleaning up old data, ensuring efficient data management.
- Introduced performance metrics tracking, providing insights into average response times and throughput.

These changes significantly enhance the usability and functionality of the metrics dashboard, providing a more robust framework for performance monitoring and data analysis.
2024-12-05 07:08:08 +08:00
2d658c35e6 fix(metrics): refine SQL query for recent metrics retrieval
- Updated the SQL query in GetRecentMetrics to adjust the time filtering logic, ensuring that only metrics within the specified hours are retrieved.
- This change enhances the accuracy of the metrics data by correctly bounding the time range, improving the reliability of performance monitoring.
2024-12-05 06:51:16 +08:00
c416c76790 feat(metrics): implement full metrics saving and enhance database schema
- Added functionality to save full metrics periodically and on application shutdown, improving data persistence.
- Introduced new database tables for performance metrics, status code history, popular paths, and referer history, enhancing data tracking capabilities.
- Updated the GetRecentMetrics function to utilize window functions for more accurate metrics retrieval and ensure non-negative values.
- Improved data handling by ensuring empty records are returned instead of null when no metrics are available.

These changes significantly enhance the metrics collection and storage process, providing a more robust framework for performance monitoring.
2024-12-05 06:47:39 +08:00
c35d95f2cc fix(metrics): enhance metrics dashboard layout and optimize database queries
- Increased the bottom margin of charts in the metrics dashboard for improved visual spacing.
- Added titles to the charts for better context and understanding of displayed data.
- Introduced composite indexes in the database to optimize aggregation queries and improve performance.
- Modified the SQL query in GetRecentMetrics to calculate incremental changes in metrics, enhancing data accuracy and usability.

These changes improve the user experience by providing clearer visualizations and more efficient data retrieval in the metrics dashboard.
2024-12-05 01:46:25 +08:00
68a0ea234b fix(metrics): refine chart handling and data validation in metrics dashboard
- Updated chart management logic to ensure proper destruction of existing charts before creating new ones, preventing memory leaks.
- Enhanced data validation by adding a check for the data format returned from the API, ensuring it is an array before processing.
- Consolidated chart options into a common configuration for improved consistency across different charts.
- Improved the updateChart function to handle canvas element existence checks and streamline chart creation.

These changes enhance the performance and reliability of the metrics dashboard, providing clearer visualizations and better data handling.
2024-12-05 01:28:17 +08:00
b5a3cfeee4 fix(metrics): improve chart management in metrics dashboard
- Added logic to destroy existing charts before creating new ones, preventing memory leaks and ensuring proper chart updates.
- Updated the currentCharts object to maintain references to the newly created charts, enhancing the management of chart instances.
- These changes improve the performance and reliability of the metrics dashboard by ensuring that charts are correctly handled during updates.
2024-12-05 01:22:58 +08:00
660e60576d fix(metrics): enhance metrics chart rendering and data handling
- Updated the metrics chart rendering logic to reverse the data order for a more intuitive time progression from left to right.
- Introduced chart options to ensure the x-axis is not reversed, improving the clarity of time-based data visualization.
- Modified the updateChart function to accept additional options, allowing for more flexible chart configurations.
- Added a safeguard in GetRecentMetrics to return a default empty record instead of null when no metrics are available, enhancing data reliability.

These changes improve the user experience by providing clearer visualizations and ensuring consistent data handling in the metrics dashboard.
2024-12-05 01:13:11 +08:00
8858c41419 Merge branch 'main' of https://github.com/woodchen-ink/proxy-go 2024-12-05 01:06:57 +08:00
59358cbe8a fix(metrics): update SQL query to use localtime for accurate metrics retrieval
- Modified the SQL query in GetRecentMetrics to utilize the 'localtime' modifier for timestamp handling, ensuring that metrics are retrieved based on the local time zone.
- This change enhances the accuracy of the metrics data by aligning the time calculations with local time, improving the reliability of performance monitoring.
2024-12-05 01:06:55 +08:00
wood chen
12b85b24e7
Merge pull request #1 from woodchen-ink/dependabot/go_modules/modernc.org/sqlite-1.34.2
chore(deps): bump modernc.org/sqlite from 1.28.0 to 1.34.2
2024-12-04 12:10:49 +08:00
60b115438a fix(metrics): update AvgLatency type and improve SQL query for metrics retrieval
- Changed AvgLatency field type from int64 to float64 in HistoricalMetrics for better precision in latency measurements.
- Updated SQL query in GetRecentMetrics to ensure proper averaging of AvgLatency by casting to float, enhancing accuracy in metrics reporting.
- These changes improve the reliability of metrics data and ensure more accurate performance monitoring.
2024-12-04 11:57:08 +08:00
dependabot[bot]
adfacfdeeb
chore(deps): bump modernc.org/sqlite from 1.28.0 to 1.34.2
Bumps [modernc.org/sqlite](https://gitlab.com/cznic/sqlite) from 1.28.0 to 1.34.2.
- [Commits](https://gitlab.com/cznic/sqlite/compare/v1.28.0...v1.34.2)

---
updated-dependencies:
- dependency-name: modernc.org/sqlite
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-12-03 12:35:22 +00:00
a009dd04a8 refactor(metrics): remove historical data section from metrics dashboard template
- Eliminated the historical data section from the metrics dashboard, including time range buttons and associated chart containers.
- Streamlined the metrics template for improved clarity and focus on current metrics display.
- This change enhances the user experience by simplifying the dashboard layout.
2024-12-03 18:27:04 +08:00
837820639f feat(metrics): implement database initialization and cleanup for metrics tracking
- Added initTables function to create necessary tables for metrics history, status statistics, and path statistics in the database.
- Implemented indexing on timestamp columns to enhance query performance.
- Introduced a cleanupRoutine function to periodically delete old metrics data based on retention policies, improving database management.
- Integrated logging for cleanup operations to monitor success and errors during the cleanup process.
2024-12-03 18:25:23 +08:00
b69a78eae0 feat(metrics): enhance metrics dashboard with time range buttons and chart updates
- Replaced the time range dropdown with a set of buttons for selecting different time ranges (1 hour, 6 hours, 12 hours, 24 hours, 3 days, 5 days, 7 days, 15 days, 30 days).
- Improved the styling of the time range buttons for better user experience.
- Refactored chart loading logic to update existing charts instead of recreating them, enhancing performance and user experience.
- Added functionality to dynamically load historical data based on the selected time range, improving data visualization capabilities.
2024-12-03 18:23:37 +08:00
91d4686713 feat(metrics): add safe type conversion functions and enhance metrics data retrieval
- Introduced safe type conversion functions for memory usage, status code stats, top paths, and recent requests to prevent panics when accessing metrics data.
- Updated MetricsHandler to utilize these safe functions, improving the robustness of metrics handling.
- Refactored GetStats method in Collector to ensure all fields are initialized and to streamline the retrieval of metrics data.
- Enhanced the overall structure of metrics data for better clarity and reliability in reporting.
2024-12-03 18:17:25 +08:00
9602034f9d feat(metrics): improve metrics handling with safe type conversions and enhanced request statistics
- Introduced safe type conversion functions to prevent panics when accessing metrics data.
- Updated MetricsHandler to utilize these functions for retrieving active requests, total requests, total errors, and average response time.
- Enhanced error rate calculation to avoid division by zero.
- Refactored buffer pool management in ProxyHandler for better memory handling.
- Improved target URL determination logic based on file extensions for more flexible proxy behavior.
2024-12-03 18:11:29 +08:00
1db0e6ae98 fix(metrics): update SQLite driver usage in MetricsDB initialization
- Changed the SQLite driver from "sqlite3" to "sqlite" in the NewMetricsDB function for improved compatibility with the new driver.
- This change aligns with the recent dependency update to modernc.org/sqlite, enhancing performance and stability.
2024-12-03 17:59:20 +08:00
54053f3a92 chore(dependencies): update SQLite driver and add indirect dependencies
- Replaced `github.com/mattn/go-sqlite3` with `modernc.org/sqlite` for improved compatibility and performance.
- Updated `go.mod` and `go.sum` to include several indirect dependencies for enhanced functionality and stability.
- Refactored import statements in `metrics.go` and `db.go` to reflect the new SQLite driver.
2024-12-03 17:57:31 +08:00
3962799980 feat(config): update alert configurations and error rate thresholds
- Increased ErrorRate threshold from 0.5 to 0.8 for stricter alerting.
- Added AlertInterval setting to config for customizable notification intervals.
- Updated latency thresholds for small, medium, and large files to improve performance monitoring.
- Enhanced metrics handling to incorporate new alert configurations in the system.
2024-12-03 17:54:45 +08:00
68c27b544b feat(metrics): enhance metrics functionality and configuration
- Added new dependency on github.com/mattn/go-sqlite3 for improved metrics storage.
- Updated main.go to initialize metrics collector with a new database path and configuration settings.
- Enhanced config.json to include additional metrics settings such as alert configurations and latency thresholds.
- Refactored internal metrics handling to support new metrics structures and improve data retrieval.
- Introduced a new metrics history endpoint for retrieving historical data, enhancing monitoring capabilities.
- Improved UI for metrics dashboard to include historical data visualization options.
2024-12-03 17:48:11 +08:00
d4af4c4d31 feat(metrics): enhance metrics collection and UI with top referers tracking
- Added support for tracking top referers in the metrics collector, allowing for better insights into request sources.
- Updated MetricsHandler to include top referers in the metrics response.
- Enhanced the metrics UI to display a new section for the top 10 referers, improving visibility into traffic sources.
- Refactored request recording to capture referer information in the collector for comprehensive statistics.
2024-11-30 22:55:31 +08:00
9be13ce0ef feat(deployment): add SSH deployment commands to Docker build workflow
- Integrated SSH action to automate deployment commands for the proxy-go service.
- Added steps to pull the latest Docker image, stop and remove the existing container, and restart the service using Docker Compose.
- Enhanced the workflow for smoother deployment processes.
2024-11-30 22:27:57 +08:00
040b01f4a4 feat(metrics): integrate comprehensive metrics tracking across handlers
- Enhanced metrics collection in ProxyHandler, MirrorProxyHandler, and FixedPathProxyMiddleware.
- Introduced a centralized metrics collector to streamline request tracking and statistics reporting.
- Updated MetricsHandler to utilize new metrics structure, including total bytes, requests per second, and error rates.
- Improved documentation in readme.md to reflect new features and usage instructions.
- Added support for metrics monitoring at `/metrics/ui` for better visibility into proxy performance.
2024-11-30 22:26:11 +08:00
b8d7659aa9 feat(metrics): enhance metrics reporting with uptime, error rate calculation, and recent requests retrieval
- Added uptime and error rate metrics to the MetricsHandler.
- Introduced helper functions for calculating error rates and retrieving recent requests.
- Improved latency formatting in the metrics template for better readability.
- Streamlined the metrics data structure to include requests per second and recent request logs.
2024-11-30 21:50:32 +08:00
7b6a193434 feat(metrics): enhance metrics UI with detailed traffic statistics, status code breakdown, and recent requests overview 2024-11-30 21:42:30 +08:00
bb830658e0 feat(metrics): add comprehensive metrics display for uptime, request counts, and performance indicators 2024-11-30 21:23:17 +08:00
ef97e833e6 refactor(main): streamline metrics route handling in main function 2024-11-30 21:19:05 +08:00
e9e932b0b7 feat(main): add metrics routes for enhanced monitoring and remove duplicate route definitions 2024-11-30 21:14:16 +08:00
8770d79bb8 feat(docker-compose, config, handler): enhance deployment configuration, add metrics support, and improve proxy handling
- Updated docker-compose.yml to include resource limits and health checks for the service.
- Modified go.mod and go.sum to include the new dependency on golang.org/x/time.
- Enhanced main.go to add new metrics routes for monitoring.
- Updated config.json to include metrics configuration with password and token expiry.
- Refactored internal/config to implement a ConfigManager for dynamic configuration loading.
- Improved internal/handler to utilize a shared HTTP client and added metrics tracking for requests.
2024-11-30 21:11:05 +08:00
7ee1b0efb5 refactor(internal/handler): optimize image request handling and cloudflare headers 2024-11-17 10:47:41 +08:00