kingbosster 发表于 2018-8-11 08:09:06

python获取linux中top信息

commands :top -b -n 1  ######## ip: 192.168.47.196######2018:3:4:16:9:46====
  top - 03:52:39 up9:05,1 user,load average: 0.00, 0.00, 0.00
  Tasks: 110 total,   1 running, 108 sleeping,   1 stopped,   0 zombie
  Cpu(s):0.2%us,0.1%sy,0.0%ni, 99.5%id,0.2%wa,0.0%hi,0.0%si,0.0%st
  Mem:   1914164k total,   814092k used,1100072k free,   170248k buffers
  Swap:2064376k total,      0k used,2064376k free,   491472k cached
  PID USER      PRNIVIRTRESSHR S %CPU %MEM    TIME+COMMAND
  1 root      20   02900 1440 1216 S0.00.1   0:01.44 init
  2 root      20   0   0    0    0 S0.00.0   0:00.00 kthreadd
  3 root      RT   0   0    0    0 S0.00.0   0:00.15 migration/0
  4 root      20   0   0    0    0 S0.00.0   0:00.07 ksoftirqd/0
  5 root      RT   0   0    0    0 S0.00.0   0:00.00 migration/0
  6 root      RT   0   0    0    0 S0.00.0   0:01.12 watchdog/0
  7 root      RT   0   0    0    0 S0.00.0   0:00.18 migration/1
  8 root      RT   0   0    0    0 S0.00.0   0:00.00 migration/1
  9 root      20   0   0    0    0 S0.00.0   0:00.10 ksoftirqd/1
  10 root      RT   0   0    0    0 S0.00.0   0:00.15 watchdog/1
  11 root      20   0   0    0    0 S0.00.0   0:02.38 events/0
  12 root      20   0   0    0    0 S0.00.0   0:07.81 events/1
  13 root      20   0   0    0    0 S0.00.0   0:00.00 cgroup
  14 root      20   0   0    0    0 S0.00.0   0:00.00 khelper
  15 root      20   0   0    0    0 S0.00.0   0:00.00 netns
  16 root      20   0   0    0    0 S0.00.0   0:00.00 async/mgr
  17 root      20   0   0    0    0 S0.00.0   0:00.00 pm
  18 root      20   0   0    0    0 S0.00.0   0:00.11 sync_supers
  19 root      20   0   0    0    0 S0.00.0   0:00.11 bdi-default
  20 root      20   0   0    0    0 S0.00.0   0:00.00 kintegrityd/0
  21 root      20   0   0    0    0 S0.00.0   0:00.00 kintegrityd/1
  22 root      20   0   0    0    0 S0.00.0   0:00.25 kblockd/0
  23 root      20   0   0    0    0 S0.00.0   0:00.43 kblockd/1
  24 root      20   0   0    0    0 S0.00.0   0:00.00 kacpid
  25 root      20   0   0    0    0 S0.00.0   0:00.00 kacpi_notify
  26 root      20   0   0    0    0 S0.00.0   0:00.00 kacpi_hotplug
  27 root      20   0   0    0    0 S0.00.0   0:00.00 ata_aux
  28 root      20   0   0    0    0 S0.00.0   0:00.03 ata_sff/0
  29 root      20   0   0    0    0 S0.00.0   0:00.00 ata_sff/1
  30 root      20   0   0    0    0 S0.00.0   0:00.00 ksuspend_usbd
  31 root      20   0   0    0    0 S0.00.0   0:00.00 khubd
  32 root      20   0   0    0    0 S0.00.0   0:00.00 kseriod
  33 root      20   0   0    0    0 S0.00.0   0:00.00 md/0
  34 root      20   0   0    0    0 S0.00.0   0:00.00 md/1
  35 root      20   0   0    0    0 S0.00.0   0:00.00 md_misc/0
  36 root      20   0   0    0    0 S0.00.0   0:00.00 md_misc/1
  37 root      20   0   0    0    0 S0.00.0   0:00.00 linkwatch
  38 root      20   0   0    0    0 S0.00.0   0:00.00 khungtaskd
  39 root      20   0   0    0    0 S0.00.0   0:00.00 kswapd0
  40 root      25   5   0    0    0 S0.00.0   0:00.00 ksmd
  41 root      20   0   0    0    0 S0.00.0   0:00.00 aio/0
  42 root      20   0   0    0    0 S0.00.0   0:00.00 aio/1
  43 root      20   0   0    0    0 S0.00.0   0:00.00 crypto/0
  44 root      20   0   0    0    0 S0.00.0   0:00.00 crypto/1
  49 root      20   0   0    0    0 S0.00.0   0:00.00 kthrotld/0
  50 root      20   0   0    0    0 S0.00.0   0:00.00 kthrotld/1
  51 root      20   0   0    0    0 S0.00.0   0:00.00 pciehpd
  53 root      20   0   0    0    0 S0.00.0   0:00.00 kpsmoused
  54 root      20   0   0    0    0 S0.00.0   0:00.00 usbhid_resumer
  85 root      20   0   0    0    0 S0.00.0   0:00.00 kstriped
  162 root      20   0   0    0    0 S0.00.0   0:00.01 scsi_eh_0
  166 root      20   0   0    0    0 S0.00.0   0:00.00 scsi_eh_1
  176 root      20   0   0    0    0 S0.00.0   0:00.68 mpt_poll_0
  177 root      20   0   0    0    0 S0.00.0   0:00.00 mpt/0
  178 root      20   0   0    0    0 S0.00.0   0:00.00 scsi_eh_2
  306 root      20   0   0    0    0 S0.00.0   0:00.00 kdmflush
  307 root      20   0   0    0    0 S0.00.0   0:00.00 kdmflush
  326 root      20   0   0    0    0 S0.00.0   0:03.24 flush-253:0
  327 root      20   0   0    0    0 S0.00.0   0:02.66 jbd2/dm-0-8
  328 root      20   0   0    0    0 S0.00.0   0:00.00 ext4-dio-unwrit
  415 root      16-42720 1008364 S0.00.1   0:01.14 udevd
  764 root      20   0   0    0    0 S0.00.0   0:32.91 vmmemctl
  898 root      18-22716 1000360 S0.00.1   0:00.00 udevd
  941 root      20   0   0    0    0 S0.00.0   0:00.00 jbd2/sda1-8
  942 root      20   0   0    0    0 S0.00.0   0:00.00 ext4-dio-unwrit
  1032 root      20   0   0    0    0 S0.00.0   0:00.05 kauditd
  1194 root      16-4 12932824600 S0.00.0   0:00.12 auditd
  1219 root      20   0 37000 1548 1040 S0.00.1   0:00.11 rsyslogd
  1248 root      20   02268628444 S0.00.0   0:04.43 irqbalance
  1262 rpc       20   02576792592 S0.00.0   0:00.06 rpcbind
  1277 dbus      20   03100 1056744 S0.00.1   0:00.35 dbus-daemon
  1287 root      20   0 32312 4416 3776 S0.00.2   0:01.25 NetworkManager
  1294 root      20   04868 2272 1912 S0.00.1   0:00.08 modem-manager
  1306 rpcuser   20   02840 1272868 S0.00.1   0:00.03 rpc.statd
  1335 root      20   0 13332 2752 2084 S0.00.1   0:00.01 cupsd
  1365 root      20   07628648432 S0.00.0   0:00.00 wpa_supplicant
  1366 root      20   02020592508 S0.00.0   0:00.00 acpid
  1375 haldaemo20   0 17764 4844 4064 S0.00.3   0:00.35 hald
  1376 root      20   04052 1128964 S0.00.1   0:00.00 hald-runner
  1418 root      20   04124 1060928 S0.00.1   0:00.00 hald-addon-inpu
  1422 haldaemo20   03712 1008892 S0.00.1   0:00.00 hald-addon-acpi
  1443 root      20   0 30040 1592 1220 S0.00.1   0:00.87 automount
  1503 root      20   0 51984 4840 1492 S0.00.3   0:01.18 php-fpm
  1504 www       20   0 51984 4208860 S0.00.2   0:00.00 php-fpm
  1505 www       20   0 51984 4212864 S0.00.2   0:00.00 php-fpm
  1513 root      20   07776884396 S0.00.0   0:00.00 nginx
  1518 www       20   0 1838811m628 S0.00.6   0:02.46 nginx
  1519 www       20   0 1838811m532 S0.00.6   0:00.08 nginx
  1526 root      20   08968988480 S0.00.1   0:00.01 sshd
  1540 root      20   06276 1392 1188 S0.00.1   0:00.04 mysqld_safe
  2080 mysql   20   0212m25m 5064 S0.01.4   0:05.39 mysqld
  2084 root      20   06672940824 S0.00.0   0:00.00 abrtd
  2092 root      20   07148 1196636 S0.00.1   0:00.06 crond
  2103 root      20   02988468320 S0.00.0   0:00.00 atd
  2115 root      20   08808564272 S0.00.0   0:00.02 certmonger
  2128 root      20   02008476424 S0.00.0   0:00.00 mingetty
  2130 root      20   02008476424 S0.00.0   0:00.00 mingetty
  2132 root      20   02008472424 S0.00.0   0:00.00 mingetty
  2134 root      20   02008480424 S0.00.0   0:00.00 mingetty
  2136 root      20   02008480424 S0.00.0   0:00.00 mingetty
  2138 root      20   02008480424 S0.00.0   0:00.00 mingetty
  2139 root      18-22716980340 S0.00.1   0:00.00 udevd
  17357 root      20   0 11912 3520 2760 S0.00.2   0:00.08 sshd
  17359 root      20   06876 1804 1468 S0.00.1   0:00.02 bash
  17959 root      20   02836 1272988 S0.00.1   0:00.00 dhclient
  18005 smmsp   20   0 12612 1764684 S0.00.1   0:00.00 sendmail
  18006 root      20   0 12988 2004740 S0.00.1   0:01.19 sendmail
  18107 root      20   02020480412 T0.00.0   0:00.00 vmstat
  18757 root      20   0 12044 3524 2768 S0.00.2   0:00.05 sshd
  18759 root      20   02712984768 R0.00.1   0:00.00 top
  commands :free -m
  ######## ip: 192.168.47.196######2018:3:4:16:9:46====
  total       used       free   shared    buffers   cached
  Mem:          1869      795       1074          0      166      479
  -/+ buffers/cache:      148       1720
  Swap:         2015          0       2015
  commands :vmstat 1 1
  ######## ip: 192.168.47.196######2018:3:4:16:9:46====
  procs -----------memory---------- ---swap-- -----io---- --system-- -----cpu-----

  rb   swpd   free   buffcache   si   so    bi    bo   in   cs us sy>  10      0 1100048 170256 491472    0    0   6   5   29   4200 9900
  commands :top -b -n 1
  ######## ip: 192.168.41.11######2018:3:4:16:9:47====
  top - 16:09:36 up 34 days, 23:46,0 users,load average: 0.00, 0.00, 0.00
  Tasks: 100 total,   1 running,99 sleeping,   0 stopped,   0 zombie
  Cpu(s):0.1%us,0.0%sy,0.0%ni, 99.9%id,0.0%wa,0.0%hi,0.0%si,0.0%st
  Mem:   4056492k total,1399408k used,2657084k free,   246380k buffers
  Swap:      0k total,      0k used,      0k free,   496020k cached
  PID USER      PRNIVIRTRESSHR S %CPU %MEM    TIME+COMMAND
  1 root      20   0 19352 1540 1236 S0.00.0   0:00.68 init
  2 root      20   0   0    0    0 S0.00.0   0:00.00 kthreadd
  3 root      RT   0   0    0    0 S0.00.0   0:00.46 migration/0
  4 root      20   0   0    0    0 S0.00.0   0:01.10 ksoftirqd/0
  5 root      RT   0   0    0    0 S0.00.0   0:00.00 stopper/0
  6 root      RT   0   0    0    0 S0.00.0   0:02.20 watchdog/0
  7 root      RT   0   0    0    0 S0.00.0   0:00.22 migration/1
  8 root      RT   0   0    0    0 S0.00.0   0:00.00 stopper/1
  9 root      20   0   0    0    0 S0.00.0   0:01.24 ksoftirqd/1
  10 root      RT   0   0    0    0 S0.00.0   0:01.72 watchdog/1
  11 root      20   0   0    0    0 S0.00.0   1:41.08 events/0
  12 root      20   0   0    0    0 S0.00.0   2:25.67 events/1
  13 root      20   0   0    0    0 S0.00.0   0:00.00 events/0
  14 root      20   0   0    0    0 S0.00.0   0:00.00 events/1
  15 root      20   0   0    0    0 S0.00.0   0:00.00 events_long/0
  16 root      20   0   0    0    0 S0.00.0   0:00.00 events_long/1
  17 root      20   0   0    0    0 S0.00.0   0:00.00 events_power_ef
  18 root      20   0   0    0    0 S0.00.0   0:00.00 events_power_ef
  19 root      20   0   0    0    0 S0.00.0   0:00.00 cgroup
  20 root      20   0   0    0    0 S0.00.0   0:00.00 khelper
  21 root      20   0   0    0    0 S0.00.0   0:00.00 netns
  22 root      20   0   0    0    0 S0.00.0   0:00.00 async/mgr
  23 root      20   0   0    0    0 S0.00.0   0:00.00 pm
  24 root      20   0   0    0    0 S0.00.0   0:07.93 sync_supers
  25 root      20   0   0    0    0 S0.00.0   0:00.13 bdi-default
  26 root      20   0   0    0    0 S0.00.0   0:00.00 kintegrityd/0
  27 root      20   0   0    0    0 S0.00.0   0:00.00 kintegrityd/1
  28 root      20   0   0    0    0 S0.00.0   0:02.26 kblockd/0
  29 root      20   0   0    0    0 S0.00.0   0:01.05 kblockd/1
  30 root      20   0   0    0    0 S0.00.0   0:00.00 kacpid
  31 root      20   0   0    0    0 S0.00.0   0:00.00 kacpi_notify
  32 root      20   0   0    0    0 S0.00.0   0:00.00 kacpi_hotplug
  33 root      20   0   0    0    0 S0.00.0   0:00.00 ata_aux
  34 root      20   0   0    0    0 S0.00.0   0:00.00 ata_sff/0
  35 root      20   0   0    0    0 S0.00.0   0:00.00 ata_sff/1
  36 root      20   0   0    0    0 S0.00.0   0:00.00 ksuspend_usbd
  37 root      20   0   0    0    0 S0.00.0   0:00.00 khubd
  38 root      20   0   0    0    0 S0.00.0   0:00.00 kseriod
  39 root      20   0   0    0    0 S0.00.0   0:00.00 md/0
  40 root      20   0   0    0    0 S0.00.0   0:00.00 md/1
  41 root      20   0   0    0    0 S0.00.0   0:00.00 md_misc/0
  42 root      20   0   0    0    0 S0.00.0   0:00.00 md_misc/1
  43 root      20   0   0    0    0 S0.00.0   0:00.00 linkwatch
  46 root      20   0   0    0    0 S0.00.0   0:00.61 khungtaskd
  47 root      20   0   0    0    0 S0.00.0   0:00.00 kswapd0
  48 root      25   5   0    0    0 S0.00.0   0:00.00 ksmd
  49 root      3919   0    0    0 S0.00.0   0:03.93 khugepaged
  50 root      20   0   0    0    0 S0.00.0   0:00.00 aio/0
  51 root      20   0   0    0    0 S0.00.0   0:00.00 aio/1
  52 root      20   0   0    0    0 S0.00.0   0:00.00 crypto/0
  53 root      20   0   0    0    0 S0.00.0   0:00.00 crypto/1
  60 root      20   0   0    0    0 S0.00.0   0:00.00 kthrotld/0
  61 root      20   0   0    0    0 S0.00.0   0:00.00 kthrotld/1
  63 root      20   0   0    0    0 S0.00.0   0:00.00 kpsmoused
  64 root      20   0   0    0    0 S0.00.0   0:00.00 usbhid_resumer
  65 root      20   0   0    0    0 S0.00.0   0:00.00 deferwq
  97 root      20   0   0    0    0 S0.00.0   0:00.00 kdmremove
  98 root      20   0   0    0    0 S0.00.0   0:00.00 kstriped
  280 root      20   0   0    0    0 S0.00.0   0:00.00 scsi_eh_0
  281 root      20   0   0    0    0 S0.00.0   0:00.00 scsi_eh_1
  330 root      20   0   0    0    0 S0.00.0   0:00.00 virtio-blk
  401 root      20   0   0    0    0 S0.00.0   0:08.18 jbd2/vda1-8
  402 root      20   0   0    0    0 S0.00.0   0:00.00 ext4-dio-unwrit
  500 root      16-4 10796916348 S0.00.0   0:00.05 udevd
  663 root      20   0   0    0    0 S0.00.0   0:00.00 virtio-net
  684 root      20   0   0    0    0 S0.00.0   0:00.00 vballoon
  843 root      20   0   0    0    0 S0.00.0   0:00.00 kauditd
  846 root      20   01488628544 S0.00.014:07.76 aliyun-service
  886 root      20   0   0    0    0 S0.00.0   0:00.06 ib_addr
  891 root      20   0   0    0    0 S0.00.0   0:00.00 infiniband/0
  892 root      20   0   0    0    0 S0.00.0   0:00.00 infiniband/1
  901 root      20   0   0    0    0 S0.00.0   0:00.00 ib_mcast
  906 root      20   0   0    0    0 S0.00.0   0:00.00 iw_cm_wq
  911 root      18-2 10792892328 S0.00.0   0:00.00 udevd
  912 root      20   0   0    0    0 S0.00.0   0:00.00 ib_cm/0
  913 root      20   0   0    0    0 S0.00.0   0:00.00 ib_cm/1
  918 root      20   0   0    0    0 S0.00.0   0:00.00 rdma_cm
  939 root      20   0   0    0    0 S0.00.0   0:00.00 ipoib_flush
  1062 root      20   0   0    0    0 S0.00.0   0:08.54 flush-252:0
  1123 root      20   0245m 5192 1120 S0.00.1   0:06.21 rsyslogd
  1145 nscd      20   0615m 1516 1012 S0.00.0   0:14.69 nscd
  1203 root      20   0   0    0    0 S0.00.0   0:00.00 cqueue
  1226 root      20   0 66256 1200468 S0.00.0   0:01.14 sshd
  1237 ntp       20   0 26600 1688 1188 S0.00.0   0:11.36 ntpd
  1257 exim      20   0 93688 1896868 S0.00.0   0:00.33 exim
  1283 root      20   0114m 1288672 S0.00.0   0:16.22 crond
  1339 root      20   04060548472 S0.00.0   0:00.00 mingetty
  1341 root      20   04060544472 S0.00.0   0:00.00 mingetty
  1343 root      20   04060548472 S0.00.0   0:00.00 mingetty
  1345 root      20   04060544472 S0.00.0   0:00.00 mingetty
  1347 root      20   04060548472 S0.00.0   0:00.00 mingetty
  1349 root      20   04060544472 S0.00.0   0:00.00 mingetty
  1350 root      18-2 10792880316 S0.00.0   0:00.00 udevd
  1396 root      20   0 11340 1400 1140 S0.00.0   0:00.00 mysqld_safe
  1548 mysql   20   0 1694m 458m 7928 S0.0 11.6   6:17.59 mysqld
  4810 root      20   0 24608 2664 2040 S0.00.1   1:45.30 AliYunDunUpdate
  4840 root      20   0121m13m 8460 S0.00.3   7:47.17 AliYunDun
  23353 root      20   0100m 4384 3360 S0.00.1   0:00.02 sshd
  23355 gstudent20   0100m 1836812 S0.00.0   0:00.00 sshd
  23356 gstudent20   0 15024 1088828 R0.00.0   0:00.00 top
  commands :free -m
  ######## ip: 192.168.41.11######2018:3:4:16:9:47====
  total       used       free   shared    buffers   cached
  Mem:          3961       1366       2594          0      240      484
  -/+ buffers/cache:      641       3319
  Swap:            0          0          0
  commands :vmstat 1 1
  ######## ip: 192.168.41.11######2018:3:4:16:9:47====
  procs -----------memory---------- ---swap-- -----io---- --system-- -----cpu-----

  rb   swpd   free   buffcache   si   so    bi    bo   in   cs us sy>  00      0 2656960 246380 496020    0    0   0   1    1    500 10000
页: [1]
查看完整版本: python获取linux中top信息