apps.plugin function add max value on all value columns (#13899)
* apps.plugin function add max value on all value columns * prevent warning of uninitialized variables
Costa Tsaousis committed
Oct 29, 2022 at 22:38 UTC
f9ea1f28b2cf6a3920c791365039e76f8ccbf9d0
1 file changed
+312
-257
collectors/apps.plugin/apps_plugin.c
+312
-257
@@ -4272,28 +4272,40 @@ static void apps_plugin_function_processes_help(const char *transaction) {
4272
}
4273
4274
#define add_table_field(wb, key, name, visible, type, units, max, sort, sortable, sticky, unique_key, pointer_to, summary) do { \
4275
- if(fields_added) buffer_strcat(wb, ","); \
4276
- buffer_sprintf(wb, "\n \"%s\": {", key); \
4277
- buffer_sprintf(wb, "\n \"index\":%d,", fields_added); \
4278
- buffer_sprintf(wb, "\n \"unique_key\":%s,", (unique_key)?"true":"false"); \
4279
- buffer_sprintf(wb, "\n \"name\":\"%s\",", name); \
4280
- buffer_sprintf(wb, "\n \"visible\":%s,", (visible)?"true":"false"); \
4281
- buffer_sprintf(wb, "\n \"type\":\"%s\",", type); \
4282
- if(units) \
4283
- buffer_sprintf(wb, "\n \"units\":\"%s\",", (char*)(units)); \
4284
- if(netdata_double_isnumber(max)) \
4285
- buffer_sprintf(wb, "\n \"max\":%f,", (NETDATA_DOUBLE)(max)); \
4286
- if(pointer_to) \
4287
- buffer_sprintf(wb, "\n \"pointer_to\":\"%s\",", (char *)(pointer_to)); \
4288
- buffer_sprintf(wb, "\n \"sort\":\"%s\",", sort); \
4289
- buffer_sprintf(wb, "\n \"sortable\":%s,", (sortable)?"true":"false"); \
4290
- buffer_sprintf(wb, "\n \"sticky\":%s,", (sticky)?"true":"false"); \
4291
- buffer_sprintf(wb, "\n \"summary\":\"%s\"", summary); \
4292
- buffer_sprintf(wb, "\n }"); \
4293
- fields_added++; \
4294
- } while(0)
4295
-
4296
-static BUFFER *func_processes_fields = NULL;
4275
+ if(fields_added) buffer_strcat(wb, ","); \
4276
+ buffer_sprintf(wb, "\n \"%s\": {", key); \
4277
+ buffer_sprintf(wb, "\n \"index\":%d,", fields_added); \
4278
+ buffer_sprintf(wb, "\n \"unique_key\":%s,", (unique_key)?"true":"false"); \
4279
+ buffer_sprintf(wb, "\n \"name\":\"%s\",", name); \
4280
+ buffer_sprintf(wb, "\n \"visible\":%s,", (visible)?"true":"false"); \
4281
+ buffer_sprintf(wb, "\n \"type\":\"%s\",", type); \
4282
+ if(units) \
4283
+ buffer_sprintf(wb, "\n \"units\":\"%s\",", (char*)(units)); \
4284
+ if(!isnan((NETDATA_DOUBLE)(max))) \
4285
+ buffer_sprintf(wb, "\n \"max\":%f,", (NETDATA_DOUBLE)(max)); \
4286
+ if(pointer_to) \
4287
+ buffer_sprintf(wb, "\n \"pointer_to\":\"%s\",", (char *)(pointer_to)); \
4288
+ buffer_sprintf(wb, "\n \"sort\":\"%s\",", sort); \
4289
+ buffer_sprintf(wb, "\n \"sortable\":%s,", (sortable)?"true":"false"); \
4290
+ buffer_sprintf(wb, "\n \"sticky\":%s,", (sticky)?"true":"false"); \
4291
+ buffer_sprintf(wb, "\n \"summary\":\"%s\"", summary); \
4292
+ buffer_sprintf(wb, "\n }"); \
4293
+ fields_added++; \
4294
+} while(0)
4295
+
4296
+#define add_value_field_llu_with_max(wb, key, value) do { \
4297
+ unsigned long long _tmp = (value); \
4298
+ key ## _max = (rows == 0) ? (_tmp) : MAX(key ## _max, _tmp); \
4299
+ buffer_fast_strcat(wb, ",", 1); \
4300
+ buffer_print_llu(wb, _tmp); \
4301
+} while(0)
4302
+
4303
+#define add_value_field_ndd_with_max(wb, key, value) do { \
4304
+ NETDATA_DOUBLE _tmp = (value); \
4305
+ key ## _max = (rows == 0) ? (_tmp) : MAX(key ## _max, _tmp); \
4306
+ buffer_fast_strcat(wb, ",", 1); \
4307
+ buffer_rrd_value(wb, _tmp); \
4308
+} while(0)
4309
4310
static void apps_plugin_function_processes(const char *transaction, char *function __maybe_unused, char *line_buffer __maybe_unused, int line_max __maybe_unused, int timeout __maybe_unused) {
4311
struct pid_stat *p;
@@ -4363,204 +4375,69 @@ static void apps_plugin_function_processes(const char *transaction, char *functi
4375
time_t expires = now_realtime_sec() + update_every;
4376
pluginsd_function_result_begin_to_stdout(transaction, HTTP_RESP_OK, "application/json", expires);
4377
4366
- if(unlikely(!func_processes_fields)) {
4367
- func_processes_fields = buffer_create(1000);
4368
-
4369
- int fields_added = 0;
4370
-
4371
- buffer_sprintf(func_processes_fields,
4372
- "{"
4373
- "\n \"status\":%d"
4374
- ",\n \"type\":\"table\""
4375
- ",\n \"update_every\":%d"
4376
- ",\n \"columns\": {"
4377
- , HTTP_RESP_OK
4378
- , update_every
4379
- );
4380
-
4381
- // IMPORTANT!
4382
- // THE ORDER SHOULD BE THE SAME WITH THE VALUES!
4383
-
4384
- add_table_field(func_processes_fields, "Pid", "Process ID", true, "integer", NULL, NAN, "ascending", true, true, true, NULL, "count_unique");
4385
- add_table_field(func_processes_fields, "Cmd", "Process Name", true, "string", NULL, NAN, "ascending", true, true, false, NULL, "count_unique");
4386
-
4387
-#ifdef NETDATA_DEV_MODE
4388
- add_table_field(func_processes_fields, "CmdLine", "Command Line", false, "detail-string:Cmd", NULL, NAN, "ascending", true, true, false, NULL, "count_unique");
4389
-#endif
4390
- add_table_field(func_processes_fields, "PPid", "Parent Process ID", false, "integer", NULL, NAN, "ascending", true, true, false, "Pid", "count_unique");
4391
- add_table_field(func_processes_fields, "Category", "Category (apps_groups.conf)", true, "string", NULL, NAN, "ascending", true, true, false, NULL, "count_unique");
4392
- add_table_field(func_processes_fields, "User", "User Owner", true, "string", NULL, NAN, "ascending", true, true, false, NULL, "count_unique");
4393
- add_table_field(func_processes_fields, "Uid", "User ID", false, "integer", NULL, NAN, "ascending", true, true, false, NULL, "count_unique");
4394
- add_table_field(func_processes_fields, "Group", "Group Owner", false, "string", NULL, NAN, "ascending", true, true, false, NULL, "count_unique");
4395
- add_table_field(func_processes_fields, "Gid", "Group ID", false, "integer", NULL, NAN, "ascending", true, true, false, NULL, "count_unique");
4396
- add_table_field(func_processes_fields, "Processes", "Processes", true, "bar-with-integer", "processes", NAN, "descending", true, false, false, NULL, "sum");
4397
- add_table_field(func_processes_fields, "Threads", "Threads", true, "bar-with-integer", "threads", NAN, "descending", true, false, false, NULL, "sum");
4398
- add_table_field(func_processes_fields, "Uptime", "Uptime in seconds", true, "duration", "seconds", NAN, "descending", true, false, false, NULL, "max");
4399
-
4400
- // minor page faults
4401
- add_table_field(func_processes_fields, "MinFlt", "Minor Page Faults/s", false, "bar", "pgflts/s", NAN, "descending", true, false, false, NULL, "sum");
4402
- add_table_field(func_processes_fields, "CMinFlt", "Children Minor Page Faults/s", false, "bar", "pgflts/s", NAN, "descending", true, false, false, NULL, "sum");
4403
- add_table_field(func_processes_fields, "TMinFlt", "Total Minor Page Faults/s", false, "bar", "pgflts/s", NAN, "descending", true, false, false, NULL, "sum");
4404
-
4405
- // major page faults
4406
- add_table_field(func_processes_fields, "MajFlt", "Major Page Faults/s", false, "bar", "pgflts/s", NAN, "descending", true, false, false, NULL, "sum");
4407
- add_table_field(func_processes_fields, "CMajFlt", "Children Major Page Faults/s", false, "bar", "pgflts/s", NAN, "descending", true, false, false, NULL, "sum");
4408
- add_table_field(func_processes_fields, "TMajFlt", "Total Major Page Faults/s", true, "bar", "pgflts/s", NAN, "descending", true, false, false, NULL, "sum");
4409
-
4410
- // CPU utilization
4411
- add_table_field(func_processes_fields, "UserCPU", "User CPU time", false, "bar", "%", NAN, "descending", true, false, false, NULL, "sum");
4412
- add_table_field(func_processes_fields, "SysCPU", "System CPU Time", false, "bar", "%", NAN, "descending", true, false, false, NULL, "sum");
4413
- add_table_field(func_processes_fields, "GuestCPU", "Guest CPU Time", false, "bar", "%", NAN, "descending", true, false, false, NULL, "sum");
4414
- add_table_field(func_processes_fields, "CUserCPU", "Children User CPU Time", false, "bar", "%", NAN, "descending", true, false, false, NULL, "sum");
4415
- add_table_field(func_processes_fields, "CSysCPU", "Children System CPU Time", false, "bar", "%", NAN, "descending", true, false, false, NULL, "sum");
4416
- add_table_field(func_processes_fields, "CGuestCPU", "Children Guest CPU Time", false, "bar", "%", NAN, "descending", true, false, false, NULL, "sum");
4417
- add_table_field(func_processes_fields, "CPU", "Total CPU Time", true, "bar", "%", NAN, "descending", true, false, false, NULL, "sum");
4418
-
4419
- // memory
4420
- add_table_field(func_processes_fields, "VMSize", "Virtual Memory Size", false, "bar", "MiB", NAN, "descending", true, false, false, NULL, "sum");
4421
- add_table_field(func_processes_fields, "RSS", "Resident Set Size", MemTotal?false:true, "bar", "MiB", NAN, "descending", true, false, false, NULL, "sum");
4422
- add_table_field(func_processes_fields, "Shared", "Shared Pages", false, "bar", "MiB", NAN, "descending", true, false, false, NULL, "sum");
4423
- add_table_field(func_processes_fields, "Swap", "Swap Memory", false, "bar", "MiB", NAN, "descending", true, false, false, NULL, "sum");
4424
-
4425
- if(MemTotal)
4426
- add_table_field(func_processes_fields, "MemPcnt", "Memory Percentage", true, "bar", "%", 100.0, "descending", true, false, false, NULL, "sum");
4427
-
4428
- // Logical I/O
4429
-#ifndef __FreeBSD__
4430
- add_table_field(func_processes_fields, "LReads", "Logical I/O Reads", false, "bar", "KiB/s", NAN, "descending", true, false, false, NULL, "sum");
4431
- add_table_field(func_processes_fields, "LWrites", "Logical I/O Writes", false, "bar", "KiB/s", NAN, "descending", true, false, false, NULL, "sum");
4432
-#endif
4433
-
4434
- // Physical I/O
4435
- add_table_field(func_processes_fields, "PReads", "Physical I/O Reads", true, "bar", "KiB/s", NAN, "descending", true, false, false, NULL, "sum");
4436
- add_table_field(func_processes_fields, "PWrites", "Physical I/O Writes", true, "bar", "KiB/s", NAN, "descending", true, false, false, NULL, "sum");
4437
-
4438
- // I/O calls
4439
- add_table_field(func_processes_fields, "RCalls", "I/O Read Calls", false, "bar", "calls/s", NAN, "descending", true, false, false, NULL, "sum");
4440
- add_table_field(func_processes_fields, "WCalls", "I/O Write Calls", false, "bar", "calls/s", NAN, "descending", true, false, false, NULL, "sum");
4441
-
4442
- // open file descriptors
4443
- add_table_field(func_processes_fields, "Files", "Open Files", false, "bar", "fds", NAN, "descending", true, false, false, NULL, "sum");
4444
- add_table_field(func_processes_fields, "Pipes", "Open Pipes", false, "bar", "fds", NAN, "descending", true, false, false, NULL, "sum");
4445
- add_table_field(func_processes_fields, "Sockets", "Open Sockets", false, "bar", "fds", NAN, "descending", true, false, false, NULL, "sum");
4446
- add_table_field(func_processes_fields, "iNotiFDs", "Open iNotify Descriptors", false, "bar", "fds", NAN, "descending", true, false, false, NULL, "sum");
4447
- add_table_field(func_processes_fields, "EventFDs", "Open Event Descriptors", false, "bar", "fds", NAN, "descending", true, false, false, NULL, "sum");
4448
- add_table_field(func_processes_fields, "TimerFDs", "Open Timer Descriptors", false, "bar", "fds", NAN, "descending", true, false, false, NULL, "sum");
4449
- add_table_field(func_processes_fields, "SigFDs", "Open Signal Descriptors", false, "bar", "fds", NAN, "descending", true, false, false, NULL, "sum");
4450
- add_table_field(func_processes_fields, "EvPollFDs", "Open Event Poll Descriptors", false, "bar", "fds", NAN, "descending", true, false, false, NULL, "sum");
4451
- add_table_field(func_processes_fields, "OtherFDs", "Other Open Descriptors", false, "bar", "fds", NAN, "descending", true, false, false, NULL, "sum");
4452
- add_table_field(func_processes_fields, "FDs", "All Open File Descriptors", true, "bar", "fds", NAN, "descending", true, false, false, NULL, "sum");
4453
-
4454
- buffer_strcat(
4455
- func_processes_fields,
4456
- ""
4457
- "\n },"
4458
- "\n \"default sort column\": \"CPU\","
4459
- "\n \"charts\": {"
4460
- "\n \"CPU\": {"
4461
- "\n \"name\":\"CPU Utilization\","
4462
- "\n \"type\":\"stacked-bar\","
4463
- "\n \"columns\": [ \"UserCPU\", \"SysCPU\", \"GuestCPU\", \"CUserCPU\", \"CSysCPU\", \"CGuestCPU\" ]"
4464
- "\n },"
4465
- "\n \"Memory\": {"
4466
- "\n \"name\":\"Memory\","
4467
- "\n \"type\":\"stacked-bar\","
4468
- "\n \"columns\": [ \"VMSize\", \"RSS\", \"Shared\", \"Swap\" ]"
4469
- "\n },"
4470
- );
4471
-
4472
- if(MemTotal)
4473
- buffer_strcat(
4474
- func_processes_fields,
4475
- ""
4476
- "\n \"MemoryPercent\": {"
4477
- "\n \"name\":\"Memory Percentage\","
4478
- "\n \"type\":\"stacked-bar\","
4479
- "\n \"columns\": [ \"MemPcnt\" ]"
4480
- "\n },"
4481
- );
4482
-
4483
- buffer_strcat(
4484
- func_processes_fields, ""
4485
-#ifndef __FreeBSD__
4486
- "\n \"Reads\": {"
4487
- "\n \"name\":\"I/O Reads\","
4488
- "\n \"type\":\"stacked-bar\","
4489
- "\n \"columns\": [ \"LReads\", \"PReads\" ]"
4490
- "\n },"
4491
- "\n \"Writes\": {"
4492
- "\n \"name\":\"I/O Writes\","
4493
- "\n \"type\":\"stacked-bar\","
4494
- "\n \"columns\": [ \"LWrites\", \"PWrites\" ]"
4495
- "\n },"
4496
- "\n \"LogicalIO\": {"
4497
- "\n \"name\":\"Logical I/O\","
4498
- "\n \"type\":\"stacked-bar\","
4499
- "\n \"columns\": [ \"LReads\", \"LWrites\" ]"
4500
- "\n },"
4501
-#endif
4502
- "\n \"PhysicalIO\": {"
4503
- "\n \"name\":\"Physical I/O\","
4504
- "\n \"type\":\"stacked-bar\","
4505
- "\n \"columns\": [ \"PReads\", \"PWrites\" ]"
4506
- "\n },"
4507
- "\n \"IOCalls\": {"
4508
- "\n \"name\":\"I/O Calls\","
4509
- "\n \"type\":\"stacked-bar\","
4510
- "\n \"columns\": [ \"RCalls\", \"WCalls\" ]"
4511
- "\n },"
4512
- "\n \"MinFlt\": {"
4513
- "\n \"name\":\"Minor Page Faults\","
4514
- "\n \"type\":\"stacked-bar\","
4515
- "\n \"columns\": [ \"MinFlt\", \"CMinFlt\" ]"
4516
- "\n },"
4517
- "\n \"MajFlt\": {"
4518
- "\n \"name\":\"Major Page Faults\","
4519
- "\n \"type\":\"stacked-bar\","
4520
- "\n \"columns\": [ \"MajFlt\", \"CMajFlt\" ]"
4521
- "\n },"
4522
- "\n \"Threads\": {"
4523
- "\n \"name\":\"Threads\","
4524
- "\n \"type\":\"stacked-bar\","
4525
- "\n \"columns\": [ \"Threads\" ]"
4526
- "\n },"
4527
- "\n \"Processes\": {"
4528
- "\n \"name\":\"Processes\","
4529
- "\n \"type\":\"stacked-bar\","
4530
- "\n \"columns\": [ \"Processes\" ]"
4531
- "\n },"
4532
- "\n \"FDs\": {"
4533
- "\n \"name\":\"File Descriptors\","
4534
- "\n \"type\":\"stacked-bar\","
4535
- "\n \"columns\": [ \"Files\", \"Pipes\", \"Sockets\", \"iNotiFDs\", \"EventFDs\", \"TimerFDs\", \"SigFDs\", \"EvPollFDs\", \"OtherFDs\" ]"
4536
- "\n }"
4537
- "\n },"
4538
- "\n \"group_by\": {"
4539
- "\n \"Process Tree by PID\": {"
4540
- "\n \"columns\": [ \"PPid\" ]"
4541
- "\n },"
4542
- "\n \"Process Tree by Category\": {"
4543
- "\n \"columns\": [ \"Category\", \"PPid\" ]"
4544
- "\n },"
4545
- "\n \"Process Tree by User\": {"
4546
- "\n \"columns\": [ \"User\", \"PPid\" ]"
4547
- "\n },"
4548
- "\n \"Process Tree by Group\": {"
4549
- "\n \"columns\": [ \"Group\", \"PPid\" ]"
4550
- "\n }"
4551
- "\n },"
4552
- "\n \"data\":["
4553
- "\n"
4554
- );
4555
- }
4556
-
4557
- fwrite(buffer_tostring(func_processes_fields), buffer_strlen(func_processes_fields), 1, stdout);
4558
-
4378
unsigned int cpu_divisor = time_factor * RATES_DETAIL / 100;
4379
unsigned int memory_divisor = 1024;
4380
unsigned int io_divisor = 1024 * RATES_DETAIL;
4381
4382
BUFFER *wb = buffer_create(PLUGINSD_LINE_MAX);
4383
+ buffer_sprintf(wb,
4384
+ "{"
4385
+ "\n \"status\":%d"
4386
+ ",\n \"type\":\"table\""
4387
+ ",\n \"update_every\":%d"
4388
+ ",\n \"data\":["
4389
+ "\n"
4390
+ , HTTP_RESP_OK
4391
+ , update_every
4392
+ );
4393
+
4394
+ NETDATA_DOUBLE
4395
+ UserCPU_max = 0.0
4396
+ , SysCPU_max = 0.0
4397
+ , GuestCPU_max = 0.0
4398
+ , CUserCPU_max = 0.0
4399
+ , CSysCPU_max = 0.0
4400
+ , CGuestCPU_max = 0.0
4401
+ , CPU_max = 0.0
4402
+ , VMSize_max = 0.0
4403
+ , RSS_max = 0.0
4404
+ , Shared_max = 0.0
4405
+ , Swap_max = 0.0
4406
+ , MemPcnt_max = 0.0
4407
+ ;
4408
+
4409
+ unsigned long long
4410
+ Processes_max = 0
4411
+ , Threads_max = 0
4412
+ , Uptime_max = 0
4413
+ , MinFlt_max = 0
4414
+ , CMinFlt_max = 0
4415
+ , TMinFlt_max = 0
4416
+ , MajFlt_max = 0
4417
+ , CMajFlt_max = 0
4418
+ , TMajFlt_max = 0
4419
+ , PReads_max = 0
4420
+ , PWrites_max = 0
4421
+ , RCalls_max = 0
4422
+ , WCalls_max = 0
4423
+ , Files_max = 0
4424
+ , Pipes_max = 0
4425
+ , Sockets_max = 0
4426
+ , iNotiFDs_max = 0
4427
+ , EventFDs_max = 0
4428
+ , TimerFDs_max = 0
4429
+ , SigFDs_max = 0
4430
+ , EvPollFDs_max = 0
4431
+ , OtherFDs_max = 0
4432
+ , FDs_max = 0
4433
+ ;
4434
+
4435
+#ifndef __FreeBSD__
4436
+ unsigned long long
4437
+ LReads_max = 0
4438
+ , LWrites_max = 0
4439
+ ;
4440
+#endif
4441
4442
int rows= 0;
4443
for(p = root_of_pids; p ; p = p->next) {
@@ -4636,69 +4513,67 @@ static void apps_plugin_function_processes(const char *transaction, char *functi
4513
buffer_fast_strcat(wb, ",", 1); buffer_print_llu(wb, p->gid);
4514
4515
// procs
4639
- buffer_fast_strcat(wb, ",", 1); buffer_print_llu(wb, p->children_count);
4516
+ add_value_field_llu_with_max(wb, Processes, p->children_count);
4517
4518
// threads
4642
- buffer_fast_strcat(wb, ",", 1); buffer_print_llu(wb, p->num_threads);
4519
+ add_value_field_llu_with_max(wb, Threads, p->num_threads);
4520
4521
// uptime
4645
- buffer_fast_strcat(wb, ",", 1); buffer_print_llu(wb, p->uptime);
4522
+ add_value_field_llu_with_max(wb, Uptime, p->uptime);
4523
4524
// minor page faults
4648
- buffer_fast_strcat(wb, ",", 1); buffer_print_llu(wb, p->minflt / RATES_DETAIL);
4649
- buffer_fast_strcat(wb, ",", 1); buffer_print_llu(wb, p->cminflt / RATES_DETAIL);
4650
- buffer_fast_strcat(wb, ",", 1); buffer_print_llu(wb, (p->minflt + p->cminflt) / RATES_DETAIL);
4525
+ add_value_field_llu_with_max(wb, MinFlt, p->minflt / RATES_DETAIL);
4526
+ add_value_field_llu_with_max(wb, CMinFlt, p->cminflt / RATES_DETAIL);
4527
+ add_value_field_llu_with_max(wb, TMinFlt, (p->minflt + p->cminflt) / RATES_DETAIL);
4528
4529
// major page faults
4653
- buffer_fast_strcat(wb, ",", 1); buffer_print_llu(wb, p->majflt / RATES_DETAIL);
4654
- buffer_fast_strcat(wb, ",", 1); buffer_print_llu(wb, p->cmajflt / RATES_DETAIL);
4655
- buffer_fast_strcat(wb, ",", 1); buffer_print_llu(wb, (p->majflt + p->cmajflt) / RATES_DETAIL);
4530
+ add_value_field_llu_with_max(wb, MajFlt, p->majflt / RATES_DETAIL);
4531
+ add_value_field_llu_with_max(wb, CMajFlt, p->cmajflt / RATES_DETAIL);
4532
+ add_value_field_llu_with_max(wb, TMajFlt, (p->majflt + p->cmajflt) / RATES_DETAIL);
4533
4534
// CPU utilization %
4658
- buffer_fast_strcat(wb, ",", 1); buffer_rrd_value(wb, (NETDATA_DOUBLE)(p->utime) / cpu_divisor);
4659
- buffer_fast_strcat(wb, ",", 1); buffer_rrd_value(wb, (NETDATA_DOUBLE)(p->stime) / cpu_divisor);
4660
- buffer_fast_strcat(wb, ",", 1); buffer_rrd_value(wb, (NETDATA_DOUBLE)(p->gtime) / cpu_divisor);
4661
- buffer_fast_strcat(wb, ",", 1); buffer_rrd_value(wb, (NETDATA_DOUBLE)(p->cutime) / cpu_divisor);
4662
- buffer_fast_strcat(wb, ",", 1); buffer_rrd_value(wb, (NETDATA_DOUBLE)(p->cstime) / cpu_divisor);
4663
- buffer_fast_strcat(wb, ",", 1); buffer_rrd_value(wb, (NETDATA_DOUBLE)(p->cgtime) / cpu_divisor);
4664
- buffer_fast_strcat(wb, ",", 1); buffer_rrd_value(wb, (NETDATA_DOUBLE)(p->utime + p->stime + p->gtime + p->cutime + p->cstime + p->cgtime) / cpu_divisor);
4535
+ add_value_field_ndd_with_max(wb, UserCPU, (NETDATA_DOUBLE)(p->utime) / cpu_divisor);
4536
+ add_value_field_ndd_with_max(wb, SysCPU, (NETDATA_DOUBLE)(p->stime) / cpu_divisor);
4537
+ add_value_field_ndd_with_max(wb, GuestCPU, (NETDATA_DOUBLE)(p->gtime) / cpu_divisor);
4538
+ add_value_field_ndd_with_max(wb, CUserCPU, (NETDATA_DOUBLE)(p->cutime) / cpu_divisor);
4539
+ add_value_field_ndd_with_max(wb, CSysCPU, (NETDATA_DOUBLE)(p->cstime) / cpu_divisor);
4540
+ add_value_field_ndd_with_max(wb, CGuestCPU, (NETDATA_DOUBLE)(p->cgtime) / cpu_divisor);
4541
+ add_value_field_ndd_with_max(wb, CPU, (NETDATA_DOUBLE)(p->utime + p->stime + p->gtime + p->cutime + p->cstime + p->cgtime) / cpu_divisor);
4542
4543
// memory MiB
4667
- buffer_fast_strcat(wb, ",", 1); buffer_rrd_value(wb, (NETDATA_DOUBLE)p->status_vmsize / memory_divisor);
4668
- buffer_fast_strcat(wb, ",", 1); buffer_rrd_value(wb, (NETDATA_DOUBLE)p->status_vmrss / memory_divisor);
4669
- buffer_fast_strcat(wb, ",", 1); buffer_rrd_value(wb, (NETDATA_DOUBLE)p->status_vmshared / memory_divisor);
4670
- buffer_fast_strcat(wb, ",", 1); buffer_rrd_value(wb, (NETDATA_DOUBLE)p->status_vmswap / memory_divisor);
4671
-
4672
- if(MemTotal) {
4673
- buffer_fast_strcat(wb, ",", 1);
4674
- buffer_rrd_value(wb, (NETDATA_DOUBLE)p->status_vmrss * 100.0 / (NETDATA_DOUBLE)MemTotal);
4675
- }
4544
+ add_value_field_ndd_with_max(wb, VMSize, (NETDATA_DOUBLE)p->status_vmsize / memory_divisor);
4545
+ add_value_field_ndd_with_max(wb, RSS, (NETDATA_DOUBLE)p->status_vmrss / memory_divisor);
4546
+ add_value_field_ndd_with_max(wb, Shared, (NETDATA_DOUBLE)p->status_vmshared / memory_divisor);
4547
+ add_value_field_ndd_with_max(wb, Swap, (NETDATA_DOUBLE)p->status_vmswap / memory_divisor);
4548
+
4549
+ if(MemTotal)
4550
+ add_value_field_ndd_with_max(wb, MemPcnt, (NETDATA_DOUBLE)p->status_vmrss * 100.0 / (NETDATA_DOUBLE)MemTotal);
4551
4552
// Logical I/O
4553
#ifndef __FreeBSD__
4679
- buffer_fast_strcat(wb, ",", 1); buffer_print_llu(wb, p->io_logical_bytes_read / io_divisor);
4680
- buffer_fast_strcat(wb, ",", 1); buffer_print_llu(wb, p->io_logical_bytes_written / io_divisor);
4554
+ add_value_field_llu_with_max(wb, LReads, p->io_logical_bytes_read / io_divisor);
4555
+ add_value_field_llu_with_max(wb, LWrites, p->io_logical_bytes_written / io_divisor);
4556
#endif
4557
4558
// Physical I/O
4684
- buffer_fast_strcat(wb, ",", 1); buffer_print_llu(wb, p->io_storage_bytes_read / io_divisor);
4685
- buffer_fast_strcat(wb, ",", 1); buffer_print_llu(wb, p->io_storage_bytes_written / io_divisor);
4559
+ add_value_field_llu_with_max(wb, PReads, p->io_storage_bytes_read / io_divisor);
4560
+ add_value_field_llu_with_max(wb, PWrites, p->io_storage_bytes_written / io_divisor);
4561
4562
// I/O calls
4688
- buffer_fast_strcat(wb, ",", 1); buffer_print_llu(wb, p->io_read_calls / RATES_DETAIL);
4689
- buffer_fast_strcat(wb, ",", 1); buffer_print_llu(wb, p->io_write_calls / RATES_DETAIL);
4563
+ add_value_field_llu_with_max(wb, RCalls, p->io_read_calls / RATES_DETAIL);
4564
+ add_value_field_llu_with_max(wb, WCalls, p->io_write_calls / RATES_DETAIL);
4565
4566
// open file descriptors
4692
- buffer_fast_strcat(wb, ",", 1); buffer_print_llu(wb, p->openfds.files);
4693
- buffer_fast_strcat(wb, ",", 1); buffer_print_llu(wb, p->openfds.pipes);
4694
- buffer_fast_strcat(wb, ",", 1); buffer_print_llu(wb, p->openfds.sockets);
4695
- buffer_fast_strcat(wb, ",", 1); buffer_print_llu(wb, p->openfds.inotifies);
4696
- buffer_fast_strcat(wb, ",", 1); buffer_print_llu(wb, p->openfds.eventfds);
4697
- buffer_fast_strcat(wb, ",", 1); buffer_print_llu(wb, p->openfds.timerfds);
4698
- buffer_fast_strcat(wb, ",", 1); buffer_print_llu(wb, p->openfds.signalfds);
4699
- buffer_fast_strcat(wb, ",", 1); buffer_print_llu(wb, p->openfds.eventpolls);
4700
- buffer_fast_strcat(wb, ",", 1); buffer_print_llu(wb, p->openfds.other);
4701
- buffer_fast_strcat(wb, ",", 1); buffer_print_llu(wb, p->openfds.files + p->openfds.pipes + p->openfds.sockets + p->openfds.inotifies + p->openfds.eventfds + p->openfds.timerfds + p->openfds.signalfds + p->openfds.eventpolls + p->openfds.other);
4567
+ add_value_field_llu_with_max(wb, Files, p->openfds.files);
4568
+ add_value_field_llu_with_max(wb, Pipes, p->openfds.pipes);
4569
+ add_value_field_llu_with_max(wb, Sockets, p->openfds.sockets);
4570
+ add_value_field_llu_with_max(wb, iNotiFDs, p->openfds.inotifies);
4571
+ add_value_field_llu_with_max(wb, EventFDs, p->openfds.eventfds);
4572
+ add_value_field_llu_with_max(wb, TimerFDs, p->openfds.timerfds);
4573
+ add_value_field_llu_with_max(wb, SigFDs, p->openfds.signalfds);
4574
+ add_value_field_llu_with_max(wb, EvPollFDs, p->openfds.eventpolls);
4575
+ add_value_field_llu_with_max(wb, OtherFDs, p->openfds.other);
4576
+ add_value_field_llu_with_max(wb, FDs, p->openfds.files + p->openfds.pipes + p->openfds.sockets + p->openfds.inotifies + p->openfds.eventfds + p->openfds.timerfds + p->openfds.signalfds + p->openfds.eventpolls + p->openfds.other);
4577
4578
buffer_fast_strcat(wb, "]", 1);
4579
@@ -4706,9 +4581,189 @@ static void apps_plugin_function_processes(const char *transaction, char *functi
4581
buffer_flush(wb);
4582
}
4583
4584
+ {
4585
+ int fields_added = 0;
4586
+
4587
+ buffer_flush(wb);
4588
+ buffer_sprintf(wb, "\n ],\n \"columns\": {");
4589
+
4590
+ // IMPORTANT!
4591
+ // THE ORDER SHOULD BE THE SAME WITH THE VALUES!
4592
+ add_table_field(wb, "Pid", "Process ID", true, "integer", NULL, NAN, "ascending", true, true, true, NULL, "count_unique");
4593
+ add_table_field(wb, "Cmd", "Process Name", true, "string", NULL, NAN, "ascending", true, true, false, NULL, "count_unique");
4594
+
4595
+#ifdef NETDATA_DEV_MODE
4596
+ add_table_field(wb, "CmdLine", "Command Line", false, "detail-string:Cmd", NULL, NAN, "ascending", true, true, false, NULL, "count_unique");
4597
+#endif
4598
+ add_table_field(wb, "PPid", "Parent Process ID", false, "integer", NULL, NAN, "ascending", true, true, false, "Pid", "count_unique");
4599
+ add_table_field(wb, "Category", "Category (apps_groups.conf)", true, "string", NULL, NAN, "ascending", true, true, false, NULL, "count_unique");
4600
+ add_table_field(wb, "User", "User Owner", true, "string", NULL, NAN, "ascending", true, true, false, NULL, "count_unique");
4601
+ add_table_field(wb, "Uid", "User ID", false, "integer", NULL, NAN, "ascending", true, true, false, NULL, "count_unique");
4602
+ add_table_field(wb, "Group", "Group Owner", false, "string", NULL, NAN, "ascending", true, true, false, NULL, "count_unique");
4603
+ add_table_field(wb, "Gid", "Group ID", false, "integer", NULL, NAN, "ascending", true, true, false, NULL, "count_unique");
4604
+ add_table_field(wb, "Processes", "Processes", true, "bar-with-integer", "processes", Processes_max, "descending", true, false, false, NULL, "sum");
4605
+ add_table_field(wb, "Threads", "Threads", true, "bar-with-integer", "threads", Threads_max, "descending", true, false, false, NULL, "sum");
4606
+ add_table_field(wb, "Uptime", "Uptime in seconds", true, "duration", "seconds", Uptime_max, "descending", true, false, false, NULL, "max");
4607
+
4608
+ // minor page faults
4609
+ add_table_field(wb, "MinFlt", "Minor Page Faults/s", false, "bar", "pgflts/s", MinFlt_max, "descending", true, false, false, NULL, "sum");
4610
+ add_table_field(wb, "CMinFlt", "Children Minor Page Faults/s", false, "bar", "pgflts/s", CMinFlt_max, "descending", true, false, false, NULL, "sum");
4611
+ add_table_field(wb, "TMinFlt", "Total Minor Page Faults/s", false, "bar", "pgflts/s", TMinFlt_max, "descending", true, false, false, NULL, "sum");
4612
+
4613
+ // major page faults
4614
+ add_table_field(wb, "MajFlt", "Major Page Faults/s", false, "bar", "pgflts/s", MajFlt_max, "descending", true, false, false, NULL, "sum");
4615
+ add_table_field(wb, "CMajFlt", "Children Major Page Faults/s", false, "bar", "pgflts/s", CMajFlt_max, "descending", true, false, false, NULL, "sum");
4616
+ add_table_field(wb, "TMajFlt", "Total Major Page Faults/s", true, "bar", "pgflts/s", TMajFlt_max, "descending", true, false, false, NULL, "sum");
4617
+
4618
+ // CPU utilization
4619
+ add_table_field(wb, "UserCPU", "User CPU time", false, "bar", "%", UserCPU_max, "descending", true, false, false, NULL, "sum");
4620
+ add_table_field(wb, "SysCPU", "System CPU Time", false, "bar", "%", SysCPU_max, "descending", true, false, false, NULL, "sum");
4621
+ add_table_field(wb, "GuestCPU", "Guest CPU Time", false, "bar", "%", GuestCPU_max, "descending", true, false, false, NULL, "sum");
4622
+ add_table_field(wb, "CUserCPU", "Children User CPU Time", false, "bar", "%", CUserCPU_max, "descending", true, false, false, NULL, "sum");
4623
+ add_table_field(wb, "CSysCPU", "Children System CPU Time", false, "bar", "%", CSysCPU_max, "descending", true, false, false, NULL, "sum");
4624
+ add_table_field(wb, "CGuestCPU", "Children Guest CPU Time", false, "bar", "%", CGuestCPU_max, "descending", true, false, false, NULL, "sum");
4625
+ add_table_field(wb, "CPU", "Total CPU Time", true, "bar", "%", CPU_max, "descending", true, false, false, NULL, "sum");
4626
+
4627
+ // memory
4628
+ add_table_field(wb, "VMSize", "Virtual Memory Size", false, "bar", "MiB", VMSize_max, "descending", true, false, false, NULL, "sum");
4629
+ add_table_field(wb, "RSS", "Resident Set Size", MemTotal ? false : true, "bar", "MiB", RSS_max, "descending", true, false, false, NULL, "sum");
4630
+ add_table_field(wb, "Shared", "Shared Pages", false, "bar", "MiB", Shared_max, "descending", true, false, false, NULL, "sum");
4631
+ add_table_field(wb, "Swap", "Swap Memory", false, "bar", "MiB", Swap_max, "descending", true, false, false, NULL, "sum");
4632
+
4633
+ if(MemTotal)
4634
+ add_table_field(wb, "MemPcnt", "Memory Percentage", true, "bar", "%", 100.0, "descending", true, false, false, NULL, "sum");
4635
+
4636
+ // Logical I/O
4637
+#ifndef __FreeBSD__
4638
+ add_table_field(wb, "LReads", "Logical I/O Reads", false, "bar", "KiB/s", LReads_max, "descending", true, false, false, NULL, "sum");
4639
+ add_table_field(wb, "LWrites", "Logical I/O Writes", false, "bar", "KiB/s", LWrites_max, "descending", true, false, false, NULL, "sum");
4640
+#endif
4641
+
4642
+ // Physical I/O
4643
+ add_table_field(wb, "PReads", "Physical I/O Reads", true, "bar", "KiB/s", PReads_max, "descending", true, false, false, NULL, "sum");
4644
+ add_table_field(wb, "PWrites", "Physical I/O Writes", true, "bar", "KiB/s", PWrites_max, "descending", true, false, false, NULL, "sum");
4645
+
4646
+ // I/O calls
4647
+ add_table_field(wb, "RCalls", "I/O Read Calls", false, "bar", "calls/s", RCalls_max, "descending", true, false, false, NULL, "sum");
4648
+ add_table_field(wb, "WCalls", "I/O Write Calls", false, "bar", "calls/s", WCalls_max, "descending", true, false, false, NULL, "sum");
4649
+
4650
+ // open file descriptors
4651
+ add_table_field(wb, "Files", "Open Files", false, "bar", "fds", Files_max, "descending", true, false, false, NULL, "sum");
4652
+ add_table_field(wb, "Pipes", "Open Pipes", false, "bar", "fds", Pipes_max, "descending", true, false, false, NULL, "sum");
4653
+ add_table_field(wb, "Sockets", "Open Sockets", false, "bar", "fds", Sockets_max, "descending", true, false, false, NULL, "sum");
4654
+ add_table_field(wb, "iNotiFDs", "Open iNotify Descriptors", false, "bar", "fds", iNotiFDs_max, "descending", true, false, false, NULL, "sum");
4655
+ add_table_field(wb, "EventFDs", "Open Event Descriptors", false, "bar", "fds", EventFDs_max, "descending", true, false, false, NULL, "sum");
4656
+ add_table_field(wb, "TimerFDs", "Open Timer Descriptors", false, "bar", "fds", TimerFDs_max, "descending", true, false, false, NULL, "sum");
4657
+ add_table_field(wb, "SigFDs", "Open Signal Descriptors", false, "bar", "fds", SigFDs_max, "descending", true, false, false, NULL, "sum");
4658
+ add_table_field(wb, "EvPollFDs", "Open Event Poll Descriptors", false, "bar", "fds", EvPollFDs_max, "descending", true, false, false, NULL, "sum");
4659
+ add_table_field(wb, "OtherFDs", "Other Open Descriptors", false, "bar", "fds", OtherFDs_max, "descending", true, false, false, NULL, "sum");
4660
+ add_table_field(wb, "FDs", "All Open File Descriptors", true, "bar", "fds", FDs_max, "descending", true, false, false, NULL, "sum");
4661
+
4662
+ buffer_strcat(
4663
+ wb,
4664
+ ""
4665
+ "\n },"
4666
+ "\n \"default sort column\": \"CPU\","
4667
+ "\n \"charts\": {"
4668
+ "\n \"CPU\": {"
4669
+ "\n \"name\":\"CPU Utilization\","
4670
+ "\n \"type\":\"stacked-bar\","
4671
+ "\n \"columns\": [ \"UserCPU\", \"SysCPU\", \"GuestCPU\", \"CUserCPU\", \"CSysCPU\", \"CGuestCPU\" ]"
4672
+ "\n },"
4673
+ "\n \"Memory\": {"
4674
+ "\n \"name\":\"Memory\","
4675
+ "\n \"type\":\"stacked-bar\","
4676
+ "\n \"columns\": [ \"VMSize\", \"RSS\", \"Shared\", \"Swap\" ]"
4677
+ "\n },"
4678
+ );
4679
+
4680
+ if(MemTotal)
4681
+ buffer_strcat(
4682
+ wb,
4683
+ ""
4684
+ "\n \"MemoryPercent\": {"
4685
+ "\n \"name\":\"Memory Percentage\","
4686
+ "\n \"type\":\"stacked-bar\","
4687
+ "\n \"columns\": [ \"MemPcnt\" ]"
4688
+ "\n },"
4689
+ );
4690
+
4691
+ buffer_strcat(
4692
+ wb, ""
4693
+ #ifndef __FreeBSD__
4694
+ "\n \"Reads\": {"
4695
+ "\n \"name\":\"I/O Reads\","
4696
+ "\n \"type\":\"stacked-bar\","
4697
+ "\n \"columns\": [ \"LReads\", \"PReads\" ]"
4698
+ "\n },"
4699
+ "\n \"Writes\": {"
4700
+ "\n \"name\":\"I/O Writes\","
4701
+ "\n \"type\":\"stacked-bar\","
4702
+ "\n \"columns\": [ \"LWrites\", \"PWrites\" ]"
4703
+ "\n },"
4704
+ "\n \"LogicalIO\": {"
4705
+ "\n \"name\":\"Logical I/O\","
4706
+ "\n \"type\":\"stacked-bar\","
4707
+ "\n \"columns\": [ \"LReads\", \"LWrites\" ]"
4708
+ "\n },"
4709
+ #endif
4710
+ "\n \"PhysicalIO\": {"
4711
+ "\n \"name\":\"Physical I/O\","
4712
+ "\n \"type\":\"stacked-bar\","
4713
+ "\n \"columns\": [ \"PReads\", \"PWrites\" ]"
4714
+ "\n },"
4715
+ "\n \"IOCalls\": {"
4716
+ "\n \"name\":\"I/O Calls\","
4717
+ "\n \"type\":\"stacked-bar\","
4718
+ "\n \"columns\": [ \"RCalls\", \"WCalls\" ]"
4719
+ "\n },"
4720
+ "\n \"MinFlt\": {"
4721
+ "\n \"name\":\"Minor Page Faults\","
4722
+ "\n \"type\":\"stacked-bar\","
4723
+ "\n \"columns\": [ \"MinFlt\", \"CMinFlt\" ]"
4724
+ "\n },"
4725
+ "\n \"MajFlt\": {"
4726
+ "\n \"name\":\"Major Page Faults\","
4727
+ "\n \"type\":\"stacked-bar\","
4728
+ "\n \"columns\": [ \"MajFlt\", \"CMajFlt\" ]"
4729
+ "\n },"
4730
+ "\n \"Threads\": {"
4731
+ "\n \"name\":\"Threads\","
4732
+ "\n \"type\":\"stacked-bar\","
4733
+ "\n \"columns\": [ \"Threads\" ]"
4734
+ "\n },"
4735
+ "\n \"Processes\": {"
4736
+ "\n \"name\":\"Processes\","
4737
+ "\n \"type\":\"stacked-bar\","
4738
+ "\n \"columns\": [ \"Processes\" ]"
4739
+ "\n },"
4740
+ "\n \"FDs\": {"
4741
+ "\n \"name\":\"File Descriptors\","
4742
+ "\n \"type\":\"stacked-bar\","
4743
+ "\n \"columns\": [ \"Files\", \"Pipes\", \"Sockets\", \"iNotiFDs\", \"EventFDs\", \"TimerFDs\", \"SigFDs\", \"EvPollFDs\", \"OtherFDs\" ]"
4744
+ "\n }"
4745
+ "\n },"
4746
+ "\n \"group_by\": {"
4747
+ "\n \"Process Tree by PID\": {"
4748
+ "\n \"columns\": [ \"PPid\" ]"
4749
+ "\n },"
4750
+ "\n \"Process Tree by Category\": {"
4751
+ "\n \"columns\": [ \"Category\", \"PPid\" ]"
4752
+ "\n },"
4753
+ "\n \"Process Tree by User\": {"
4754
+ "\n \"columns\": [ \"User\", \"PPid\" ]"
4755
+ "\n },"
4756
+ "\n \"Process Tree by Group\": {"
4757
+ "\n \"columns\": [ \"Group\", \"PPid\" ]"
4758
+ "\n }"
4759
+ "\n }"
4760
+ );
4761
+
4762
+ fwrite(buffer_tostring(wb), buffer_strlen(wb), 1, stdout);
4763
+ }
4764
+
4765
buffer_free(wb);
4766
4711
- fprintf(stdout, "\n ]");
4767
fprintf(stdout, ",\n \"expires\":%lld", (long long)expires);
4768
fprintf(stdout, "\n}");
4769