Hi Bill,


Patch 3: bytes sent metric

Here is it. There is still the open question about the right variable to use:

2. added a new metric to each transaction which allows to measure the amount of bytes sent during that transaction. I currently use the variable "bytes_sent" from the request_rec structure. I also tried "clength" but it seemed not to give as good results as "bytes sent". Maybe you guys can give me a hint which of them better suites my needs since I made my decision on "try and error" but was not sure what exactly each variable contains.

Any hints available? Thanks in advance
Greetings
Kai

diff -Naur -x .svn -x CVS mod_arm4_svn_20050825_changed2/mod_arm4.c 
mod_arm4_svn_20050825_changed3/mod_arm4.c
--- mod_arm4_svn_20050825_changed2/mod_arm4.c   2005-09-22 21:25:47.000000000 
+0200
+++ mod_arm4_svn_20050825_changed3/mod_arm4.c   2005-09-22 21:31:35.000000000 
+0200
@@ -312,13 +312,16 @@
     server_config_t                 *sconf;
 
     arm_buffer4_t                   api_buff4;    /*ARM buffer4*/
-    arm_subbuffer_t                 *subbuf;
+    arm_subbuffer_t                *app_subbuf[1];
+    arm_subbuffer_t                *tran_subbuf[2];
     arm_subbuffer_app_identity_t    *sb_appl_identity;
     arm_subbuffer_tran_identity_t   *sb_tran_identity;
+    arm_subbuffer_metric_bindings_t *sb_metric_binding;
 
     char *app_group;
     char *app_instance;
     
+    arm_metric_binding_t            metric_binding[1];
     arm_property_t appl_identity_properties[1];
 
     const arm_char_t *tran_context_names[] = {
@@ -366,9 +369,9 @@
     sb_appl_identity->context_name_count = 0;
     sb_appl_identity->context_name_array = NULL;
 
-    subbuf = (arm_subbuffer_t *) sb_appl_identity;
+    app_subbuf[0] = (arm_subbuffer_t *)sb_appl_identity;
     api_buff4.count = 1;
-    api_buff4.subbuffer_array = &subbuf;
+    api_buff4.subbuffer_array = &app_subbuf[0];
      
     arm_rc = ap_arm_register_application(sconf->app_name, ARM_ID_NONE, 
                                          ARM_FLAG_NONE, &api_buff4,
@@ -398,9 +401,34 @@
     sb_tran_identity->context_name_array = &tran_context_names[0];
     sb_tran_identity->uri = NULL;
 
-    subbuf = (arm_subbuffer_t *) sb_tran_identity;
-    api_buff4.count = 1;
-    api_buff4.subbuffer_array = &subbuf;
+    tran_subbuf[0] = (arm_subbuffer_t *)sb_tran_identity;
+    /*
+     * prepare metrics as well
+     */
+    metric_binding[0].slot = 0;
+    ap_arm_register_metric(&(sconf->app_id),
+                          "BytesSent", 
+                          ARM_METRIC_FORMAT_NUMERICID64, 
+                          ARM_METRIC_USE_TRAN_SIZE,
+                          "Bytes",
+                          ARM_ID_NONE,
+                          ARM_FLAG_NONE, 
+                          ARM_BUF4_NONE,
+                          &metric_binding[0].id);
+    /**
+     * organize buffers and subbuffers for metrics
+     */
+    sb_metric_binding = apr_pcalloc(p, sizeof(*sb_metric_binding));
+    
+    sb_metric_binding->header.format = ARM_SUBBUFFER_METRIC_BINDINGS;
+    sb_metric_binding->count = 1;
+    sb_metric_binding->metric_binding_array = &metric_binding[0];
+
+    tran_subbuf[1] = (arm_subbuffer_t *)sb_metric_binding;
+
+    /* prepare buf4*/ 
+    api_buff4.count = 2;
+    api_buff4.subbuffer_array = &tran_subbuf[0];
 
     arm_rc = ap_arm_register_transaction(&(sconf->app_id),
                                          sconf->tran_name,
@@ -492,6 +520,11 @@
     arm_tran_status_t tran_status;
     request_config_t *rconf;
 
+    arm_metric_t metrics[1];
+    arm_buffer4_t cvbuf;  
+    arm_subbuffer_t *subbuf[1];
+    arm_subbuffer_metric_values_t *sb_metric_values;    
+
 #if 0
     /* This check was needed when this code was called during the
      * logging phase. Leave in for documentation.
@@ -512,11 +545,30 @@
     else {
         tran_status = ARM_STATUS_GOOD;      /* No Error */
     }
+    /*
+     * initialize the arm_subbuffer_metric_values_t
+     */
+    metrics[0].slot   = 0;
+    metrics[0].format = ARM_METRIC_FORMAT_NUMERICID64;
+    metrics[0].usage  = ARM_METRIC_USE_TRAN_SIZE;
+    metrics[0].valid  = 1;
+    metrics[0].metric_u.numericid64 = r->bytes_sent;
+
+    sb_metric_values = apr_pcalloc(r->pool, sizeof(*sb_metric_values));
+    sb_metric_values->header.format = ARM_SUBBUFFER_METRIC_VALUES;
+    sb_metric_values->count = 1;
+    sb_metric_values->metric_value_array = &metrics[0];
+    subbuf[0] = (arm_subbuffer_t *) sb_metric_values;
 
+    cvbuf.count = 1;
+    cvbuf.subbuffer_array = &subbuf[0];
+   /*
+    * stop the transaction
+    */
     arm_rc = ap_arm_stop_transaction(rconf->tran_handle,
                                      tran_status,
                                      0,
-                                     NULL);
+                                     &cvbuf);
 
     if (arm_rc < 0) {
         ap_log_rerror(APLOG_MARK, APLOG_WARNING, 0, r, 

Reply via email to