2 years ago
#45092

fleetingbytes
Unexpected output of top when started by systemctl
I want to log the cpu and memory usage of a service which starts some time after startup (webappmgr.service
). For this I have created another simple logging service which depends on it and shall be run after webappmgr
starts called perftrace.service
. This shall continuously write the output of top
and awk
to the file /tmp/webapp.top
:
[Unit]
Description=Perftrace
After=webappmgr.service
[Service]
User=root
Type=oneshot
RemainAfterExit=yes
ExecStart=/bin/bash -c 'top -b -H -p $(pgrep webappmgr) | awk \'{ print strftime("%%H:%%M:%%S", systime())" " $0 }\' > /tmp/webapp.top &'
[Install]
WantedBy=webappmgr.service
When the system is started up and webappmgr
is running, I start perftrace
by systemctl start perftrace
. In the file /tmp/webapp.top
I see what I want to see:
04:26:27 2596 testuser 20 0 1887640 24092 17068 S 0.0 0.5 0:00.27 webappmgr
04:26:27 2622 testuser 20 0 1887640 24092 17068 S 0.0 0.5 0:00.06 JSEngine
04:26:27 2628 testuser 20 0 1887640 24092 17068 S 0.0 0.5 0:00.01 webappmgr
04:26:27 2629 testuser 20 0 1887640 24092 17068 S 0.0 0.5 0:00.00 webappmgr
04:26:27 2630 testuser 20 0 1887640 24092 17068 S 0.0 0.5 0:00.00 webappmgr
04:26:27 2631 testuser 20 0 1887640 24092 17068 S 0.0 0.5 0:00.00 webappmgr
04:26:27 2632 testuser 20 0 1887640 24092 17068 S 0.0 0.5 0:00.00 FileDownloa+
However, after enabling the perftrace.service
and rebooting the system, so that it starts at the startup right after webappmgr
, I see a completely different ouput in the file:
04:31:03 %Cpu(s): 33.1 us, 17.7 sy, 0.1 ni, 41.2 id, 1.2 wa, 4.3 hi, 2.5 si, 0.0 st
04:31:03 KiB Mem : 4667484 total, 1369968 free, 2187548 used, 1109968 buff/cache
04:31:03 KiB Swap: 0 total, 0 free, 0 used. 2373988 avail Mem
04:31:03
04:31:06 PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
04:31:06
04:31:06 top - 04:31:06 up 1 min, 1 user, load average: 40.87, 12.93, 4.54
04:31:06 Threads: 0 total, 0 running, 0 sleeping, 0 stopped, 0 zombie
04:31:06 %Cpu(s): 11.2 us, 15.5 sy, 0.0 ni, 66.8 id, 0.8 wa, 3.5 hi, 2.1 si, 0.0 st
04:31:06 KiB Mem : 4667484 total, 1362788 free, 2194416 used, 1110280 buff/cache
04:31:06 KiB Swap: 0 total, 0 free, 0 used. 2367116 avail Mem
04:31:06
04:31:09 PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
04:31:09
04:31:09 top - 04:31:09 up 1 min, 1 user, load average: 40.87, 12.93, 4.54
04:31:09 Threads: 0 total, 0 running, 0 sleeping, 0 stopped, 0 zombie
04:31:09 %Cpu(s): 11.9 us, 16.2 sy, 0.0 ni, 66.0 id, 0.0 wa, 3.6 hi, 2.2 si, 0.0 st
04:31:09 KiB Mem : 4667484 total, 1358060 free, 2199204 used, 1110220 buff/cache
04:31:09 KiB Swap: 0 total, 0 free, 0 used. 2362388 avail Mem
04:31:09
what shall I do to get similar output to when I started my perftrace service manually?
linux
systemctl
linux
systemctl
0 Answers
Your Answer