Commit d52d8e53 authored by Naman Dixit's avatar Naman Dixit

Docker instrumentation finished in grunt

parent d554a5dd
...@@ -338,9 +338,9 @@ int main(int argc, char** argv) ...@@ -338,9 +338,9 @@ int main(int argc, char** argv)
JSON_Print_Command command = {0}; JSON_Print_Command command = {0};
while (instrumentCommandDequeue(&command)) { while (instrumentCommandDequeue(&command)) {
// TODO(naman): Enable this after proper testing // TODO(naman): Enable this after proper testing
/* if (!kafkaWrite(kafka.writer, command.topic, "resource_daemon", command.msg)) { */ if (!kafkaWrite(kafka.writer, command.topic, "resource_daemon", command.msg)) {
/* return -1; */ return -1;
/* } */ }
} }
} }
......
...@@ -12,7 +12,7 @@ void* dockerProcessLoop (void *arg) ...@@ -12,7 +12,7 @@ void* dockerProcessLoop (void *arg)
while (true) { while (true) {
// TODO(naman): Get data // TODO(naman): Get data
Char *data_cmd = NULL; Char *data_cmd = NULL;
sbufPrint(data_cmd, "docker stats %s", (Char*)arg); sbufPrint(data_cmd, "docker stats --no-stream --format \"{{ json . }}\" %s", (Char*)arg);
FILE* data_file = popen(data_cmd, "r"); FILE* data_file = popen(data_cmd, "r");
fseek(data_file, 0, SEEK_END); fseek(data_file, 0, SEEK_END);
...@@ -22,17 +22,49 @@ void* dockerProcessLoop (void *arg) ...@@ -22,17 +22,49 @@ void* dockerProcessLoop (void *arg)
fread(data, 1, (Size)size + 1, data_file); fread(data, 1, (Size)size + 1, data_file);
fclose(data_file); fclose(data_file);
const Char *json_error = NULL;
cJSON *data_json = cJSON_ParseWithOpts(data, &json_error, true);
Char *json = NULL; Char *json = NULL;
sbufPrint(json, "{\"cpu_percentage\": %f",
atof(cJSON_GetObjectItem(data_json, "CPUPerc")->valuestring));
sbufPrint(json, ",\n\"memory_percentage\": %f",
atof(cJSON_GetObjectItem(data_json, "MemPerc")->valuestring));
sbufPrint(json, ",\n\"memory_used\": %f",
atof(cJSON_GetObjectItem(data_json, "MemUsage")->valuestring));
sbufPrint(json, ",\n\"memory_limit\": %f",
atof(strchr(cJSON_GetObjectItem(data_json, "MemUsage")->valuestring, '/') + 1));
sbufPrint(json, ",\n\"block_input\": %f",
atof(cJSON_GetObjectItem(data_json, "BlockIO")->valuestring));
sbufPrint(json, ",\n\"block_output\": %f",
atof(strchr(cJSON_GetObjectItem(data_json, "BlockIO")->valuestring, '/') + 1));
sbufPrint(json, ",\n\"net_down\": %f",
atof(cJSON_GetObjectItem(data_json, "NetIO")->valuestring));
sbufPrint(json, ",\n\"net_up\": %f",
atof(strchr(cJSON_GetObjectItem(data_json, "NetIO")->valuestring, '/') + 1));
sbufPrint(json, "\n}\n");
cJSON *json_parse = cJSON_Parse(json);
Char *json_pretty = cJSON_Print(json_parse);
Char *output = NULL; Char *output = NULL;
sbufPrint(output, "{\"node_id\": \"%s\"", node_name); sbufPrint(output, "{\"node_id\": \"%s\"", node_name);
sbufPrint(output, ",\n\"type\": \"%s\"", "docker"); sbufPrint(output, ",\n\"entity_id\": \"%s\"", (Char*)arg);
sbufPrint(output, ",\n\"data\": %s", json ? json : "{}"); sbufPrint(output, ",\n\"type\": \"%s\"", "instrumentation");
sbufPrint(output, ",\n\"backend\": \"%s\"", "docker");
sbufPrint(output, ",\n\"data\": %s", json_pretty);
sbufPrint(output, "\n}\n"); sbufPrint(output, "\n}\n");
JSON_Print_Command jpc = {.msg = output, JSON_Print_Command jpc = {.msg = output,
.topic = "LOG_CHANNEL"}; .topic = "LOG_CHANNEL"};
cJSON_free(json_pretty);
cJSON_Delete(json_parse);
sbufDelete(output);
sbufDelete(json);
free(data);
sbufDelete(data_cmd);
U64 time_before = timeMilli(); U64 time_before = timeMilli();
instrumentCommandEnqueue(jpc); instrumentCommandEnqueue(jpc);
U64 time_after = timeMilli(); U64 time_after = timeMilli();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment