jhg03a commented on a change in pull request #4713:
URL: https://github.com/apache/trafficcontrol/pull/4713#discussion_r430496218



##########
File path: traffic_server/plugins/astats_over_http/astats_over_http.c
##########
@@ -326,7 +383,40 @@ static void appendSystemState(stats_state *my_state) {
                end = strstr(str, "\n");
                if (end)
                        *end = 0;
-               APPEND_STAT("proc.loadavg", "\"%s\"", str);
+               APPEND_STAT_JSON("proc.loadavg", "\"%s\"", str);
+       }
+}
+
+static void appendSystemStateCsv(stats_state *my_state) {
+       char *interface = my_state->interfaceName;
+       char buffer[16384];
+       char *str;
+       char *end;
+       int speed = 0;
+
+       APPEND_STAT_CSV("inf.name", "%s", interface);
+
+       speed = getSpeed(interface, buffer, sizeof(buffer));
+
+       APPEND_STAT_CSV("inf.speed", "%d", speed);
+
+       str = getFile("/proc/net/dev", buffer, sizeof(buffer));
+       if (str && interface) {
+               str = strstr(str, interface);
+               if (str) {
+                       end = strstr(str, "\n");
+                       if (end)
+                               *end = 0;
+                       APPEND_STAT_CSV("proc.net.dev", "%s", str);
+               }
+       }
+
+       str = getFile("/proc/loadavg", buffer, sizeof(buffer));
+       if (str) {
+               end = strstr(str, "\n");
+               if (end)
+                       *end = 0;
+               APPEND_STAT_CSV("proc.loadavg", "%s", str);

Review comment:
       This looks like a lot of copypasta just to change the output functions.  
Not a huge issue though.

##########
File path: traffic_server/plugins/astats_over_http/astats_over_http.c
##########
@@ -193,14 +199,25 @@ stats_add_data_to_resp_buffer(const char *s, stats_state 
*my_state) {
        return s_len;
 }
 
-static const char RESP_HEADER[] = "HTTP/1.0 200 Ok\r\nContent-Type: 
text/javascript\r\nCache-Control: no-cache\r\n\r\n";
+static const char RESP_HEADER_JSON[] = "HTTP/1.0 200 Ok\r\nContent-Type: 
text/json\r\nCache-Control: no-cache\r\n\r\n";
+static const char RESP_HEADER_CSV[] = "HTTP/1.0 200 Ok\r\nContent-Type: 
text/csv\r\nCache-Control: no-cache\r\n\r\n";
 
 static void
 stats_process_read(TSCont contp, TSEvent event, stats_state *my_state) {
        TSDebug(PLUGIN_TAG, "stats_process_read(%d)", event);
 
        if (event == TS_EVENT_VCONN_READ_READY) {
-               my_state->output_bytes = 
stats_add_data_to_resp_buffer(RESP_HEADER, my_state);
+               switch (my_state->output) {
+                       case JSON_OUTPUT:
+                               my_state->output_bytes = 
stats_add_data_to_resp_buffer(RESP_HEADER_JSON, my_state);
+                               break;
+                       case CSV_OUTPUT:
+                               my_state->output_bytes = 
stats_add_data_to_resp_buffer(RESP_HEADER_CSV, my_state);
+                               break;
+                       default:
+                               TSError("stats_process_read: Unknown output 
format\n");
+                               break;

Review comment:
       This might be an issue since it's a change to the default behavior.  
Just in case we've got malformed client requests and havn't noticed since it 
just worked.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to