@cryptotaxi247 / netdata-1 / commits / a7370f415

apps.plugin limits tracing (#15504)

Costa Tsaousis committed Jul 24, 2023 at 18:10 UTC a7370f4157c1eaf31479499c586dd6770bd3b01e
1 file changed +32 -3
collectors/apps.plugin/apps_plugin.c
+32 -3
@@ -1363,6 +1363,9 @@ static inline kernel_uint_t get_proc_pid_limits_limit(char *buf, const char *key
1363 char *v = &line[key_len];
1364 while(isspace(*v)) v++;
1365
1366 + if(strcmp(v, "unlimited") == 0)
1367 + return 0;
1368 +
1369 return str2ull(v, NULL);
1370 }
1371
@@ -1377,6 +1380,7 @@ static inline int read_proc_pid_limits(struct pid_stat *p, void *ptr) {
1380 bool read_limits = false;
1381
1382 errno = 0;
1383 + proc_pid_limits_buffer[0] = '\0';
1384
1385 kernel_uint_t all_fds = pid_openfds_sum(p);
1386 if(all_fds < p->limits.max_open_files / 2 && p->io_collected_usec > p->last_limits_collected_usec && p->io_collected_usec - p->last_limits_collected_usec <= 60 * USEC_PER_SEC) {
@@ -1400,9 +1404,15 @@ static inline int read_proc_pid_limits(struct pid_stat *p, void *ptr) {
1404 if(bytes <= 0)
1405 goto cleanup;
1406
1403 - read_limits = true;
1407 + // make it '\0' terminated
1408 + if(bytes < MAX_PROC_PID_LIMITS)
1409 + proc_pid_limits_buffer[bytes] = '\0';
1410 + else
1411 + proc_pid_limits_buffer[MAX_PROC_PID_LIMITS - 1] = '\0';
1412 +
1413 p->limits.max_open_files = get_proc_pid_limits_limit(proc_pid_limits_buffer, PROC_PID_LIMITS_MAX_OPEN_FILES_KEY, sizeof(PROC_PID_LIMITS_MAX_OPEN_FILES_KEY) - 1, 0);
1414 p->last_limits_collected_usec = p->io_collected_usec;
1415 + read_limits = true;
1416
1417 ret = 1;
1418
@@ -1414,6 +1424,23 @@ cleanup:
1424
1425 if(p->openfds_limits_percent > 100.0) {
1426 if(!(p->log_thrown & PID_LOG_LIMITS_DETAIL)) {
1427 + char *line;
1428 +
1429 + if(!read_limits) {
1430 + proc_pid_limits_buffer[0] = '\0';
1431 + line = "NOT READ";
1432 + }
1433 + else {
1434 + line = strstr(proc_pid_limits_buffer, PROC_PID_LIMITS_MAX_OPEN_FILES_KEY);
1435 + if (line) {
1436 + line++; // skip the initial newline
1437 +
1438 + char *end = strchr(line, '\n');
1439 + if (end)
1440 + *end = '\0';
1441 + }
1442 + }
1443 +
1444 netdata_log_info(
1445 "FDS_LIMITS: PID %d (%s) is using "
1446 "%0.2f %% of its fds limits, "
@@ -1428,7 +1455,8 @@ cleanup:
1455 "eventpolls = %llu "
1456 "other = %llu "
1457 "), open fds limit = %llu, "
1431 - "%s",
1458 + "%s, "
1459 + "original line [%s]",
1460 p->pid, p->comm, p->openfds_limits_percent, all_fds,
1461 p->openfds.files,
1462 p->openfds.pipes,
@@ -1441,7 +1469,8 @@ cleanup:
1469 p->openfds.other,
1470 p->limits.max_open_files,
1471 read_limits ? "and we have read the limits AFTER counting the fds"
1444 - : "but we have read the limits BEFORE counting the fds");
1472 + : "but we have read the limits BEFORE counting the fds",
1473 + line);
1474
1475 p->log_thrown |= PID_LOG_LIMITS_DETAIL;
1476 }