mirror of
https://github.com/usmannasir/cyberpanel.git
synced 2026-02-28 01:10:44 +01:00
backups to aws s3
This commit is contained in:
@@ -636,4 +636,143 @@ app.controller('lswsSwitch', function ($scope, $http, $timeout, $window) {
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
app.controller('topProcesses', function ($scope, $http, $timeout) {
|
||||
|
||||
$scope.cyberPanelLoading = true;
|
||||
|
||||
$scope.topProcessesStatus = function () {
|
||||
|
||||
$scope.cyberPanelLoading = false;
|
||||
|
||||
url = "/serverstatus/topProcessesStatus";
|
||||
|
||||
var data = {};
|
||||
|
||||
var config = {
|
||||
headers: {
|
||||
'X-CSRFToken': getCookie('csrftoken')
|
||||
}
|
||||
};
|
||||
|
||||
$http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas);
|
||||
|
||||
|
||||
function ListInitialDatas(response) {
|
||||
$scope.cyberPanelLoading = true;
|
||||
if (response.data.status === 1) {
|
||||
$scope.processes = JSON.parse(response.data.data);
|
||||
|
||||
//CPU Details
|
||||
$scope.cores = response.data.cores;
|
||||
$scope.modelName = response.data.modelName;
|
||||
$scope.cpuMHZ = response.data.cpuMHZ;
|
||||
$scope.cacheSize = response.data.cacheSize;
|
||||
|
||||
//CPU Load
|
||||
$scope.cpuNow = response.data.cpuNow;
|
||||
$scope.cpuOne = response.data.cpuOne;
|
||||
$scope.cpuFive = response.data.cpuFive;
|
||||
$scope.cpuFifteen = response.data.cpuFifteen;
|
||||
|
||||
//CPU Time spent
|
||||
$scope.ioWait = response.data.ioWait;
|
||||
$scope.idleTime = response.data.idleTime;
|
||||
$scope.hwInterrupts = response.data.hwInterrupts;
|
||||
$scope.Softirqs = response.data.Softirqs;
|
||||
|
||||
//Memory
|
||||
$scope.totalMemory = response.data.totalMemory;
|
||||
$scope.freeMemory = response.data.freeMemory;
|
||||
$scope.usedMemory = response.data.usedMemory;
|
||||
$scope.buffCache = response.data.buffCache;
|
||||
|
||||
//Swap
|
||||
$scope.swapTotalMemory = response.data.swapTotalMemory;
|
||||
$scope.swapFreeMemory = response.data.swapFreeMemory;
|
||||
$scope.swapUsedMemory = response.data.swapUsedMemory;
|
||||
$scope.swapBuffCache = response.data.swapBuffCache;
|
||||
|
||||
//Processes
|
||||
$scope.totalProcesses = response.data.totalProcesses;
|
||||
$scope.runningProcesses = response.data.runningProcesses;
|
||||
$scope.sleepingProcesses = response.data.sleepingProcesses;
|
||||
$scope.stoppedProcesses = response.data.stoppedProcesses;
|
||||
$scope.zombieProcesses = response.data.zombieProcesses;
|
||||
|
||||
$timeout($scope.topProcessesStatus, 3000);
|
||||
}
|
||||
else {
|
||||
new PNotify({
|
||||
title: 'Operation Failed!',
|
||||
text: response.data.error_message,
|
||||
type: 'error'
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function cantLoadInitialDatas(response) {
|
||||
$scope.cyberPanelLoading = true;
|
||||
new PNotify({
|
||||
title: 'Operation Failed!',
|
||||
text: 'Could not connect to server, please refresh this page',
|
||||
type: 'error'
|
||||
});
|
||||
}
|
||||
|
||||
};
|
||||
$scope.topProcessesStatus();
|
||||
|
||||
$scope.killProcess = function (pid) {
|
||||
|
||||
$scope.cyberPanelLoading = false;
|
||||
|
||||
url = "/serverstatus/killProcess";
|
||||
|
||||
var data = {
|
||||
pid: pid
|
||||
};
|
||||
|
||||
var config = {
|
||||
headers: {
|
||||
'X-CSRFToken': getCookie('csrftoken')
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
$http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas);
|
||||
|
||||
|
||||
function ListInitialDatas(response) {
|
||||
$scope.cyberPanelLoading = true;
|
||||
if (response.data.status === 1) {
|
||||
new PNotify({
|
||||
title: 'Success',
|
||||
text: 'Process successfully killed.',
|
||||
type: 'success'
|
||||
});
|
||||
}
|
||||
else {
|
||||
new PNotify({
|
||||
title: 'Operation Failed!',
|
||||
text: response.data.error_message,
|
||||
type: 'error'
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function cantLoadInitialDatas(response) {
|
||||
$scope.cyberPanelLoading = true;
|
||||
new PNotify({
|
||||
title: 'Operation Failed!',
|
||||
text: 'Could not connect to server, please refresh this page',
|
||||
type: 'error'
|
||||
});
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
});
|
||||
229
serverStatus/templates/serverStatus/topProcesses.html
Normal file
229
serverStatus/templates/serverStatus/topProcesses.html
Normal file
@@ -0,0 +1,229 @@
|
||||
{% extends "baseTemplate/index.html" %}
|
||||
{% load i18n %}
|
||||
{% block title %}{% trans "Top Processes - CyberPanel" %}{% endblock %}
|
||||
{% block content %}
|
||||
|
||||
{% load static %}
|
||||
{% get_current_language as LANGUAGE_CODE %}
|
||||
<!-- Current language: {{ LANGUAGE_CODE }} -->
|
||||
|
||||
|
||||
<div ng-controller="topProcesses" class="container">
|
||||
|
||||
<div id="page-title">
|
||||
<h2>{% trans "Top Processes" %} <img height="20px" ng-hide="cyberPanelLoading"
|
||||
src="/static/images/loading.gif"></h2>
|
||||
<p>{% trans "List of top processes on your server. (Refresh every 3 seconds)" %}</p>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-md-6">
|
||||
<div class="example-box-wrapper">
|
||||
|
||||
<div class="content-box-wrapper">
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr >
|
||||
<th style="background: #3498db;color:white">{% trans 'Cores' %}</th>
|
||||
<th style="background: #3498db;color:white">{% trans 'Model Name' %}</th>
|
||||
<th style="background: #3498db;color:white">{% trans 'CPU Mhz' %}</th>
|
||||
<th style="background: #3498db;color:white">{% trans 'Cache Size' %}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>{$ cores $}</td>
|
||||
<td>{$ modelName $}</td>
|
||||
<td>{$ cpuMHZ $}</td>
|
||||
<td>{$ cacheSize $}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
<div class="example-box-wrapper">
|
||||
<div class="content-box-wrapper">
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th style="background: #3498db;color:white">{% trans 'Processes' %}</th>
|
||||
<th style="background: #3498db;color:white">{% trans 'Running' %}</th>
|
||||
<th style="background: #3498db;color:white">{% trans 'Sleeping' %}</th>
|
||||
<th style="background: #3498db;color:white">{% trans 'Stopped' %}</th>
|
||||
<th style="background: #3498db;color:white">{% trans 'Zombie' %}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>{$ totalProcesses $}</td>
|
||||
<td>{$ runningProcesses $}</td>
|
||||
<td>{$ sleepingProcesses $}</td>
|
||||
<td>{$ stoppedProcesses $}</td>
|
||||
<td>{$ zombieProcesses $}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-md-6">
|
||||
<div class="example-box-wrapper">
|
||||
<div class="content-box-wrapper">
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th style="background: #3498db;color:white">{% trans 'CPU Load' %}</th>
|
||||
<th style="background: #3498db;color:white">{% trans '1 Min' %}</th>
|
||||
<th style="background: #3498db;color:white">{% trans '5 Min' %}</th>
|
||||
<th style="background: #3498db;color:white">{% trans '15 Min' %}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>{$ cpuNow $}</td>
|
||||
<td>{$ cpuOne $}</td>
|
||||
<td>{$ cpuFive $}</td>
|
||||
<td>{$ cpuFifteen $}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
<div class="example-box-wrapper">
|
||||
<div class="content-box-wrapper">
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th style="background: #3498db;color:white">{% trans 'I/O Wait' %}</th>
|
||||
<th style="background: #3498db;color:white">{% trans 'Idle Time' %}</th>
|
||||
<th style="background: #3498db;color:white">{% trans 'HW Interrupts' %}</th>
|
||||
<th style="background: #3498db;color:white">{% trans 'Softirqs' %}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>{$ ioWait $}</td>
|
||||
<td>{$ idleTime $}</td>
|
||||
<td>{$ hwInterrupts $}</td>
|
||||
<td>{$ Softirqs $}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-md-6">
|
||||
<div class="example-box-wrapper">
|
||||
<div class="content-box-wrapper">
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th style="background: #3498db;color:white">{% trans 'Memory' %}</th>
|
||||
<th style="background: #3498db;color:white">{% trans 'Free' %}</th>
|
||||
<th style="background: #3498db;color:white">{% trans 'Used' %}</th>
|
||||
<th style="background: #3498db;color:white">{% trans 'buff/cache' %}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>{$ totalMemory $}</td>
|
||||
<td>{$ freeMemory $}</td>
|
||||
<td>{$ usedMemory $}</td>
|
||||
<td>{$ buffCache $}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
<div class="example-box-wrapper">
|
||||
<div class="content-box-wrapper">
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th style="background: #3498db;color:white">{% trans 'SWAP' %}</th>
|
||||
<th style="background: #3498db;color:white">{% trans 'Free' %}</th>
|
||||
<th style="background: #3498db;color:white">{% trans 'Used' %}</th>
|
||||
<th style="background: #3498db;color:white">{% trans 'buff/cache' %}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>{$ swapTotalMemory $}</td>
|
||||
<td>{$ swapFreeMemory $}</td>
|
||||
<td>{$ swapUsedMemory $}</td>
|
||||
<td>{$ swapBuffCache $}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
<div class="example-box-wrapper">
|
||||
<h3 style="background:#3498db; color: white" class="content-box-header bg-black">
|
||||
{% trans 'Top Processes' %}
|
||||
</h3>
|
||||
<div class="content-box-wrapper">
|
||||
|
||||
<div style="margin-top: 2%; margin-bottom: 2%" class="row">
|
||||
|
||||
<div class="col-sm-12">
|
||||
<input placeholder="Search..." ng-model="search" name="dom" type="text"
|
||||
class="form-control" ng-model="domainNameCreate" required>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>{% trans 'PID' %}</th>
|
||||
<th>{% trans 'User' %}</th>
|
||||
<th>{% trans 'VIRT' %}</th>
|
||||
<th>{% trans 'RES' %}</th>
|
||||
<th>{% trans 'State' %}</th>
|
||||
<th>{% trans '%CPU' %}</th>
|
||||
<th>{% trans '%MEM' %}</th>
|
||||
<th>{% trans 'Time' %}</th>
|
||||
<th>{% trans 'Command' %}</th>
|
||||
<th>{% trans 'Actions' %}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr ng-repeat="process in processes | filter:search">
|
||||
<td ng-bind="process.PID"></td>
|
||||
<td ng-bind="process.User"></td>
|
||||
<td ng-bind="process.VIRT"></td>
|
||||
<td ng-bind="process.RES"></td>
|
||||
<td ng-bind="process.S"></td>
|
||||
<td ng-bind="process.CPU"></td>
|
||||
<td ng-bind="process.MEM"></td>
|
||||
<td ng-bind="process.Time"></td>
|
||||
<td ng-bind="process.Command"></td>
|
||||
<td>
|
||||
<button ng-click="killProcess(process.PID)" class="btn btn-danger">KILL</button>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{% endblock %}
|
||||
@@ -15,5 +15,8 @@ urlpatterns = [
|
||||
url(r'^switchTOLSWSStatus$', views.switchTOLSWSStatus, name='switchTOLSWSStatus'),
|
||||
url(r'^licenseStatus$', views.licenseStatus, name='licenseStatus'),
|
||||
url(r'^changeLicense$', views.changeLicense, name='changeLicense'),
|
||||
url(r'^topProcesses$', views.topProcesses, name='topProcesses'),
|
||||
url(r'^topProcessesStatus$', views.topProcessesStatus, name='topProcessesStatus'),
|
||||
url(r'^killProcess$', views.killProcess, name='killProcess'),
|
||||
|
||||
]
|
||||
@@ -16,6 +16,7 @@ from plogical.virtualHostUtilities import virtualHostUtilities
|
||||
import time
|
||||
import serverStatusUtil
|
||||
from plogical.processUtilities import ProcessUtilities
|
||||
from plogical.httpProc import httpProc
|
||||
# Create your views here.
|
||||
|
||||
def serverStatusHome(request):
|
||||
@@ -436,6 +437,172 @@ def changeLicense(request):
|
||||
final_json = json.dumps(final_dic)
|
||||
return HttpResponse(final_json)
|
||||
|
||||
except BaseException, msg:
|
||||
final_dic = {'status': 0, 'erroMessage': str(msg)}
|
||||
final_json = json.dumps(final_dic)
|
||||
return HttpResponse(final_json)
|
||||
except KeyError, msg:
|
||||
final_dic = {'status': 0, 'erroMessage': str(msg)}
|
||||
final_json = json.dumps(final_dic)
|
||||
return HttpResponse(final_json)
|
||||
|
||||
def topProcesses(request):
|
||||
try:
|
||||
userID = request.session['userID']
|
||||
currentACL = ACLManager.loadedACL(userID)
|
||||
|
||||
if currentACL['admin'] == 1:
|
||||
pass
|
||||
else:
|
||||
return ACLManager.loadError()
|
||||
|
||||
templateName = "serverStatus/topProcesses.html"
|
||||
proc = httpProc(request, templateName)
|
||||
return proc.renderPre()
|
||||
|
||||
except KeyError,msg:
|
||||
logging.CyberCPLogFileWriter.writeToFile(str(msg) + "[litespeedStatus]")
|
||||
return redirect(loadLoginPage)
|
||||
|
||||
def topProcessesStatus(request):
|
||||
try:
|
||||
|
||||
with open("/home/cyberpanel/top", "w") as outfile:
|
||||
subprocess.call("sudo top -n1 -b", shell=True, stdout=outfile)
|
||||
|
||||
data = open('/home/cyberpanel/top', 'r').readlines()
|
||||
|
||||
json_data = "["
|
||||
checker = 0
|
||||
counter = 0
|
||||
|
||||
loadAVG = data[0].split(' ')
|
||||
loadAVG = filter(lambda a: a != '', loadAVG)
|
||||
logging.CyberCPLogFileWriter.writeToFile(str(loadAVG))
|
||||
|
||||
loadNow = data[2].split(' ')
|
||||
loadNow = filter(lambda a: a != '', loadNow)
|
||||
|
||||
|
||||
memory = data[3].split(' ')
|
||||
memory = filter(lambda a: a != '', memory)
|
||||
|
||||
swap = data[4].split(' ')
|
||||
swap = filter(lambda a: a != '', swap)
|
||||
|
||||
processes = data[1].split(' ')
|
||||
processes = filter(lambda a: a != '', processes)
|
||||
|
||||
|
||||
for items in data:
|
||||
counter = counter + 1
|
||||
if counter <= 7:
|
||||
continue
|
||||
|
||||
points = items.split(' ')
|
||||
points = filter(lambda a: a != '', points)
|
||||
|
||||
dic = {'PID': points[0], 'User': points[1], 'VIRT': points[4],
|
||||
'RES': points[5], 'S': points[7], 'CPU': points[8], 'MEM': points[9],
|
||||
'Time': points[10], 'Command': points[11]
|
||||
}
|
||||
|
||||
if checker == 0:
|
||||
json_data = json_data + json.dumps(dic)
|
||||
checker = 1
|
||||
else:
|
||||
json_data = json_data + ',' + json.dumps(dic)
|
||||
|
||||
|
||||
json_data = json_data + ']'
|
||||
|
||||
data = {}
|
||||
data['status'] = 1
|
||||
data['error_message'] = 'None'
|
||||
data['data'] = json_data
|
||||
|
||||
## CPU
|
||||
data['cpuNow'] = loadNow[1]
|
||||
data['cpuOne'] = loadAVG[-3].rstrip(',')
|
||||
data['cpuFive'] = loadAVG[-2].rstrip(',')
|
||||
data['cpuFifteen'] = loadAVG[-1]
|
||||
|
||||
## CPU Time spent
|
||||
|
||||
data['ioWait'] = loadNow[9] + '%'
|
||||
data['idleTime'] = loadNow[7] + '%'
|
||||
data['hwInterrupts'] = loadNow[11] + '%'
|
||||
data['Softirqs'] = loadNow[13] + '%'
|
||||
|
||||
## Memory
|
||||
data['totalMemory'] = str(int(float(memory[3])/1024)) + 'MB'
|
||||
data['freeMemory'] = str(int(float(memory[5])/1024)) + 'MB'
|
||||
data['usedMemory'] = str(int(float(memory[7])/1024)) + 'MB'
|
||||
data['buffCache'] = str(int(float(memory[9])/1024)) + 'MB'
|
||||
|
||||
## Swap
|
||||
|
||||
data['swapTotalMemory'] = str(int(float(swap[2]) / 1024)) + 'MB'
|
||||
data['swapFreeMemory'] = str(int(float(swap[4]) / 1024)) + 'MB'
|
||||
data['swapUsedMemory'] = str(int(float(swap[6]) / 1024)) + 'MB'
|
||||
data['swapBuffCache'] = str(int(float(swap[8]) / 1024)) + 'MB'
|
||||
|
||||
## Processes
|
||||
|
||||
data['totalProcesses'] = processes[1]
|
||||
data['runningProcesses'] = processes[3]
|
||||
data['sleepingProcesses'] = processes[5]
|
||||
data['stoppedProcesses'] = processes[7]
|
||||
data['zombieProcesses'] = processes[9]
|
||||
|
||||
## CPU Details
|
||||
|
||||
command = 'sudo cat /proc/cpuinfo'
|
||||
output = subprocess.check_output(shlex.split(command)).splitlines()
|
||||
|
||||
import psutil
|
||||
|
||||
data['cores'] = psutil.cpu_count()
|
||||
|
||||
for items in output:
|
||||
if items.find('model name') > -1:
|
||||
modelName = items.split(':')[1].strip(' ')
|
||||
index = modelName.find('CPU')
|
||||
data['modelName'] = modelName[0:index]
|
||||
elif items.find('cpu MHz') > -1:
|
||||
data['cpuMHZ'] = items.split(':')[1].strip(' ')
|
||||
elif items.find('cache size') > -1:
|
||||
data['cacheSize'] = items.split(':')[1].strip(' ')
|
||||
break
|
||||
|
||||
final_json = json.dumps(data)
|
||||
return HttpResponse(final_json)
|
||||
|
||||
except BaseException, msg:
|
||||
data_ret = {'status': 0, 'error_message': str(msg)}
|
||||
json_data = json.dumps(data_ret)
|
||||
return HttpResponse(json_data)
|
||||
|
||||
def killProcess(request):
|
||||
try:
|
||||
userID = request.session['userID']
|
||||
|
||||
try:
|
||||
currentACL = ACLManager.loadedACL(userID)
|
||||
|
||||
if currentACL['admin'] == 1:
|
||||
pass
|
||||
else:
|
||||
return ACLManager.loadErrorJson('status', 0)
|
||||
|
||||
data = json.loads(request.body)
|
||||
pid = data['pid']
|
||||
|
||||
ProcessUtilities.executioner('sudo kill ' + pid)
|
||||
|
||||
proc = httpProc(request, None)
|
||||
return proc.ajax(1, None)
|
||||
|
||||
except BaseException, msg:
|
||||
final_dic = {'status': 0, 'erroMessage': str(msg)}
|
||||
final_json = json.dumps(final_dic)
|
||||
|
||||
Reference in New Issue
Block a user