-
Notifications
You must be signed in to change notification settings - Fork 41
/
Copy pathcloudlinux.py
42 lines (32 loc) · 1020 Bytes
/
cloudlinux.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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
import plugins
import json
class Plugin(plugins.BasePlugin):
__name__ = 'cloudlinux'
def run(self, config):
'''
Beta plugin to monitor cloudlinux users
Requires sudo access to lveinfo (whereis lveinfo) add to /etc/sudoers:
nixstats ALL=(ALL) NOPASSWD: /REPLACE/PATH/TO/lveinfo
To enable add to /etc/nixstats.ini:
[cloudlinux]
enabled = yes
'''
data = os.popen('sudo lveinfo -d --period 5m -o cpu_avg -l 20 --json').read()
results = {}
try:
data = json.loads(data)
except Exception:
return "Could not load lveinfo data"
if data['success'] is not 1:
return "Failed to load lveinfo"
results = {}
for line in data['data']:
username = line['ID']
del line['ID']
results[username] = line
return results
if __name__ == '__main__':
Plugin().execute()