diff --git a/CHANGELOG.md b/CHANGELOG.md index 419cea5..5f46832 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,33 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [0.3.0] - 2026-02-02 + +### Added + +- Custom Metrics Builder: + - Admin UI to define custom gauge metrics + - Support for static values and WordPress option-based values + - Label support with up to 5 labels and 50 value combinations + - Metric validation following Prometheus naming conventions +- Metric Export/Import: + - JSON-based configuration export for backup + - Import with three modes: skip existing, overwrite, or rename duplicates + - Version tracking in export format +- Grafana Dashboard Templates: + - WordPress Overview dashboard (users, posts, comments, cron, transients) + - WordPress Runtime dashboard (HTTP requests, database queries) + - WordPress WooCommerce dashboard (orders, revenue, products, customers) + - Easy download and import instructions +- New "Custom Metrics" tab in admin settings +- New "Dashboards" tab in admin settings +- Reset runtime metrics button to clear accumulated data + +### Changed + +- Settings page now has 5 tabs: License, Metrics, Custom Metrics, Dashboards, Help +- Updated translations with all new strings + ## [0.2.2] - 2026-02-02 ### Fixed diff --git a/CLAUDE.md b/CLAUDE.md index cf35e28..9fd0ae8 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -18,6 +18,9 @@ This plugin provides a Prometheus `/metrics` endpoint and an extensible way to a - Cron job metrics (scheduled events, overdue, next run) - Transient cache metrics (total, expiring, expired) - WooCommerce integration (products, orders, revenue, customers) +- Custom metric builder with admin UI (gauges with static or option-based values) +- Metric export/import for backup and site migration +- Grafana dashboard templates for easy visualization - Dedicated plugin settings under 'Settings/Metrics' menu - Extensible by other plugins using `wp_prometheus_collect_metrics` action hook - License management integration @@ -30,11 +33,7 @@ This project is proudly **"vibe-coded"** using Claude.AI - the entire codebase w **Note for AI Assistants:** Clean this section after the specific features are done or new releases are made. Effective changes are tracked in `CHANGELOG.md`. Do not add completed versions here - document them in the Session History section at the end of this file. -### Version 0.3.0 (Planned) - -- Custom metric builder in admin -- Metric export/import -- Grafana dashboard templates +*No planned features at this time.* ## Technical Stack @@ -214,6 +213,10 @@ wp-prometheus/ │ └── release.yml # CI/CD pipeline ├── assets/ │ ├── css/ # Admin/Frontend styles +│ ├── dashboards/ # Grafana dashboard templates +│ │ ├── wordpress-overview.json +│ │ ├── wordpress-runtime.json +│ │ └── wordpress-woocommerce.json │ └── js/ │ └── admin.js # Admin JavaScript ├── languages/ # Translation files @@ -222,6 +225,7 @@ wp-prometheus/ ├── releases/ # Release packages ├── src/ │ ├── Admin/ +│ │ ├── DashboardProvider.php # Grafana dashboard provider │ │ └── Settings.php # Settings page │ ├── Endpoint/ │ │ └── MetricsEndpoint.php # /metrics endpoint @@ -229,6 +233,7 @@ wp-prometheus/ │ │ └── Manager.php # License management │ ├── Metrics/ │ │ ├── Collector.php # Prometheus metrics collector +│ │ ├── CustomMetricBuilder.php # Custom metric CRUD │ │ └── RuntimeCollector.php # Runtime metrics collector │ ├── Installer.php # Activation/Deactivation │ ├── Plugin.php # Main plugin class @@ -285,6 +290,37 @@ add_action( 'wp_prometheus_collect_metrics', function( $collector ) { ## Session History +### 2026-02-02 - Custom Metrics & Dashboards (v0.3.0) + +- Added Custom Metric Builder with full admin UI: + - `CustomMetricBuilder.php` - CRUD operations, validation, export/import + - Support for static values and WordPress option-based values + - Label support (max 5 labels, 50 value combinations) + - Prometheus naming convention validation (`[a-zA-Z_:][a-zA-Z0-9_:]*`) +- Added Grafana Dashboard Templates: + - `DashboardProvider.php` - Dashboard file provider with path traversal protection + - `wordpress-overview.json` - General WordPress metrics + - `wordpress-runtime.json` - HTTP/DB performance metrics + - `wordpress-woocommerce.json` - WooCommerce store metrics +- Added export/import functionality: + - JSON-based configuration export + - Three import modes: skip, overwrite, rename duplicates + - Version tracking in export format +- Updated Settings page with new tabs: + - "Custom Metrics" tab with metric form and table + - "Dashboards" tab with download buttons + - "Reset Runtime Metrics" button in Metrics tab +- Updated `Collector.php` to integrate custom metrics +- Updated translation files with all new strings +- **Key Learning**: Dynamic form handling in WordPress admin + - Use `wp_create_nonce()` with unique nonce names per AJAX action + - Localize script with `wp_localize_script()` for nonces and AJAX URL + - Always verify `current_user_can('manage_options')` in AJAX handlers +- **Key Learning**: Grafana dashboard JSON format + - Use `${DS_PROMETHEUS}` for data source variable + - Schema version 39 for current Grafana compatibility + - Panels use `gridPos` for layout positioning + ### 2026-02-02 - Extended Metrics (v0.2.0) - Added WooCommerce integration metrics (only when WooCommerce is active): diff --git a/assets/css/admin.css b/assets/css/admin.css index 6f56f3d..785bc62 100644 --- a/assets/css/admin.css +++ b/assets/css/admin.css @@ -45,3 +45,163 @@ .wp-prometheus-tab-content .form-table { margin-top: 10px; } + +/* Custom metrics form */ +.wp-prometheus-metric-form { + background: #fff; + border: 1px solid #ccd0d4; + border-radius: 4px; + padding: 20px; + margin: 20px 0; +} + +.wp-prometheus-metric-form h3 { + margin-top: 0; + padding-bottom: 10px; + border-bottom: 1px solid #eee; +} + +.wp-prometheus-metric-form .required { + color: #d63638; +} + +/* Label rows */ +.metric-label-row { + display: flex; + align-items: center; + gap: 10px; + margin-bottom: 8px; +} + +.metric-label-row input { + flex: 1; + max-width: 300px; +} + +.metric-label-row .remove-label { + padding: 0 8px; + min-width: auto; +} + +/* Value rows */ +.metric-value-row { + display: flex; + align-items: center; + gap: 8px; + margin-bottom: 8px; + flex-wrap: wrap; +} + +.metric-value-row input { + width: 120px; +} + +.metric-value-row .remove-value-row { + padding: 0 8px; + min-width: auto; +} + +/* Custom metrics table */ +.wp-prometheus-custom-metrics .wp-list-table code { + background: #f0f0f1; + padding: 2px 6px; + border-radius: 3px; +} + +.wp-prometheus-custom-metrics .wp-list-table td { + vertical-align: middle; +} + +.wp-prometheus-custom-metrics .wp-list-table .dashicons { + font-size: 18px; + width: 18px; + height: 18px; +} + +/* Dashboard grid */ +.wp-prometheus-dashboard-grid { + display: grid; + grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); + gap: 20px; + margin: 20px 0; +} + +.wp-prometheus-dashboard-card { + background: #fff; + border: 1px solid #ccd0d4; + border-radius: 4px; + padding: 20px; + text-align: center; + transition: box-shadow 0.2s ease; +} + +.wp-prometheus-dashboard-card:hover { + box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1); +} + +.wp-prometheus-dashboard-card .dashboard-icon { + margin-bottom: 15px; +} + +.wp-prometheus-dashboard-card .dashboard-icon .dashicons { + font-size: 48px; + width: 48px; + height: 48px; + color: #2271b1; +} + +.wp-prometheus-dashboard-card h3 { + margin: 0 0 10px 0; + font-size: 16px; +} + +.wp-prometheus-dashboard-card p { + color: #646970; + margin: 0 0 15px 0; + font-size: 13px; +} + +/* Import options panel */ +#import-options { + border-radius: 4px; +} + +#import-options label { + display: block; + margin-bottom: 8px; +} + +/* Spinner alignment */ +.spinner { + float: none; + vertical-align: middle; +} + +/* Button groups */ +.wp-prometheus-tab-content .button + .button { + margin-left: 5px; +} + +/* Notice messages in forms */ +.wp-prometheus-metric-form .notice, +.wp-prometheus-custom-metrics .notice { + margin: 10px 0; + padding: 10px 15px; +} + +/* Responsive adjustments */ +@media screen and (max-width: 782px) { + .wp-prometheus-dashboard-grid { + grid-template-columns: 1fr; + } + + .metric-value-row { + flex-direction: column; + align-items: flex-start; + } + + .metric-value-row input { + width: 100%; + max-width: none; + } +} diff --git a/assets/dashboards/wordpress-overview.json b/assets/dashboards/wordpress-overview.json new file mode 100644 index 0000000..c8f896c --- /dev/null +++ b/assets/dashboards/wordpress-overview.json @@ -0,0 +1,851 @@ +{ + "annotations": { + "list": [] + }, + "editable": true, + "fiscalYearStartMonth": 0, + "graphTooltip": 0, + "id": null, + "links": [], + "panels": [ + { + "collapsed": false, + "gridPos": { + "h": 1, + "w": 24, + "x": 0, + "y": 0 + }, + "id": 1, + "panels": [], + "title": "System Info", + "type": "row" + }, + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "thresholds" + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + } + ] + } + }, + "overrides": [] + }, + "gridPos": { + "h": 4, + "w": 6, + "x": 0, + "y": 1 + }, + "id": 2, + "options": { + "colorMode": "value", + "graphMode": "none", + "justifyMode": "auto", + "orientation": "auto", + "reduceOptions": { + "calcs": ["lastNotNull"], + "fields": "/^version$/", + "values": false + }, + "textMode": "value" + }, + "pluginVersion": "10.0.0", + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "editorMode": "code", + "expr": "wordpress_info", + "format": "table", + "instant": true, + "legendFormat": "__auto", + "refId": "A" + } + ], + "title": "WordPress Version", + "type": "stat" + }, + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "thresholds" + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + } + ] + } + }, + "overrides": [] + }, + "gridPos": { + "h": 4, + "w": 6, + "x": 6, + "y": 1 + }, + "id": 3, + "options": { + "colorMode": "value", + "graphMode": "none", + "justifyMode": "auto", + "orientation": "auto", + "reduceOptions": { + "calcs": ["lastNotNull"], + "fields": "/^php_version$/", + "values": false + }, + "textMode": "value" + }, + "pluginVersion": "10.0.0", + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "editorMode": "code", + "expr": "wordpress_info", + "format": "table", + "instant": true, + "legendFormat": "__auto", + "refId": "A" + } + ], + "title": "PHP Version", + "type": "stat" + }, + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "thresholds" + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "blue", + "value": null + } + ] + } + }, + "overrides": [] + }, + "gridPos": { + "h": 4, + "w": 6, + "x": 12, + "y": 1 + }, + "id": 4, + "options": { + "colorMode": "value", + "graphMode": "none", + "justifyMode": "auto", + "orientation": "auto", + "reduceOptions": { + "calcs": ["lastNotNull"], + "fields": "", + "values": false + }, + "textMode": "auto" + }, + "pluginVersion": "10.0.0", + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "editorMode": "code", + "expr": "sum(wordpress_users_total)", + "instant": true, + "legendFormat": "__auto", + "refId": "A" + } + ], + "title": "Total Users", + "type": "stat" + }, + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "thresholds" + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "blue", + "value": null + } + ] + } + }, + "overrides": [] + }, + "gridPos": { + "h": 4, + "w": 6, + "x": 18, + "y": 1 + }, + "id": 5, + "options": { + "colorMode": "value", + "graphMode": "none", + "justifyMode": "auto", + "orientation": "auto", + "reduceOptions": { + "calcs": ["lastNotNull"], + "fields": "", + "values": false + }, + "textMode": "auto" + }, + "pluginVersion": "10.0.0", + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "editorMode": "code", + "expr": "wordpress_plugins_total{status=\"active\"}", + "instant": true, + "legendFormat": "__auto", + "refId": "A" + } + ], + "title": "Active Plugins", + "type": "stat" + }, + { + "collapsed": false, + "gridPos": { + "h": 1, + "w": 24, + "x": 0, + "y": 5 + }, + "id": 6, + "panels": [], + "title": "Content", + "type": "row" + }, + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "palette-classic" + }, + "custom": { + "hideFrom": { + "legend": false, + "tooltip": false, + "viz": false + } + }, + "mappings": [] + }, + "overrides": [] + }, + "gridPos": { + "h": 8, + "w": 8, + "x": 0, + "y": 6 + }, + "id": 7, + "options": { + "legend": { + "displayMode": "list", + "placement": "right", + "showLegend": true + }, + "pieType": "pie", + "reduceOptions": { + "calcs": ["lastNotNull"], + "fields": "", + "values": false + }, + "tooltip": { + "mode": "single", + "sort": "none" + } + }, + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "editorMode": "code", + "expr": "wordpress_users_total", + "instant": true, + "legendFormat": "{{role}}", + "refId": "A" + } + ], + "title": "Users by Role", + "type": "piechart" + }, + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "palette-classic" + }, + "custom": { + "hideFrom": { + "legend": false, + "tooltip": false, + "viz": false + } + }, + "mappings": [] + }, + "overrides": [] + }, + "gridPos": { + "h": 8, + "w": 8, + "x": 8, + "y": 6 + }, + "id": 8, + "options": { + "legend": { + "displayMode": "list", + "placement": "right", + "showLegend": true + }, + "pieType": "pie", + "reduceOptions": { + "calcs": ["lastNotNull"], + "fields": "", + "values": false + }, + "tooltip": { + "mode": "single", + "sort": "none" + } + }, + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "editorMode": "code", + "expr": "wordpress_posts_total{post_type=\"post\"}", + "instant": true, + "legendFormat": "{{status}}", + "refId": "A" + } + ], + "title": "Posts by Status", + "type": "piechart" + }, + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "palette-classic" + }, + "custom": { + "hideFrom": { + "legend": false, + "tooltip": false, + "viz": false + } + }, + "mappings": [] + }, + "overrides": [] + }, + "gridPos": { + "h": 8, + "w": 8, + "x": 16, + "y": 6 + }, + "id": 9, + "options": { + "legend": { + "displayMode": "list", + "placement": "right", + "showLegend": true + }, + "pieType": "pie", + "reduceOptions": { + "calcs": ["lastNotNull"], + "fields": "", + "values": false + }, + "tooltip": { + "mode": "single", + "sort": "none" + } + }, + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "editorMode": "code", + "expr": "wordpress_comments_total{status!=\"total_comments\"}", + "instant": true, + "legendFormat": "{{status}}", + "refId": "A" + } + ], + "title": "Comments by Status", + "type": "piechart" + }, + { + "collapsed": false, + "gridPos": { + "h": 1, + "w": 24, + "x": 0, + "y": 14 + }, + "id": 10, + "panels": [], + "title": "System Health", + "type": "row" + }, + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "thresholds" + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + }, + { + "color": "yellow", + "value": 5 + }, + { + "color": "red", + "value": 10 + } + ] + } + }, + "overrides": [] + }, + "gridPos": { + "h": 4, + "w": 6, + "x": 0, + "y": 15 + }, + "id": 11, + "options": { + "colorMode": "value", + "graphMode": "area", + "justifyMode": "auto", + "orientation": "auto", + "reduceOptions": { + "calcs": ["lastNotNull"], + "fields": "", + "values": false + }, + "textMode": "auto" + }, + "pluginVersion": "10.0.0", + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "editorMode": "code", + "expr": "wordpress_cron_overdue_total", + "instant": true, + "legendFormat": "__auto", + "refId": "A" + } + ], + "title": "Overdue Cron Events", + "type": "stat" + }, + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "thresholds" + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "blue", + "value": null + } + ] + } + }, + "overrides": [] + }, + "gridPos": { + "h": 4, + "w": 6, + "x": 6, + "y": 15 + }, + "id": 12, + "options": { + "colorMode": "value", + "graphMode": "none", + "justifyMode": "auto", + "orientation": "auto", + "reduceOptions": { + "calcs": ["lastNotNull"], + "fields": "", + "values": false + }, + "textMode": "auto" + }, + "pluginVersion": "10.0.0", + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "editorMode": "code", + "expr": "sum(wordpress_cron_events_total)", + "instant": true, + "legendFormat": "__auto", + "refId": "A" + } + ], + "title": "Total Cron Events", + "type": "stat" + }, + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "thresholds" + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "blue", + "value": null + } + ] + } + }, + "overrides": [] + }, + "gridPos": { + "h": 4, + "w": 6, + "x": 12, + "y": 15 + }, + "id": 13, + "options": { + "colorMode": "value", + "graphMode": "none", + "justifyMode": "auto", + "orientation": "auto", + "reduceOptions": { + "calcs": ["lastNotNull"], + "fields": "", + "values": false + }, + "textMode": "auto" + }, + "pluginVersion": "10.0.0", + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "editorMode": "code", + "expr": "wordpress_transients_total{type=\"total\"}", + "instant": true, + "legendFormat": "__auto", + "refId": "A" + } + ], + "title": "Total Transients", + "type": "stat" + }, + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "thresholds" + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + }, + { + "color": "yellow", + "value": 50 + }, + { + "color": "red", + "value": 100 + } + ] + } + }, + "overrides": [] + }, + "gridPos": { + "h": 4, + "w": 6, + "x": 18, + "y": 15 + }, + "id": 14, + "options": { + "colorMode": "value", + "graphMode": "area", + "justifyMode": "auto", + "orientation": "auto", + "reduceOptions": { + "calcs": ["lastNotNull"], + "fields": "", + "values": false + }, + "textMode": "auto" + }, + "pluginVersion": "10.0.0", + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "editorMode": "code", + "expr": "wordpress_transients_total{type=\"expired\"}", + "instant": true, + "legendFormat": "__auto", + "refId": "A" + } + ], + "title": "Expired Transients", + "type": "stat" + }, + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "palette-classic" + }, + "custom": { + "axisBorderShow": false, + "axisCenteredZero": false, + "axisColorMode": "text", + "axisLabel": "", + "axisPlacement": "auto", + "barAlignment": 0, + "drawStyle": "bars", + "fillOpacity": 80, + "gradientMode": "none", + "hideFrom": { + "legend": false, + "tooltip": false, + "viz": false + }, + "insertNulls": false, + "lineInterpolation": "linear", + "lineWidth": 1, + "pointSize": 5, + "scaleDistribution": { + "type": "linear" + }, + "showPoints": "auto", + "spanNulls": false, + "stacking": { + "group": "A", + "mode": "none" + }, + "thresholdsStyle": { + "mode": "off" + } + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + } + ] + } + }, + "overrides": [] + }, + "gridPos": { + "h": 8, + "w": 24, + "x": 0, + "y": 19 + }, + "id": 15, + "options": { + "legend": { + "calcs": [], + "displayMode": "list", + "placement": "bottom", + "showLegend": true + }, + "tooltip": { + "mode": "single", + "sort": "none" + } + }, + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "editorMode": "code", + "expr": "topk(10, wordpress_cron_events_total)", + "instant": false, + "legendFormat": "{{hook}}", + "range": true, + "refId": "A" + } + ], + "title": "Top 10 Cron Hooks", + "type": "timeseries" + } + ], + "refresh": "30s", + "schemaVersion": 39, + "tags": ["wordpress", "prometheus"], + "templating": { + "list": [ + { + "current": { + "selected": false, + "text": "Prometheus", + "value": "Prometheus" + }, + "hide": 0, + "includeAll": false, + "label": "Data Source", + "multi": false, + "name": "DS_PROMETHEUS", + "options": [], + "query": "prometheus", + "queryValue": "", + "refresh": 1, + "regex": "", + "skipUrlSync": false, + "type": "datasource" + } + ] + }, + "time": { + "from": "now-6h", + "to": "now" + }, + "timepicker": {}, + "timezone": "browser", + "title": "WordPress Overview", + "uid": "wp-prometheus-overview", + "version": 1, + "weekStart": "" +} diff --git a/assets/dashboards/wordpress-runtime.json b/assets/dashboards/wordpress-runtime.json new file mode 100644 index 0000000..7f1bbc3 --- /dev/null +++ b/assets/dashboards/wordpress-runtime.json @@ -0,0 +1,987 @@ +{ + "annotations": { + "list": [] + }, + "editable": true, + "fiscalYearStartMonth": 0, + "graphTooltip": 0, + "id": null, + "links": [], + "panels": [ + { + "collapsed": false, + "gridPos": { + "h": 1, + "w": 24, + "x": 0, + "y": 0 + }, + "id": 1, + "panels": [], + "title": "HTTP Requests", + "type": "row" + }, + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "palette-classic" + }, + "custom": { + "axisBorderShow": false, + "axisCenteredZero": false, + "axisColorMode": "text", + "axisLabel": "", + "axisPlacement": "auto", + "barAlignment": 0, + "drawStyle": "line", + "fillOpacity": 10, + "gradientMode": "none", + "hideFrom": { + "legend": false, + "tooltip": false, + "viz": false + }, + "insertNulls": false, + "lineInterpolation": "smooth", + "lineWidth": 2, + "pointSize": 5, + "scaleDistribution": { + "type": "linear" + }, + "showPoints": "never", + "spanNulls": false, + "stacking": { + "group": "A", + "mode": "none" + }, + "thresholdsStyle": { + "mode": "off" + } + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + } + ] + }, + "unit": "reqps" + }, + "overrides": [] + }, + "gridPos": { + "h": 8, + "w": 12, + "x": 0, + "y": 1 + }, + "id": 2, + "options": { + "legend": { + "calcs": ["mean", "max"], + "displayMode": "table", + "placement": "bottom", + "showLegend": true + }, + "tooltip": { + "mode": "multi", + "sort": "desc" + } + }, + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "editorMode": "code", + "expr": "sum(rate(wordpress_http_requests_total[5m])) by (endpoint)", + "legendFormat": "{{endpoint}}", + "range": true, + "refId": "A" + } + ], + "title": "Requests per Second by Endpoint", + "type": "timeseries" + }, + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "palette-classic" + }, + "custom": { + "axisBorderShow": false, + "axisCenteredZero": false, + "axisColorMode": "text", + "axisLabel": "", + "axisPlacement": "auto", + "barAlignment": 0, + "drawStyle": "line", + "fillOpacity": 10, + "gradientMode": "none", + "hideFrom": { + "legend": false, + "tooltip": false, + "viz": false + }, + "insertNulls": false, + "lineInterpolation": "smooth", + "lineWidth": 2, + "pointSize": 5, + "scaleDistribution": { + "type": "linear" + }, + "showPoints": "never", + "spanNulls": false, + "stacking": { + "group": "A", + "mode": "none" + }, + "thresholdsStyle": { + "mode": "off" + } + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + } + ] + }, + "unit": "reqps" + }, + "overrides": [ + { + "matcher": { + "id": "byRegexp", + "options": "/2..$/" + }, + "properties": [ + { + "id": "color", + "value": { + "fixedColor": "green", + "mode": "fixed" + } + } + ] + }, + { + "matcher": { + "id": "byRegexp", + "options": "/4..$/" + }, + "properties": [ + { + "id": "color", + "value": { + "fixedColor": "orange", + "mode": "fixed" + } + } + ] + }, + { + "matcher": { + "id": "byRegexp", + "options": "/5..$/" + }, + "properties": [ + { + "id": "color", + "value": { + "fixedColor": "red", + "mode": "fixed" + } + } + ] + } + ] + }, + "gridPos": { + "h": 8, + "w": 12, + "x": 12, + "y": 1 + }, + "id": 3, + "options": { + "legend": { + "calcs": ["mean", "max"], + "displayMode": "table", + "placement": "bottom", + "showLegend": true + }, + "tooltip": { + "mode": "multi", + "sort": "desc" + } + }, + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "editorMode": "code", + "expr": "sum(rate(wordpress_http_requests_total[5m])) by (status)", + "legendFormat": "{{status}}", + "range": true, + "refId": "A" + } + ], + "title": "Requests per Second by Status", + "type": "timeseries" + }, + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "palette-classic" + }, + "custom": { + "hideFrom": { + "legend": false, + "tooltip": false, + "viz": false + } + }, + "mappings": [] + }, + "overrides": [] + }, + "gridPos": { + "h": 8, + "w": 8, + "x": 0, + "y": 9 + }, + "id": 4, + "options": { + "legend": { + "displayMode": "list", + "placement": "right", + "showLegend": true + }, + "pieType": "donut", + "reduceOptions": { + "calcs": ["lastNotNull"], + "fields": "", + "values": false + }, + "tooltip": { + "mode": "single", + "sort": "none" + } + }, + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "editorMode": "code", + "expr": "sum(wordpress_http_requests_total) by (method)", + "instant": true, + "legendFormat": "{{method}}", + "refId": "A" + } + ], + "title": "Requests by Method", + "type": "piechart" + }, + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "palette-classic" + }, + "custom": { + "hideFrom": { + "legend": false, + "tooltip": false, + "viz": false + } + }, + "mappings": [] + }, + "overrides": [] + }, + "gridPos": { + "h": 8, + "w": 8, + "x": 8, + "y": 9 + }, + "id": 5, + "options": { + "legend": { + "displayMode": "list", + "placement": "right", + "showLegend": true + }, + "pieType": "donut", + "reduceOptions": { + "calcs": ["lastNotNull"], + "fields": "", + "values": false + }, + "tooltip": { + "mode": "single", + "sort": "none" + } + }, + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "editorMode": "code", + "expr": "sum(wordpress_http_requests_total) by (endpoint)", + "instant": true, + "legendFormat": "{{endpoint}}", + "refId": "A" + } + ], + "title": "Requests by Endpoint", + "type": "piechart" + }, + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "thresholds" + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "blue", + "value": null + } + ] + }, + "unit": "short" + }, + "overrides": [] + }, + "gridPos": { + "h": 8, + "w": 8, + "x": 16, + "y": 9 + }, + "id": 6, + "options": { + "colorMode": "value", + "graphMode": "area", + "justifyMode": "auto", + "orientation": "auto", + "reduceOptions": { + "calcs": ["lastNotNull"], + "fields": "", + "values": false + }, + "textMode": "auto" + }, + "pluginVersion": "10.0.0", + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "editorMode": "code", + "expr": "sum(wordpress_http_requests_total)", + "instant": true, + "legendFormat": "__auto", + "refId": "A" + } + ], + "title": "Total Requests (All Time)", + "type": "stat" + }, + { + "collapsed": false, + "gridPos": { + "h": 1, + "w": 24, + "x": 0, + "y": 17 + }, + "id": 7, + "panels": [], + "title": "Request Duration", + "type": "row" + }, + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "palette-classic" + }, + "custom": { + "axisBorderShow": false, + "axisCenteredZero": false, + "axisColorMode": "text", + "axisLabel": "", + "axisPlacement": "auto", + "barAlignment": 0, + "drawStyle": "line", + "fillOpacity": 10, + "gradientMode": "none", + "hideFrom": { + "legend": false, + "tooltip": false, + "viz": false + }, + "insertNulls": false, + "lineInterpolation": "smooth", + "lineWidth": 2, + "pointSize": 5, + "scaleDistribution": { + "type": "linear" + }, + "showPoints": "never", + "spanNulls": false, + "stacking": { + "group": "A", + "mode": "none" + }, + "thresholdsStyle": { + "mode": "off" + } + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + } + ] + }, + "unit": "s" + }, + "overrides": [] + }, + "gridPos": { + "h": 8, + "w": 12, + "x": 0, + "y": 18 + }, + "id": 8, + "options": { + "legend": { + "calcs": ["mean", "max"], + "displayMode": "table", + "placement": "bottom", + "showLegend": true + }, + "tooltip": { + "mode": "multi", + "sort": "desc" + } + }, + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "editorMode": "code", + "expr": "wordpress_http_request_duration_seconds_sum / wordpress_http_request_duration_seconds_count", + "legendFormat": "{{method}} {{endpoint}}", + "range": true, + "refId": "A" + } + ], + "title": "Average Request Duration", + "type": "timeseries" + }, + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "palette-classic" + }, + "custom": { + "axisBorderShow": false, + "axisCenteredZero": false, + "axisColorMode": "text", + "axisLabel": "", + "axisPlacement": "auto", + "fillOpacity": 80, + "gradientMode": "none", + "hideFrom": { + "legend": false, + "tooltip": false, + "viz": false + }, + "lineWidth": 1, + "scaleDistribution": { + "type": "linear" + }, + "thresholdsStyle": { + "mode": "off" + } + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + } + ] + } + }, + "overrides": [] + }, + "gridPos": { + "h": 8, + "w": 12, + "x": 12, + "y": 18 + }, + "id": 9, + "options": { + "barRadius": 0, + "barWidth": 0.97, + "fullHighlight": false, + "groupWidth": 0.7, + "legend": { + "calcs": [], + "displayMode": "list", + "placement": "bottom", + "showLegend": true + }, + "orientation": "horizontal", + "showValue": "auto", + "stacking": "none", + "tooltip": { + "mode": "single", + "sort": "none" + }, + "xTickLabelRotation": 0, + "xTickLabelSpacing": 0 + }, + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "editorMode": "code", + "expr": "sum(wordpress_http_request_duration_seconds_bucket) by (le)", + "format": "table", + "instant": true, + "legendFormat": "{{le}}", + "refId": "A" + } + ], + "title": "Request Duration Distribution (Buckets)", + "type": "barchart" + }, + { + "collapsed": false, + "gridPos": { + "h": 1, + "w": 24, + "x": 0, + "y": 26 + }, + "id": 10, + "panels": [], + "title": "Database Queries", + "type": "row" + }, + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "palette-classic" + }, + "custom": { + "axisBorderShow": false, + "axisCenteredZero": false, + "axisColorMode": "text", + "axisLabel": "", + "axisPlacement": "auto", + "barAlignment": 0, + "drawStyle": "line", + "fillOpacity": 10, + "gradientMode": "none", + "hideFrom": { + "legend": false, + "tooltip": false, + "viz": false + }, + "insertNulls": false, + "lineInterpolation": "smooth", + "lineWidth": 2, + "pointSize": 5, + "scaleDistribution": { + "type": "linear" + }, + "showPoints": "never", + "spanNulls": false, + "stacking": { + "group": "A", + "mode": "none" + }, + "thresholdsStyle": { + "mode": "off" + } + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + } + ] + }, + "unit": "short" + }, + "overrides": [] + }, + "gridPos": { + "h": 8, + "w": 12, + "x": 0, + "y": 27 + }, + "id": 11, + "options": { + "legend": { + "calcs": ["mean", "max"], + "displayMode": "table", + "placement": "bottom", + "showLegend": true + }, + "tooltip": { + "mode": "multi", + "sort": "desc" + } + }, + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "editorMode": "code", + "expr": "rate(wordpress_db_queries_total[5m])", + "legendFormat": "{{endpoint}}", + "range": true, + "refId": "A" + } + ], + "title": "Database Queries per Second", + "type": "timeseries" + }, + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "palette-classic" + }, + "custom": { + "axisBorderShow": false, + "axisCenteredZero": false, + "axisColorMode": "text", + "axisLabel": "", + "axisPlacement": "auto", + "barAlignment": 0, + "drawStyle": "line", + "fillOpacity": 10, + "gradientMode": "none", + "hideFrom": { + "legend": false, + "tooltip": false, + "viz": false + }, + "insertNulls": false, + "lineInterpolation": "smooth", + "lineWidth": 2, + "pointSize": 5, + "scaleDistribution": { + "type": "linear" + }, + "showPoints": "never", + "spanNulls": false, + "stacking": { + "group": "A", + "mode": "none" + }, + "thresholdsStyle": { + "mode": "off" + } + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + } + ] + }, + "unit": "s" + }, + "overrides": [] + }, + "gridPos": { + "h": 8, + "w": 12, + "x": 12, + "y": 27 + }, + "id": 12, + "options": { + "legend": { + "calcs": ["mean", "max"], + "displayMode": "table", + "placement": "bottom", + "showLegend": true + }, + "tooltip": { + "mode": "multi", + "sort": "desc" + } + }, + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "editorMode": "code", + "expr": "wordpress_db_query_duration_seconds_sum / wordpress_db_query_duration_seconds_count", + "legendFormat": "{{endpoint}}", + "range": true, + "refId": "A" + } + ], + "title": "Average Query Duration", + "type": "timeseries" + }, + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "thresholds" + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "blue", + "value": null + } + ] + }, + "unit": "short" + }, + "overrides": [] + }, + "gridPos": { + "h": 4, + "w": 12, + "x": 0, + "y": 35 + }, + "id": 13, + "options": { + "colorMode": "value", + "graphMode": "area", + "justifyMode": "auto", + "orientation": "auto", + "reduceOptions": { + "calcs": ["lastNotNull"], + "fields": "", + "values": false + }, + "textMode": "auto" + }, + "pluginVersion": "10.0.0", + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "editorMode": "code", + "expr": "sum(wordpress_db_queries_total)", + "instant": true, + "legendFormat": "__auto", + "refId": "A" + } + ], + "title": "Total Database Queries (All Time)", + "type": "stat" + }, + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "thresholds" + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + }, + { + "color": "yellow", + "value": 0.1 + }, + { + "color": "red", + "value": 0.5 + } + ] + }, + "unit": "s" + }, + "overrides": [] + }, + "gridPos": { + "h": 4, + "w": 12, + "x": 12, + "y": 35 + }, + "id": 14, + "options": { + "colorMode": "value", + "graphMode": "area", + "justifyMode": "auto", + "orientation": "auto", + "reduceOptions": { + "calcs": ["lastNotNull"], + "fields": "", + "values": false + }, + "textMode": "auto" + }, + "pluginVersion": "10.0.0", + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "editorMode": "code", + "expr": "sum(wordpress_db_query_duration_seconds_sum) / sum(wordpress_db_query_duration_seconds_count)", + "instant": true, + "legendFormat": "__auto", + "refId": "A" + } + ], + "title": "Average Query Duration (Overall)", + "type": "stat" + } + ], + "refresh": "30s", + "schemaVersion": 39, + "tags": ["wordpress", "prometheus", "performance"], + "templating": { + "list": [ + { + "current": { + "selected": false, + "text": "Prometheus", + "value": "Prometheus" + }, + "hide": 0, + "includeAll": false, + "label": "Data Source", + "multi": false, + "name": "DS_PROMETHEUS", + "options": [], + "query": "prometheus", + "queryValue": "", + "refresh": 1, + "regex": "", + "skipUrlSync": false, + "type": "datasource" + } + ] + }, + "time": { + "from": "now-6h", + "to": "now" + }, + "timepicker": {}, + "timezone": "browser", + "title": "WordPress Runtime Performance", + "uid": "wp-prometheus-runtime", + "version": 1, + "weekStart": "" +} diff --git a/assets/dashboards/wordpress-woocommerce.json b/assets/dashboards/wordpress-woocommerce.json new file mode 100644 index 0000000..69a7ec7 --- /dev/null +++ b/assets/dashboards/wordpress-woocommerce.json @@ -0,0 +1,1296 @@ +{ + "annotations": { + "list": [] + }, + "editable": true, + "fiscalYearStartMonth": 0, + "graphTooltip": 0, + "id": null, + "links": [], + "panels": [ + { + "collapsed": false, + "gridPos": { + "h": 1, + "w": 24, + "x": 0, + "y": 0 + }, + "id": 1, + "panels": [], + "title": "Revenue Overview", + "type": "row" + }, + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "thresholds" + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + } + ] + }, + "unit": "currencyUSD" + }, + "overrides": [] + }, + "gridPos": { + "h": 6, + "w": 8, + "x": 0, + "y": 1 + }, + "id": 2, + "options": { + "colorMode": "value", + "graphMode": "area", + "justifyMode": "auto", + "orientation": "auto", + "reduceOptions": { + "calcs": ["lastNotNull"], + "fields": "", + "values": false + }, + "textMode": "auto" + }, + "pluginVersion": "10.0.0", + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "editorMode": "code", + "expr": "wordpress_woocommerce_revenue_total{period=\"all_time\"}", + "instant": true, + "legendFormat": "__auto", + "refId": "A" + } + ], + "title": "Total Revenue (All Time)", + "type": "stat" + }, + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "thresholds" + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "blue", + "value": null + } + ] + }, + "unit": "currencyUSD" + }, + "overrides": [] + }, + "gridPos": { + "h": 6, + "w": 8, + "x": 8, + "y": 1 + }, + "id": 3, + "options": { + "colorMode": "value", + "graphMode": "area", + "justifyMode": "auto", + "orientation": "auto", + "reduceOptions": { + "calcs": ["lastNotNull"], + "fields": "", + "values": false + }, + "textMode": "auto" + }, + "pluginVersion": "10.0.0", + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "editorMode": "code", + "expr": "wordpress_woocommerce_revenue_total{period=\"month\"}", + "instant": true, + "legendFormat": "__auto", + "refId": "A" + } + ], + "title": "Revenue (This Month)", + "type": "stat" + }, + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "thresholds" + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "purple", + "value": null + } + ] + }, + "unit": "currencyUSD" + }, + "overrides": [] + }, + "gridPos": { + "h": 6, + "w": 8, + "x": 16, + "y": 1 + }, + "id": 4, + "options": { + "colorMode": "value", + "graphMode": "area", + "justifyMode": "auto", + "orientation": "auto", + "reduceOptions": { + "calcs": ["lastNotNull"], + "fields": "", + "values": false + }, + "textMode": "auto" + }, + "pluginVersion": "10.0.0", + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "editorMode": "code", + "expr": "wordpress_woocommerce_revenue_total{period=\"today\"}", + "instant": true, + "legendFormat": "__auto", + "refId": "A" + } + ], + "title": "Revenue (Today)", + "type": "stat" + }, + { + "collapsed": false, + "gridPos": { + "h": 1, + "w": 24, + "x": 0, + "y": 7 + }, + "id": 5, + "panels": [], + "title": "Orders", + "type": "row" + }, + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "thresholds" + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + } + ] + } + }, + "overrides": [] + }, + "gridPos": { + "h": 4, + "w": 4, + "x": 0, + "y": 8 + }, + "id": 6, + "options": { + "colorMode": "value", + "graphMode": "none", + "justifyMode": "auto", + "orientation": "auto", + "reduceOptions": { + "calcs": ["lastNotNull"], + "fields": "", + "values": false + }, + "textMode": "auto" + }, + "pluginVersion": "10.0.0", + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "editorMode": "code", + "expr": "wordpress_woocommerce_orders_total{status=\"completed\"}", + "instant": true, + "legendFormat": "__auto", + "refId": "A" + } + ], + "title": "Completed", + "type": "stat" + }, + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "thresholds" + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "blue", + "value": null + } + ] + } + }, + "overrides": [] + }, + "gridPos": { + "h": 4, + "w": 4, + "x": 4, + "y": 8 + }, + "id": 7, + "options": { + "colorMode": "value", + "graphMode": "none", + "justifyMode": "auto", + "orientation": "auto", + "reduceOptions": { + "calcs": ["lastNotNull"], + "fields": "", + "values": false + }, + "textMode": "auto" + }, + "pluginVersion": "10.0.0", + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "editorMode": "code", + "expr": "wordpress_woocommerce_orders_total{status=\"processing\"}", + "instant": true, + "legendFormat": "__auto", + "refId": "A" + } + ], + "title": "Processing", + "type": "stat" + }, + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "thresholds" + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "yellow", + "value": null + } + ] + } + }, + "overrides": [] + }, + "gridPos": { + "h": 4, + "w": 4, + "x": 8, + "y": 8 + }, + "id": 8, + "options": { + "colorMode": "value", + "graphMode": "none", + "justifyMode": "auto", + "orientation": "auto", + "reduceOptions": { + "calcs": ["lastNotNull"], + "fields": "", + "values": false + }, + "textMode": "auto" + }, + "pluginVersion": "10.0.0", + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "editorMode": "code", + "expr": "wordpress_woocommerce_orders_total{status=\"pending\"}", + "instant": true, + "legendFormat": "__auto", + "refId": "A" + } + ], + "title": "Pending", + "type": "stat" + }, + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "thresholds" + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "orange", + "value": null + } + ] + } + }, + "overrides": [] + }, + "gridPos": { + "h": 4, + "w": 4, + "x": 12, + "y": 8 + }, + "id": 9, + "options": { + "colorMode": "value", + "graphMode": "none", + "justifyMode": "auto", + "orientation": "auto", + "reduceOptions": { + "calcs": ["lastNotNull"], + "fields": "", + "values": false + }, + "textMode": "auto" + }, + "pluginVersion": "10.0.0", + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "editorMode": "code", + "expr": "wordpress_woocommerce_orders_total{status=\"on-hold\"}", + "instant": true, + "legendFormat": "__auto", + "refId": "A" + } + ], + "title": "On Hold", + "type": "stat" + }, + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "thresholds" + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "red", + "value": null + } + ] + } + }, + "overrides": [] + }, + "gridPos": { + "h": 4, + "w": 4, + "x": 16, + "y": 8 + }, + "id": 10, + "options": { + "colorMode": "value", + "graphMode": "none", + "justifyMode": "auto", + "orientation": "auto", + "reduceOptions": { + "calcs": ["lastNotNull"], + "fields": "", + "values": false + }, + "textMode": "auto" + }, + "pluginVersion": "10.0.0", + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "editorMode": "code", + "expr": "wordpress_woocommerce_orders_total{status=\"cancelled\"}", + "instant": true, + "legendFormat": "__auto", + "refId": "A" + } + ], + "title": "Cancelled", + "type": "stat" + }, + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "thresholds" + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "dark-red", + "value": null + } + ] + } + }, + "overrides": [] + }, + "gridPos": { + "h": 4, + "w": 4, + "x": 20, + "y": 8 + }, + "id": 11, + "options": { + "colorMode": "value", + "graphMode": "none", + "justifyMode": "auto", + "orientation": "auto", + "reduceOptions": { + "calcs": ["lastNotNull"], + "fields": "", + "values": false + }, + "textMode": "auto" + }, + "pluginVersion": "10.0.0", + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "editorMode": "code", + "expr": "wordpress_woocommerce_orders_total{status=\"refunded\"}", + "instant": true, + "legendFormat": "__auto", + "refId": "A" + } + ], + "title": "Refunded", + "type": "stat" + }, + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "palette-classic" + }, + "custom": { + "hideFrom": { + "legend": false, + "tooltip": false, + "viz": false + } + }, + "mappings": [] + }, + "overrides": [ + { + "matcher": { + "id": "byName", + "options": "completed" + }, + "properties": [ + { + "id": "color", + "value": { + "fixedColor": "green", + "mode": "fixed" + } + } + ] + }, + { + "matcher": { + "id": "byName", + "options": "processing" + }, + "properties": [ + { + "id": "color", + "value": { + "fixedColor": "blue", + "mode": "fixed" + } + } + ] + }, + { + "matcher": { + "id": "byName", + "options": "pending" + }, + "properties": [ + { + "id": "color", + "value": { + "fixedColor": "yellow", + "mode": "fixed" + } + } + ] + }, + { + "matcher": { + "id": "byName", + "options": "cancelled" + }, + "properties": [ + { + "id": "color", + "value": { + "fixedColor": "red", + "mode": "fixed" + } + } + ] + } + ] + }, + "gridPos": { + "h": 8, + "w": 12, + "x": 0, + "y": 12 + }, + "id": 12, + "options": { + "legend": { + "displayMode": "list", + "placement": "right", + "showLegend": true + }, + "pieType": "donut", + "reduceOptions": { + "calcs": ["lastNotNull"], + "fields": "", + "values": false + }, + "tooltip": { + "mode": "single", + "sort": "none" + } + }, + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "editorMode": "code", + "expr": "wordpress_woocommerce_orders_total", + "instant": true, + "legendFormat": "{{status}}", + "refId": "A" + } + ], + "title": "Orders by Status", + "type": "piechart" + }, + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "palette-classic" + }, + "custom": { + "axisBorderShow": false, + "axisCenteredZero": false, + "axisColorMode": "text", + "axisLabel": "", + "axisPlacement": "auto", + "barAlignment": 0, + "drawStyle": "line", + "fillOpacity": 10, + "gradientMode": "none", + "hideFrom": { + "legend": false, + "tooltip": false, + "viz": false + }, + "insertNulls": false, + "lineInterpolation": "smooth", + "lineWidth": 2, + "pointSize": 5, + "scaleDistribution": { + "type": "linear" + }, + "showPoints": "never", + "spanNulls": false, + "stacking": { + "group": "A", + "mode": "none" + }, + "thresholdsStyle": { + "mode": "off" + } + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + } + ] + } + }, + "overrides": [] + }, + "gridPos": { + "h": 8, + "w": 12, + "x": 12, + "y": 12 + }, + "id": 13, + "options": { + "legend": { + "calcs": [], + "displayMode": "list", + "placement": "bottom", + "showLegend": true + }, + "tooltip": { + "mode": "multi", + "sort": "none" + } + }, + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "editorMode": "code", + "expr": "wordpress_woocommerce_orders_total", + "legendFormat": "{{status}}", + "range": true, + "refId": "A" + } + ], + "title": "Orders Over Time", + "type": "timeseries" + }, + { + "collapsed": false, + "gridPos": { + "h": 1, + "w": 24, + "x": 0, + "y": 20 + }, + "id": 14, + "panels": [], + "title": "Products", + "type": "row" + }, + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "thresholds" + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "blue", + "value": null + } + ] + } + }, + "overrides": [] + }, + "gridPos": { + "h": 4, + "w": 6, + "x": 0, + "y": 21 + }, + "id": 15, + "options": { + "colorMode": "value", + "graphMode": "none", + "justifyMode": "auto", + "orientation": "auto", + "reduceOptions": { + "calcs": ["lastNotNull"], + "fields": "", + "values": false + }, + "textMode": "auto" + }, + "pluginVersion": "10.0.0", + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "editorMode": "code", + "expr": "wordpress_woocommerce_products_total{status=\"publish\", type=\"all\"}", + "instant": true, + "legendFormat": "__auto", + "refId": "A" + } + ], + "title": "Published Products", + "type": "stat" + }, + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "thresholds" + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "yellow", + "value": null + } + ] + } + }, + "overrides": [] + }, + "gridPos": { + "h": 4, + "w": 6, + "x": 6, + "y": 21 + }, + "id": 16, + "options": { + "colorMode": "value", + "graphMode": "none", + "justifyMode": "auto", + "orientation": "auto", + "reduceOptions": { + "calcs": ["lastNotNull"], + "fields": "", + "values": false + }, + "textMode": "auto" + }, + "pluginVersion": "10.0.0", + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "editorMode": "code", + "expr": "wordpress_woocommerce_products_total{status=\"draft\", type=\"all\"}", + "instant": true, + "legendFormat": "__auto", + "refId": "A" + } + ], + "title": "Draft Products", + "type": "stat" + }, + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "palette-classic" + }, + "custom": { + "hideFrom": { + "legend": false, + "tooltip": false, + "viz": false + } + }, + "mappings": [] + }, + "overrides": [] + }, + "gridPos": { + "h": 8, + "w": 12, + "x": 12, + "y": 21 + }, + "id": 17, + "options": { + "legend": { + "displayMode": "list", + "placement": "right", + "showLegend": true + }, + "pieType": "donut", + "reduceOptions": { + "calcs": ["lastNotNull"], + "fields": "", + "values": false + }, + "tooltip": { + "mode": "single", + "sort": "none" + } + }, + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "editorMode": "code", + "expr": "wordpress_woocommerce_products_total{status=\"publish\", type!=\"all\"}", + "instant": true, + "legendFormat": "{{type}}", + "refId": "A" + } + ], + "title": "Products by Type", + "type": "piechart" + }, + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "palette-classic" + }, + "custom": { + "hideFrom": { + "legend": false, + "tooltip": false, + "viz": false + } + }, + "mappings": [] + }, + "overrides": [] + }, + "gridPos": { + "h": 4, + "w": 12, + "x": 0, + "y": 25 + }, + "id": 18, + "options": { + "legend": { + "displayMode": "list", + "placement": "right", + "showLegend": true + }, + "pieType": "pie", + "reduceOptions": { + "calcs": ["lastNotNull"], + "fields": "", + "values": false + }, + "tooltip": { + "mode": "single", + "sort": "none" + } + }, + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "editorMode": "code", + "expr": "wordpress_woocommerce_products_total{type=\"all\"}", + "instant": true, + "legendFormat": "{{status}}", + "refId": "A" + } + ], + "title": "Products by Status", + "type": "piechart" + }, + { + "collapsed": false, + "gridPos": { + "h": 1, + "w": 24, + "x": 0, + "y": 29 + }, + "id": 19, + "panels": [], + "title": "Customers", + "type": "row" + }, + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "thresholds" + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "blue", + "value": null + } + ] + } + }, + "overrides": [] + }, + "gridPos": { + "h": 6, + "w": 8, + "x": 0, + "y": 30 + }, + "id": 20, + "options": { + "colorMode": "value", + "graphMode": "area", + "justifyMode": "auto", + "orientation": "auto", + "reduceOptions": { + "calcs": ["lastNotNull"], + "fields": "", + "values": false + }, + "textMode": "auto" + }, + "pluginVersion": "10.0.0", + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "editorMode": "code", + "expr": "wordpress_woocommerce_customers_total{type=\"registered\"}", + "instant": true, + "legendFormat": "__auto", + "refId": "A" + } + ], + "title": "Registered Customers", + "type": "stat" + }, + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "thresholds" + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "purple", + "value": null + } + ] + } + }, + "overrides": [] + }, + "gridPos": { + "h": 6, + "w": 8, + "x": 8, + "y": 30 + }, + "id": 21, + "options": { + "colorMode": "value", + "graphMode": "area", + "justifyMode": "auto", + "orientation": "auto", + "reduceOptions": { + "calcs": ["lastNotNull"], + "fields": "", + "values": false + }, + "textMode": "auto" + }, + "pluginVersion": "10.0.0", + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "editorMode": "code", + "expr": "wordpress_woocommerce_customers_total{type=\"guest\"}", + "instant": true, + "legendFormat": "__auto", + "refId": "A" + } + ], + "title": "Guest Customers", + "type": "stat" + }, + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "palette-classic" + }, + "custom": { + "hideFrom": { + "legend": false, + "tooltip": false, + "viz": false + } + }, + "mappings": [] + }, + "overrides": [ + { + "matcher": { + "id": "byName", + "options": "registered" + }, + "properties": [ + { + "id": "color", + "value": { + "fixedColor": "blue", + "mode": "fixed" + } + } + ] + }, + { + "matcher": { + "id": "byName", + "options": "guest" + }, + "properties": [ + { + "id": "color", + "value": { + "fixedColor": "purple", + "mode": "fixed" + } + } + ] + } + ] + }, + "gridPos": { + "h": 6, + "w": 8, + "x": 16, + "y": 30 + }, + "id": 22, + "options": { + "legend": { + "displayMode": "list", + "placement": "right", + "showLegend": true + }, + "pieType": "donut", + "reduceOptions": { + "calcs": ["lastNotNull"], + "fields": "", + "values": false + }, + "tooltip": { + "mode": "single", + "sort": "none" + } + }, + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "editorMode": "code", + "expr": "wordpress_woocommerce_customers_total", + "instant": true, + "legendFormat": "{{type}}", + "refId": "A" + } + ], + "title": "Customer Distribution", + "type": "piechart" + } + ], + "refresh": "30s", + "schemaVersion": 39, + "tags": ["wordpress", "prometheus", "woocommerce"], + "templating": { + "list": [ + { + "current": { + "selected": false, + "text": "Prometheus", + "value": "Prometheus" + }, + "hide": 0, + "includeAll": false, + "label": "Data Source", + "multi": false, + "name": "DS_PROMETHEUS", + "options": [], + "query": "prometheus", + "queryValue": "", + "refresh": 1, + "regex": "", + "skipUrlSync": false, + "type": "datasource" + } + ] + }, + "time": { + "from": "now-6h", + "to": "now" + }, + "timepicker": {}, + "timezone": "browser", + "title": "WooCommerce Store", + "uid": "wp-prometheus-woocommerce", + "version": 1, + "weekStart": "" +} diff --git a/assets/js/admin.js b/assets/js/admin.js index eb91125..c22693f 100644 --- a/assets/js/admin.js +++ b/assets/js/admin.js @@ -7,7 +7,26 @@ (function($) { 'use strict'; + var importFileContent = null; + $(document).ready(function() { + // License tab handlers. + initLicenseHandlers(); + + // Custom metrics tab handlers. + initCustomMetricsHandlers(); + + // Dashboards tab handlers. + initDashboardsHandlers(); + + // Runtime metrics reset handler. + initResetRuntimeHandler(); + }); + + /** + * Initialize license tab handlers. + */ + function initLicenseHandlers() { // Validate license button. $('#wp-prometheus-validate-license').on('click', function(e) { e.preventDefault(); @@ -23,78 +42,575 @@ // Regenerate token button. $('#wp-prometheus-regenerate-token').on('click', function(e) { e.preventDefault(); - if (confirm('Are you sure you want to regenerate the auth token? You will need to update your Prometheus configuration.')) { + if (confirm(wpPrometheus.confirmRegenerateToken)) { var newToken = generateToken(32); $('#wp_prometheus_auth_token').val(newToken); } }); + } - /** - * Perform a license action via AJAX. - * - * @param {string} action AJAX action name. - * @param {string} message Loading message. - */ - function performLicenseAction(action, message) { - var $spinner = $('#wp-prometheus-license-spinner'); - var $message = $('#wp-prometheus-license-message'); + /** + * Initialize custom metrics tab handlers. + */ + function initCustomMetricsHandlers() { + var $formContainer = $('#wp-prometheus-metric-form-container'); + var $form = $('#wp-prometheus-metric-form'); + var $showFormBtn = $('#show-metric-form'); - $spinner.addClass('is-active'); - $message.hide(); + // Show metric form. + $showFormBtn.on('click', function() { + resetMetricForm(); + $formContainer.slideDown(); + $(this).hide(); + }); - $.ajax({ - url: wpPrometheus.ajaxUrl, - type: 'POST', - data: { - action: action, - nonce: wpPrometheus.nonce - }, - success: function(response) { - $spinner.removeClass('is-active'); + // Cancel metric form. + $('#cancel-metric-form').on('click', function() { + $formContainer.slideUp(); + $showFormBtn.show(); + // Remove edit parameter from URL. + if (window.location.search.indexOf('edit=') > -1) { + window.history.pushState({}, '', window.location.pathname + '?page=wp-prometheus&tab=custom'); + } + }); - if (response.success) { - $message - .removeClass('notice-error') - .addClass('notice notice-success') - .html('
' + response.data.message + '
') - .show(); + // Value type toggle. + $('input[name="value_type"]').on('change', function() { + var valueType = $(this).val(); + if (valueType === 'option') { + $('#option-config-row').show(); + $('#static-values-row').hide(); + } else { + $('#option-config-row').hide(); + $('#static-values-row').show(); + } + }); - // Reload page after successful validation/activation. - setTimeout(function() { - location.reload(); - }, 1500); - } else { - $message - .removeClass('notice-success') - .addClass('notice notice-error') - .html('' + (response.data.message || 'An error occurred.') + '
') - .show(); - } - }, - error: function() { - $spinner.removeClass('is-active'); + // Add label. + $('#add-label').on('click', function() { + var $container = $('#metric-labels-container'); + var labelCount = $container.find('.metric-label-row').length; + + if (labelCount >= 5) { + alert('Maximum 5 labels allowed per metric.'); + return; + } + + var $row = $('' + response.data.message + '
') + .show(); + + // Reload page after successful validation/activation. + setTimeout(function() { + location.reload(); + }, 1500); + } else { $message .removeClass('notice-success') .addClass('notice notice-error') - .html('Connection error. Please try again.
') + .html('' + (response.data.message || 'An error occurred.') + '
') .show(); } - }); - } - - /** - * Generate a random token. - * - * @param {number} length Token length. - * @return {string} Generated token. - */ - function generateToken(length) { - var charset = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'; - var token = ''; - for (var i = 0; i < length; i++) { - token += charset.charAt(Math.floor(Math.random() * charset.length)); + }, + error: function() { + $spinner.removeClass('is-active'); + $message + .removeClass('notice-success') + .addClass('notice notice-error') + .html('Connection error. Please try again.
') + .show(); } - return token; + }); + } + + /** + * Save custom metric via AJAX. + */ + function saveCustomMetric() { + var $spinner = $('#wp-prometheus-metric-spinner'); + var $message = $('#wp-prometheus-metric-message'); + var $form = $('#wp-prometheus-metric-form'); + + $spinner.addClass('is-active'); + $message.hide(); + + var formData = $form.serialize(); + formData += '&action=wp_prometheus_save_custom_metric'; + formData += '&nonce=' + wpPrometheus.customMetricNonce; + + $.ajax({ + url: wpPrometheus.ajaxUrl, + type: 'POST', + data: formData, + success: function(response) { + $spinner.removeClass('is-active'); + + if (response.success) { + $message + .removeClass('notice-error') + .addClass('notice notice-success') + .html('' + response.data.message + '
') + .show(); + + setTimeout(function() { + window.location.href = window.location.pathname + '?page=wp-prometheus&tab=custom'; + }, 1000); + } else { + $message + .removeClass('notice-success') + .addClass('notice notice-error') + .html('' + (response.data.message || 'An error occurred.') + '
') + .show(); + } + }, + error: function() { + $spinner.removeClass('is-active'); + $message + .removeClass('notice-success') + .addClass('notice notice-error') + .html('Connection error. Please try again.
') + .show(); + } + }); + } + + /** + * Delete custom metric via AJAX. + * + * @param {string} id Metric ID. + */ + function deleteCustomMetric(id) { + $.ajax({ + url: wpPrometheus.ajaxUrl, + type: 'POST', + data: { + action: 'wp_prometheus_delete_custom_metric', + nonce: wpPrometheus.customMetricNonce, + id: id + }, + success: function(response) { + if (response.success) { + $('tr[data-metric-id="' + id + '"]').fadeOut(function() { + $(this).remove(); + // Check if table is empty. + if ($('.wp-prometheus-custom-metrics tbody tr').length === 0) { + location.reload(); + } + }); + } else { + alert(response.data.message || 'An error occurred.'); + } + }, + error: function() { + alert('Connection error. Please try again.'); + } + }); + } + + /** + * Export metrics via AJAX. + */ + function exportMetrics() { + $.ajax({ + url: wpPrometheus.ajaxUrl, + type: 'POST', + data: { + action: 'wp_prometheus_export_metrics', + nonce: wpPrometheus.exportNonce + }, + success: function(response) { + if (response.success) { + downloadFile(response.data.json, response.data.filename, 'application/json'); + } else { + alert(response.data.message || 'An error occurred.'); + } + }, + error: function() { + alert('Connection error. Please try again.'); + } + }); + } + + /** + * Import metrics via AJAX. + * + * @param {string} json JSON content. + * @param {string} mode Import mode. + */ + function importMetrics(json, mode) { + var $spinner = $('#wp-prometheus-import-spinner'); + var $message = $('#wp-prometheus-import-message'); + + $spinner.addClass('is-active'); + $message.hide(); + + $.ajax({ + url: wpPrometheus.ajaxUrl, + type: 'POST', + data: { + action: 'wp_prometheus_import_metrics', + nonce: wpPrometheus.importNonce, + json: json, + mode: mode + }, + success: function(response) { + $spinner.removeClass('is-active'); + + if (response.success) { + $message + .removeClass('notice-error') + .addClass('notice notice-success') + .html('' + response.data.message + '
') + .show(); + + $('#import-options').slideUp(); + $('#import-metrics-file').val(''); + importFileContent = null; + + setTimeout(function() { + location.reload(); + }, 1500); + } else { + $message + .removeClass('notice-success') + .addClass('notice notice-error') + .html('' + (response.data.message || 'An error occurred.') + '
') + .show(); + } + }, + error: function() { + $spinner.removeClass('is-active'); + $message + .removeClass('notice-success') + .addClass('notice notice-error') + .html('Connection error. Please try again.
') + .show(); + } + }); + } + + /** + * Download dashboard via AJAX. + * + * @param {string} slug Dashboard slug. + */ + function downloadDashboard(slug) { + $.ajax({ + url: wpPrometheus.ajaxUrl, + type: 'POST', + data: { + action: 'wp_prometheus_download_dashboard', + nonce: wpPrometheus.dashboardNonce, + slug: slug + }, + success: function(response) { + if (response.success) { + downloadFile(response.data.json, response.data.filename, 'application/json'); + } else { + alert(response.data.message || 'An error occurred.'); + } + }, + error: function() { + alert('Connection error. Please try again.'); + } + }); + } + + /** + * Reset runtime metrics via AJAX. + */ + function resetRuntimeMetrics() { + var $spinner = $('#wp-prometheus-reset-spinner'); + var $message = $('#wp-prometheus-reset-message'); + + $spinner.addClass('is-active'); + $message.hide(); + + $.ajax({ + url: wpPrometheus.ajaxUrl, + type: 'POST', + data: { + action: 'wp_prometheus_reset_runtime_metrics', + nonce: wpPrometheus.resetRuntimeNonce + }, + success: function(response) { + $spinner.removeClass('is-active'); + + if (response.success) { + $message + .removeClass('notice-error') + .addClass('notice notice-success') + .html('' + response.data.message + '
') + .show(); + } else { + $message + .removeClass('notice-success') + .addClass('notice notice-error') + .html('' + (response.data.message || 'An error occurred.') + '
') + .show(); + } + }, + error: function() { + $spinner.removeClass('is-active'); + $message + .removeClass('notice-success') + .addClass('notice notice-error') + .html('Connection error. Please try again.
') + .show(); + } + }); + } + + /** + * Reset the metric form to default state. + */ + function resetMetricForm() { + var $form = $('#wp-prometheus-metric-form'); + $form[0].reset(); + $('#metric-id').val(''); + $('#wp-prometheus-form-title').text('Add New Metric'); + $('#option-config-row').hide(); + $('#static-values-row').show(); + $('#wp-prometheus-metric-message').hide(); + + // Reset labels to single empty row. + $('#metric-labels-container').html( + '' . esc_html__( 'License settings saved.', 'wp-prometheus' ) . '
' . esc_html__( 'License settings saved.', 'wp-prometheus' ) . '
| - - | -- - | -
|---|---|
| - - | -- - | -
| - - | -- - - | -
- - - - -
- + $status_messages = array( + 'valid' => __( 'License is active and valid.', 'wp-prometheus' ), + 'invalid' => __( 'License is invalid.', 'wp-prometheus' ), + 'expired' => __( 'License has expired.', 'wp-prometheus' ), + 'revoked' => __( 'License has been revoked.', 'wp-prometheus' ), + 'inactive' => __( 'License is inactive.', 'wp-prometheus' ), + 'unchecked' => __( 'License has not been validated yet.', 'wp-prometheus' ), + 'unconfigured' => __( 'License server is not configured.', 'wp-prometheus' ), + ); - - +scrape_configs: +
| + + | ++ + | +
|---|---|
| + + | ++ + | +
| + + | ++ + + | +
+ + + + +
+ + + + + + ++ + +
+ + metric_builder->get_all(); + $editing = isset( $_GET['edit'] ) ? sanitize_key( $_GET['edit'] ) : ''; + $edit_metric = $editing ? $this->metric_builder->get( $editing ) : null; + ?> + ++ +
+ + + + + + +| + | + | + | + | + | + |
|---|---|---|---|---|---|
|
+ + | + | + | + + + + + + | ++ + + + + | +
+ + + + +
+ + + + ++ ' . esc_html( home_url( '/metrics/' ) ) . '' + ); + ?> +
+scrape_configs:
- job_name: 'wordpress'
static_configs:
- targets: ['']
@@ -381,118 +753,118 @@ class Settings {
type: Bearer
credentials: ''
-
- | - | |
-
|---|---|
| - | |
-
| + | |
+
|---|---|
| + | |
+
curl -H "Authorization: Bearer "+ + +
curl -H "Authorization: Bearer "- -
| - | - | - |
|---|---|---|
wordpress_info |
- - | - |
wordpress_users_total |
- - | - |
wordpress_posts_total |
- - | - |
wordpress_comments_total |
- - | - |
wordpress_plugins_total |
- - | - |
wordpress_http_requests_total |
- - | - |
wordpress_http_request_duration_seconds |
- - | - |
wordpress_db_queries_total |
- - | - |
wordpress_cron_events_total |
- - | - |
wordpress_cron_overdue_total |
- - | - |
wordpress_cron_next_run_timestamp |
- - | - |
wordpress_transients_total |
- - | - |
wordpress_woocommerce_products_total |
- - | - |
wordpress_woocommerce_orders_total |
- - | - |
wordpress_woocommerce_revenue_total |
- - | - |
wordpress_woocommerce_customers_total |
- - | - |
| + | + | + |
|---|---|---|
wordpress_info |
+ + | + |
wordpress_users_total |
+ + | + |
wordpress_posts_total |
+ + | + |
wordpress_comments_total |
+ + | + |
wordpress_plugins_total |
+ + | + |
wordpress_http_requests_total |
+ + | + |
wordpress_http_request_duration_seconds |
+ + | + |
wordpress_db_queries_total |
+ + | + |
wordpress_cron_events_total |
+ + | + |
wordpress_cron_overdue_total |
+ + | + |
wordpress_cron_next_run_timestamp |
+ + | + |
wordpress_transients_total |
+ + | + |
wordpress_woocommerce_products_total |
+ + | + |
wordpress_woocommerce_orders_total |
+ + | + |
wordpress_woocommerce_revenue_total |
+ + | + |
wordpress_woocommerce_customers_total |
+ + | + |
add_action( 'wp_prometheus_collect_metrics', function( $collector ) {
+
+
+ add_action( 'wp_prometheus_collect_metrics', function( $collector ) {
$gauge = $collector->register_gauge(
'my_custom_metric',
'Description of my metric',
@@ -500,137 +872,342 @@ class Settings {
);
$gauge->set( 42, array( 'value1', 'value2' ) );
} );
- ' . esc_html__( 'Configure authentication for the /metrics endpoint.', 'wp-prometheus' ) . '';
- }
+ /**
+ * Render auth section description.
+ *
+ * @return void
+ */
+ public function render_auth_section(): void {
+ echo '' . esc_html__( 'Configure authentication for the /metrics endpoint.', 'wp-prometheus' ) . '
';
+ }
- /**
- * Render metrics section description.
- *
- * @return void
- */
- public function render_metrics_section(): void {
- echo '' . esc_html__( 'Select which metrics to expose on the /metrics endpoint.', 'wp-prometheus' ) . '
';
- }
+ /**
+ * Render metrics section description.
+ *
+ * @return void
+ */
+ public function render_metrics_section(): void {
+ echo '' . esc_html__( 'Select which metrics to expose on the /metrics endpoint.', 'wp-prometheus' ) . '
';
+ }
- /**
- * Render auth token field.
- *
- * @return void
- */
- public function render_auth_token_field(): void {
- $token = get_option( 'wp_prometheus_auth_token', '' );
- ?>
-
-
-
-
-
-
+
+
+
+
+
+ __( 'WordPress Info (version, PHP version, multisite)', 'wp-prometheus' ),
- 'wordpress_users_total' => __( 'Total Users by Role', 'wp-prometheus' ),
- 'wordpress_posts_total' => __( 'Total Posts by Type and Status', 'wp-prometheus' ),
- 'wordpress_comments_total' => __( 'Total Comments by Status', 'wp-prometheus' ),
- 'wordpress_plugins_total' => __( 'Total Plugins (active/inactive)', 'wp-prometheus' ),
- 'wordpress_cron_events_total' => __( 'Cron Events (scheduled tasks, overdue, next run)', 'wp-prometheus' ),
- 'wordpress_transients_total' => __( 'Transients (total, expiring, expired)', 'wp-prometheus' ),
- );
+ $static_metrics = array(
+ 'wordpress_info' => __( 'WordPress Info (version, PHP version, multisite)', 'wp-prometheus' ),
+ 'wordpress_users_total' => __( 'Total Users by Role', 'wp-prometheus' ),
+ 'wordpress_posts_total' => __( 'Total Posts by Type and Status', 'wp-prometheus' ),
+ 'wordpress_comments_total' => __( 'Total Comments by Status', 'wp-prometheus' ),
+ 'wordpress_plugins_total' => __( 'Total Plugins (active/inactive)', 'wp-prometheus' ),
+ 'wordpress_cron_events_total' => __( 'Cron Events (scheduled tasks, overdue, next run)', 'wp-prometheus' ),
+ 'wordpress_transients_total' => __( 'Transients (total, expiring, expired)', 'wp-prometheus' ),
+ );
- $runtime_metrics = array(
- 'wordpress_http_requests_total' => __( 'HTTP Requests Total (by method, status, endpoint)', 'wp-prometheus' ),
- 'wordpress_http_request_duration_seconds' => __( 'HTTP Request Duration (histogram)', 'wp-prometheus' ),
- 'wordpress_db_queries_total' => __( 'Database Queries Total (by endpoint)', 'wp-prometheus' ),
- );
+ $runtime_metrics = array(
+ 'wordpress_http_requests_total' => __( 'HTTP Requests Total (by method, status, endpoint)', 'wp-prometheus' ),
+ 'wordpress_http_request_duration_seconds' => __( 'HTTP Request Duration (histogram)', 'wp-prometheus' ),
+ 'wordpress_db_queries_total' => __( 'Database Queries Total (by endpoint)', 'wp-prometheus' ),
+ );
- $woocommerce_metrics = array(
- 'wordpress_woocommerce_products_total' => __( 'WooCommerce Products (by status and type)', 'wp-prometheus' ),
- 'wordpress_woocommerce_orders_total' => __( 'WooCommerce Orders (by status)', 'wp-prometheus' ),
- 'wordpress_woocommerce_revenue_total' => __( 'WooCommerce Revenue (all time, today, month)', 'wp-prometheus' ),
- 'wordpress_woocommerce_customers_total' => __( 'WooCommerce Customers (registered, guest)', 'wp-prometheus' ),
- );
+ $woocommerce_metrics = array(
+ 'wordpress_woocommerce_products_total' => __( 'WooCommerce Products (by status and type)', 'wp-prometheus' ),
+ 'wordpress_woocommerce_orders_total' => __( 'WooCommerce Orders (by status)', 'wp-prometheus' ),
+ 'wordpress_woocommerce_revenue_total' => __( 'WooCommerce Revenue (all time, today, month)', 'wp-prometheus' ),
+ 'wordpress_woocommerce_customers_total' => __( 'WooCommerce Customers (registered, guest)', 'wp-prometheus' ),
+ );
- echo '