-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdatadust.py
More file actions
120 lines (81 loc) · 3.09 KB
/
datadust.py
File metadata and controls
120 lines (81 loc) · 3.09 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
'''
Copyright (C) 2015 Yeshwanth Kumar <morpheyesh@gmail.com>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, see <http://www.gnu.org/licenses/>.
'''
#!/usr/bin/env python
import sys
import subprocess
import platform
import sched
import time
import os
from system_level import system_level
from ddDaemon import Daemon
if (sys.version_info[1]) <= 6:
print("Its recommended to use python version 2.7 or above. 2.7 is the best!")
sys.exit(1)
ddConfig = {
'version': '0.1.0',
'interval': 5
}
def no_of_cores():
greppy = subprocess.Popen(['grep', 'cpu cores', '/proc/cpuinfo'], stdout=subprocess.PIPE, close_fds = True, shell = True)
printLine = subprocess.Popen(['wc -l'], stdin=greppy.stdout, stdout=subprocess.PIPE, close_fds = True, shell = True)
noOfCores = printLine.communicate()[0]
return int(noOfCores)
class datadust_agent(Daemon):
#def run(self):
BasicStats = {
'processorType': platform.processor(),
'noOfCores': no_of_cores(),
'os': sys.platform,
'nixDist': platform.dist(),
'hostname' : os.uname()[1]
}
#expand later when more dist support!(.)
#system_level instance
sysLevel = system_level(ddConfig)
schedule = sched.scheduler(time.time, time.sleep)
sysLevel.system_levelChecks(schedule, True, BasicStats)
schedule.run()
if __name__ == '__main__':
argL = len(sys.argv)
#need to do logging - logFile(.)
ddConfig['pidfileDirectory'] = '/tmp/'
pidFile = None
if argL == 3 or argL == 4:
if sys.argv[2] == 'init':
if os.path.exists('/var/run/datadust-agent/'):
pidFile = '/var/run/datadust-agent/datadust-agent.pid'
else:
pidFile = '/var/run/datadust-agent.pid'
else:
pidFile = os.path.join(ddConfig['pidfileDirectory'], 'datadust-agent.pid')
if not os.access(ddConfig['pidfileDirectory'], os.W_OK):
print 'Unable to write the PID file at ' + pidFile
print 'Agent will now quit'
sys.exit(1)
d = datadust_agent(pidFile) #pids..(..)
if argL == 2 or argL == 3 or argL == 4:
if 'start' == sys.argv[1]:
print("Started daemon-->")
d.start()
elif 'stop' == sys.argv[1]:
print("Daemon stopped!")
d.stop()
else:
print 'Check the commands properly!'
sys.exit(1)
sys.exit(0)
else:
print 'usage: %s start|stop|restart|status|update' % sys.argv[0]
sys.exit(1)