-
Notifications
You must be signed in to change notification settings - Fork 24
/
monitor_process.py
45 lines (40 loc) · 1.21 KB
/
monitor_process.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import psutil
import time
import sys
from ISStreamer.Streamer import Streamer
from subprocess import PIPE, Popen
# --------- User Settings ---------
# Initial State settings
BUCKET_NAME = ":computer: Processes"
BUCKET_KEY = "pr1208"
ACCESS_KEY = "PLACE YOUR INITIAL STATE ACCESS KEY HERE"
PROCESS_NAME = "PLACE THE NAME OF YOUR PROCESS HERE"
# Set the time between checks
MINUTES_BETWEEN_READS = 15
# ---------------------------------
def main():
if len(sys.argv) != 2:
print "Usage: " + sys.argv[0] + " <pid>"
exit()
pid = sys.argv[1]
streamer = Streamer(bucket_name=BUCKET_NAME, bucket_key=BUCKET_KEY, access_key=ACCESS_KEY)
if psutil.pid_exists(int(pid)) == False:
print "Error: That process doesn't exist! Exiting ..."
exit()
else:
streamer.log(PROCESS_NAME,"Running")
streamer.flush()
while True:
if psutil.pid_exists(int(pid)) == False:
streamer.log(PROCESS_NAME,"Exited")
streamer.flush()
exit()
else:
streamer.log(PROCESS_NAME,"Running")
process = Popen(['hostname', '-I'], stdout=PIPE)
output, _error = process.communicate()
streamer.log(PROCESS_NAME + " IP Address", output.rstrip())
streamer.flush()
time.sleep(60*MINUTES_BETWEEN_READS)
if __name__ == "__main__":
main()