summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2019-07-27 23:40:24 +0200
committerLennart Poettering <lennart@poettering.net>2019-07-29 18:50:31 +0200
commit37109b856aebeb8a35727b5bf333e98e44232d9d (patch)
tree44117b6a3c339602f942de9861ee250e1920fbc4
parent49139a5d927676f938c466610edb0c5d5c6e82c6 (diff)
downloadsystemd-37109b856aebeb8a35727b5bf333e98e44232d9d.tar.gz
pid1: use LOG_DEBUG/INFO/NOTICE for unit resource consumption message
We now log at LOG_INFO for any unit. Let's vary the log level a bit, so that for normal short lived-units (less than 1 sec CPU), we only log if debugging is enabled.
-rw-r--r--src/core/unit.c35
1 files changed, 34 insertions, 1 deletions
diff --git a/src/core/unit.c b/src/core/unit.c
index fa89bd4a4d..c130fff7bb 100644
--- a/src/core/unit.c
+++ b/src/core/unit.c
@@ -57,6 +57,16 @@
#include "user-util.h"
#include "virt.h"
+/* Thresholds for logging at INFO level about resource consumption */
+#define MENTIONWORTHY_CPU_NSEC (1 * NSEC_PER_SEC)
+#define MENTIONWORTHY_IO_BYTES (1024 * 1024ULL)
+#define MENTIONWORTHY_IP_BYTES (0ULL)
+
+/* Thresholds for logging at INFO level about resource consumption */
+#define NOTICEWORTHY_CPU_NSEC (10*60 * NSEC_PER_SEC) /* 10 minutes */
+#define NOTICEWORTHY_IO_BYTES (10 * 1024 * 1024ULL) /* 10 MB */
+#define NOTICEWORTHY_IP_BYTES (128 * 1024 * 1024ULL) /* 128 MB */
+
const UnitVTable * const unit_vtable[_UNIT_TYPE_MAX] = {
[UNIT_SERVICE] = &service_vtable,
[UNIT_SOCKET] = &socket_vtable,
@@ -2138,10 +2148,19 @@ void unit_trigger_notify(Unit *u) {
UNIT_VTABLE(other)->trigger_notify(other, u);
}
+static int raise_level(int log_level, bool condition_info, bool condition_notice) {
+ if (condition_notice && log_level > LOG_NOTICE)
+ return LOG_NOTICE;
+ if (condition_info && log_level > LOG_INFO)
+ return LOG_INFO;
+ return log_level;
+}
+
static int unit_log_resources(Unit *u) {
struct iovec iovec[1 + _CGROUP_IP_ACCOUNTING_METRIC_MAX + _CGROUP_IO_ACCOUNTING_METRIC_MAX + 4];
bool any_traffic = false, have_ip_accounting = false, any_io = false, have_io_accounting = false;
_cleanup_free_ char *igress = NULL, *egress = NULL, *rr = NULL, *wr = NULL;
+ int log_level = LOG_DEBUG; /* May be raised if resources consumed over a treshold */
size_t n_message_parts = 0, n_iovec = 0;
char* message_parts[1 + 2 + 2 + 1], *t;
nsec_t nsec = NSEC_INFINITY;
@@ -2187,6 +2206,10 @@ static int unit_log_resources(Unit *u) {
}
message_parts[n_message_parts++] = t;
+
+ log_level = raise_level(log_level,
+ nsec > NOTICEWORTHY_CPU_NSEC,
+ nsec > MENTIONWORTHY_CPU_NSEC);
}
for (CGroupIOAccountingMetric k = 0; k < _CGROUP_IO_ACCOUNTING_METRIC_MAX; k++) {
@@ -2227,6 +2250,11 @@ static int unit_log_resources(Unit *u) {
goto finish;
}
}
+
+ if (IN_SET(k, CGROUP_IO_READ_BYTES, CGROUP_IO_WRITE_BYTES))
+ log_level = raise_level(log_level,
+ value > MENTIONWORTHY_IO_BYTES,
+ value > NOTICEWORTHY_IO_BYTES);
}
if (have_io_accounting) {
@@ -2287,6 +2315,11 @@ static int unit_log_resources(Unit *u) {
goto finish;
}
}
+
+ if (IN_SET(m, CGROUP_IP_INGRESS_BYTES, CGROUP_IP_EGRESS_BYTES))
+ log_level = raise_level(log_level,
+ value > MENTIONWORTHY_IP_BYTES,
+ value > NOTICEWORTHY_IP_BYTES);
}
if (have_ip_accounting) {
@@ -2343,7 +2376,7 @@ static int unit_log_resources(Unit *u) {
t = strjoina(u->manager->invocation_log_field, u->invocation_id_string);
iovec[n_iovec + 3] = IOVEC_MAKE_STRING(t);
- log_struct_iovec(LOG_INFO, iovec, n_iovec + 4);
+ log_struct_iovec(log_level, iovec, n_iovec + 4);
r = 0;
finish: