Changeset 2000813
- Timestamp:
- 12/24/2018 05:22:54 AM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
woo-prometheus-metrics/trunk/woo-prometheus-metrics.php
r1961997 r2000813 5 5 Plugin URI: https://wordpress.org/plugins/woo-prometheus-metrics 6 6 Description: Plugin to monitor the count of products and orders on a Woocommerce site. 7 Version: 0.0. 27 Version: 0.0.3 8 8 Author: Ross Golder <ross@golder.org> 9 9 Author URI: http://www.golder.org/ … … 41 41 } 42 42 43 function woocommerce_metrics_output_order_metrics($id, $desc, $type, $values) { 44 echo "# HELP ".$id." ".$desc."\n"; 45 echo "# TYPE ".$id." ".$type."\n"; 46 foreach($values as $status => $value) { 47 echo $id."{status=\"".$status."\"} ".$value."\n"; 48 } 49 echo "\n"; 50 } 51 43 52 function woocommerce_metrics_handler__handle_request($wp_query) { 44 53 global $uris_to_check; … … 50 59 $password = $_SERVER['PHP_AUTH_PW']; 51 60 if($auth_username != $username || $auth_password != $password) { 61 header("HTTP/1.1 401 Unauthorized"); 52 62 header('WWW-Authenticate: Basic realm="Woocommerce Metrics"'); 53 header("HTTP/1.1 401 Unauthorized");54 63 echo "Authorisation required."; 55 64 exit(0); … … 64 73 } 65 74 66 // Gather count of orders 67 $order_count = wc_orders_count("processed"); 75 // Gather count of orders by status 76 $order_statuses = array_keys(wc_get_order_statuses()); 77 $order_counts = array(); 78 foreach($order_statuses as $order_status) { 79 $order_counts[$order_status] = wc_orders_count($order_status); 80 } 68 81 69 82 // Gather count of users … … 77 90 78 91 header("Content-Type: text/plain"); 92 header('Cache-Control: no-cache'); 93 79 94 80 95 woocommerce_metrics_output_metric("woocommerce_product_count", … … 84 99 ); 85 100 86 woocommerce_metrics_output_ metric("woocommerce_order_count",87 "The number of orders .",101 woocommerce_metrics_output_order_metrics("woocommerce_order_count", 102 "The number of orders, by status.", 88 103 "gauge", 89 $order_count 104 $order_counts 90 105 ); 91 106
Note: See TracChangeset
for help on using the changeset viewer.