Linux

個人服務的正常執行時間

  • January 9, 2017

我在生產伺服器上執行多個獨角獸程序。現在我想檢查我的服務的單個服務正常執行時間。例如,如果任何獨角獸程序自動重啟,它應該開始記錄其正常執行時間。通過這種方式,我想計算自上次服務以來服務的正常執行時間start/restart/reload 注意:這裡我不是在談論伺服器正常執行時間,可以通過使用uptime如下命令知道。

$ uptime
19:11:25 up 2 days, 21:28,  1 user,  load average: 0.11, 0.09, 0.11

我想知道單個服務的正常執行時間,比如 nginx 的正常執行時間

有可能以某種方式知道嗎?

Monit非常適合這個。

monit status命令清楚地顯示了此資訊:

Process 'ssh'
 status                            Running
 monitoring status                 Monitored
 pid                               11239
 parent pid                        1
 uid                               0
 effective uid                     0
 gid                               0
 uptime                            32d 5h 1m
 children                          230
 memory                            1.2 MB
 memory total                      2.0 GB
 memory percent                    0.0%
 memory percent total              0.6%
 cpu percent                       0.0%
 cpu percent total                 0.1%
 data collected                    Mon, 09 Jan 2017 11:34:08

Process 'cron'
 status                            Running
 monitoring status                 Monitored
 pid                               669744
 parent pid                        1
 uid                               0
 effective uid                     0
 gid                               0
 uptime                            1m
 children                          0
 memory                            1.2 MB
 memory total                      1.2 MB
 memory percent                    0.0%
 memory percent total              0.0%
 cpu percent                       0.0%
 cpu percent total                 0.0%
 data collected                    Mon, 09 Jan 2017 11:34:08

Process 'newrelic'
 status                            Running
 monitoring status                 Monitored
 pid                               11377
 parent pid                        1
 uid                               495
 effective uid                     495
 gid                               495
 uptime                            32d 5h 1m
 children                          1
 memory                            500.0 kB
 memory total                      8.3 MB
 memory percent                    0.0%
 memory percent total              0.0%
 cpu percent                       0.0%
 cpu percent total                 0.0%
 data collected                    Mon, 09 Jan 2017 11:34:08

引用自:https://serverfault.com/questions/825150