2015-06-16 18:42:36 +03:00
Ext . define ( 'PVE.dc.Summary' , {
extend : 'Ext.panel.Panel' ,
2016-10-28 14:11:46 +03:00
alias : 'widget.pveDcSummary' ,
2015-06-16 18:42:36 +03:00
2016-10-28 14:11:46 +03:00
scrollable : true ,
2018-02-23 12:31:57 +03:00
bodyPadding : 5 ,
2016-10-28 14:11:46 +03:00
layout : 'column' ,
defaults : {
2018-02-23 12:31:57 +03:00
padding : 5 ,
2019-12-04 15:41:35 +03:00
columnWidth : 1 ,
2016-10-28 14:11:46 +03:00
} ,
items : [
2016-10-28 14:11:47 +03:00
{
itemId : 'dcHealth' ,
2020-06-02 13:23:51 +03:00
xtype : 'pveDcHealth' ,
2016-10-28 14:11:47 +03:00
} ,
{
itemId : 'dcGuests' ,
2020-06-02 13:23:51 +03:00
xtype : 'pveDcGuests' ,
2016-10-28 14:11:47 +03:00
} ,
{
2017-01-18 19:03:32 +03:00
title : gettext ( 'Resources' ) ,
2016-10-28 14:11:47 +03:00
xtype : 'panel' ,
2018-02-23 12:31:57 +03:00
minHeight : 250 ,
bodyPadding : 5 ,
2017-06-14 10:22:23 +03:00
layout : 'hbox' ,
2016-10-28 14:11:47 +03:00
defaults : {
2017-12-11 16:57:13 +03:00
xtype : 'proxmoxGauge' ,
2021-01-19 19:31:03 +03:00
flex : 1 ,
2016-10-28 14:11:47 +03:00
} ,
2021-01-19 19:39:15 +03:00
items : [
2016-10-28 14:11:47 +03:00
{
title : gettext ( 'CPU' ) ,
2021-01-19 19:31:03 +03:00
itemId : 'cpu' ,
2016-10-28 14:11:47 +03:00
} ,
{
title : gettext ( 'Memory' ) ,
2021-01-19 19:31:03 +03:00
itemId : 'memory' ,
2016-10-28 14:11:47 +03:00
} ,
{
title : gettext ( 'Storage' ) ,
2021-01-19 19:31:03 +03:00
itemId : 'storage' ,
} ,
] ,
2016-10-28 14:11:47 +03:00
} ,
2016-10-28 14:11:46 +03:00
{
itemId : 'nodeview' ,
xtype : 'pveDcNodeView' ,
2021-01-19 19:31:03 +03:00
height : 250 ,
2019-03-01 16:27:49 +03:00
} ,
{
title : gettext ( 'Subscriptions' ) ,
height : 220 ,
items : [
{
itemId : 'subscriptions' ,
2019-04-05 14:02:46 +03:00
xtype : 'pveHealthWidget' ,
userCls : 'pointer' ,
listeners : {
element : 'el' ,
click : function ( ) {
if ( this . component . userCls === 'pointer' ) {
window . open ( 'https://www.proxmox.com/en/proxmox-ve/pricing' , '_blank' ) ;
}
2021-01-19 19:31:03 +03:00
} ,
} ,
} ,
] ,
} ,
2016-10-28 14:11:46 +03:00
] ,
2015-06-16 18:42:36 +03:00
2019-12-04 15:41:35 +03:00
listeners : {
resize : function ( panel ) {
2021-04-19 14:00:47 +03:00
Proxmox . Utils . updateColumns ( panel ) ;
2019-12-04 15:41:35 +03:00
} ,
} ,
2015-06-16 18:42:36 +03:00
initComponent : function ( ) {
var me = this ;
2018-01-15 17:18:00 +03:00
var rstore = Ext . create ( 'Proxmox.data.UpdateStore' , {
2016-10-28 14:11:46 +03:00
interval : 3000 ,
storeid : 'pve-cluster-status' ,
model : 'pve-dc-nodes' ,
proxy : {
2017-12-11 16:46:51 +03:00
type : 'proxmox' ,
2021-01-19 19:31:03 +03:00
url : "/api2/json/cluster/status" ,
} ,
2015-06-16 18:42:36 +03:00
} ) ;
2017-12-11 14:05:39 +03:00
var gridstore = Ext . create ( 'Proxmox.data.DiffStore' , {
2016-10-28 14:11:46 +03:00
rstore : rstore ,
filters : {
property : 'type' ,
2021-01-19 19:31:03 +03:00
value : 'node' ,
2016-10-28 14:11:46 +03:00
} ,
sorters : {
property : 'id' ,
2021-01-19 19:31:03 +03:00
direction : 'ASC' ,
} ,
2015-06-16 18:42:36 +03:00
} ) ;
me . callParent ( ) ;
2016-10-28 14:11:46 +03:00
me . getComponent ( 'nodeview' ) . setStore ( gridstore ) ;
2016-10-28 14:11:47 +03:00
var gueststatus = me . getComponent ( 'dcGuests' ) ;
var cpustat = me . down ( '#cpu' ) ;
var memorystat = me . down ( '#memory' ) ;
var storagestat = me . down ( '#storage' ) ;
2016-12-21 13:45:10 +03:00
var sp = Ext . state . Manager . getProvider ( ) ;
2016-10-28 14:11:47 +03:00
me . mon ( PVE . data . ResourceStore , 'load' , function ( curstore , results ) {
me . suspendLayout = true ;
2021-05-18 14:54:00 +03:00
let cpu = 0 , maxcpu = 0 ;
let memory = 0 , maxmem = 0 ;
let used = 0 , total = 0 ;
let countedStorage = { } , usableStorages = { } ;
let storages = sp . get ( 'dash-storages' ) || '' ;
storages . split ( ',' ) . filter ( v => v !== '' ) . forEach ( storage => {
usableStorages [ storage ] = true ;
2016-12-21 13:45:10 +03:00
} ) ;
2016-10-28 14:11:47 +03:00
2021-05-18 14:54:00 +03:00
let qemu = {
2016-10-28 14:11:47 +03:00
running : 0 ,
paused : 0 ,
stopped : 0 ,
2021-01-19 19:31:03 +03:00
template : 0 ,
2016-10-28 14:11:47 +03:00
} ;
2021-05-18 14:54:00 +03:00
let lxc = {
2016-10-28 14:11:47 +03:00
running : 0 ,
paused : 0 ,
stopped : 0 ,
2021-01-19 19:31:03 +03:00
template : 0 ,
2016-10-28 14:11:47 +03:00
} ;
2021-05-18 14:54:00 +03:00
let error = 0 ;
2016-10-28 14:11:47 +03:00
2021-05-18 14:54:00 +03:00
for ( const { data } of results ) {
switch ( data . type ) {
2016-10-28 14:11:47 +03:00
case 'node' :
2021-05-18 14:54:00 +03:00
cpu += data . cpu * data . maxcpu ;
maxcpu += data . maxcpu || 0 ;
memory += data . mem || 0 ;
maxmem += data . maxmem || 0 ;
if ( gridstore . getById ( data . id ) ) {
let griditem = gridstore . getById ( data . id ) ;
griditem . set ( 'cpuusage' , data . cpu ) ;
let max = data . maxmem || 1 ;
let val = data . mem || 0 ;
griditem . set ( 'memoryusage' , val / max ) ;
griditem . set ( 'uptime' , data . uptime ) ;
griditem . commit ( ) ; // else the store marks the field as dirty
2016-10-28 14:11:47 +03:00
}
break ;
2021-05-18 14:54:00 +03:00
case 'storage' : {
let sid = ! data . shared || data . storage === 'local' ? data . id : data . storage ;
2016-12-21 13:45:10 +03:00
if ( ! Ext . Object . isEmpty ( usableStorages ) ) {
2021-05-18 14:54:00 +03:00
if ( usableStorages [ data . id ] !== true ) {
break ;
2016-12-21 13:45:10 +03:00
}
2021-05-18 14:54:00 +03:00
sid = data . id ;
} else if ( countedStorage [ sid ] ) {
2016-12-21 13:45:10 +03:00
break ;
}
2021-05-18 14:54:00 +03:00
used += data . disk ;
total += data . maxdisk ;
countedStorage [ sid ] = true ;
2016-10-28 14:11:47 +03:00
break ;
2021-05-18 14:54:00 +03:00
}
2016-10-28 14:11:47 +03:00
case 'qemu' :
2021-05-18 14:54:00 +03:00
qemu [ data . template ? 'template' : data . status ] ++ ;
if ( data . hastate === 'error' ) {
2016-10-28 14:11:47 +03:00
error ++ ;
}
break ;
case 'lxc' :
2021-05-18 14:54:00 +03:00
lxc [ data . template ? 'template' : data . status ] ++ ;
if ( data . hastate === 'error' ) {
2016-10-28 14:11:47 +03:00
error ++ ;
}
break ;
default : break ;
}
}
2021-05-18 14:54:00 +03:00
let text = Ext . String . format ( gettext ( 'of {0} CPU(s)' ) , maxcpu ) ;
2021-01-19 19:42:36 +03:00
cpustat . updateValue ( cpu / maxcpu , text ) ;
2016-10-28 14:11:47 +03:00
2021-04-19 14:00:45 +03:00
text = Ext . String . format ( gettext ( '{0} of {1}' ) , Proxmox . Utils . render _size ( memory ) , Proxmox . Utils . render _size ( maxmem ) ) ;
2021-01-19 19:42:36 +03:00
memorystat . updateValue ( memory / maxmem , text ) ;
2016-10-28 14:11:47 +03:00
2021-04-19 14:00:45 +03:00
text = Ext . String . format ( gettext ( '{0} of {1}' ) , Proxmox . Utils . render _size ( used ) , Proxmox . Utils . render _size ( total ) ) ;
2021-01-19 19:42:36 +03:00
storagestat . updateValue ( used / total , text ) ;
2016-10-28 14:11:47 +03:00
2021-01-19 19:31:03 +03:00
gueststatus . updateValues ( qemu , lxc , error ) ;
2016-10-28 14:11:47 +03:00
me . suspendLayout = false ;
me . updateLayout ( true ) ;
} ) ;
2021-05-18 14:54:00 +03:00
let dcHealth = me . getComponent ( 'dcHealth' ) ;
2016-10-28 14:11:47 +03:00
me . mon ( rstore , 'load' , dcHealth . updateStatus , dcHealth ) ;
2021-05-18 14:54:00 +03:00
let subs = me . down ( '#subscriptions' ) ;
2019-03-01 16:27:49 +03:00
me . mon ( rstore , 'load' , function ( store , records , success ) {
var level ;
2019-05-07 20:51:02 +03:00
var mixed = false ;
2021-05-18 14:54:00 +03:00
for ( let i = 0 ; i < records . length ; i ++ ) {
let node = records [ i ] ;
if ( node . get ( 'type' ) !== 'node' || node . get ( 'status' ) === 'offline' ) {
2019-03-01 16:27:49 +03:00
continue ;
}
2019-05-03 15:06:13 +03:00
2021-05-18 14:54:00 +03:00
let curlevel = node . get ( 'level' ) ;
if ( curlevel === '' ) { // no subscription beats all, set it and break the loop
2019-05-03 15:06:13 +03:00
level = '' ;
break ;
}
2019-03-01 16:27:49 +03:00
2019-05-07 20:49:43 +03:00
if ( level === undefined ) { // save level
2019-03-01 16:27:49 +03:00
level = curlevel ;
2019-05-07 20:51:02 +03:00
} else if ( level !== curlevel ) { // detect different levels
mixed = true ;
2019-03-01 16:27:49 +03:00
}
}
2021-05-18 14:54:00 +03:00
let data = {
2019-05-03 15:06:13 +03:00
title : Proxmox . Utils . unknownText ,
text : Proxmox . Utils . unknownText ,
2021-01-19 19:31:03 +03:00
iconCls : PVE . Utils . get _health _icon ( undefined , true ) ,
2019-05-03 15:06:13 +03:00
} ;
2019-03-01 16:27:49 +03:00
if ( level === '' ) {
2019-05-03 15:06:13 +03:00
data = {
2019-03-01 16:27:49 +03:00
title : gettext ( 'No Subscription' ) ,
iconCls : PVE . Utils . get _health _icon ( 'critical' , true ) ,
2021-01-19 19:31:03 +03:00
text : gettext ( 'You have at least one node without subscription.' ) ,
2019-05-03 15:06:13 +03:00
} ;
2019-04-05 14:02:46 +03:00
subs . setUserCls ( 'pointer' ) ;
2019-05-07 20:51:02 +03:00
} else if ( mixed ) {
2019-05-03 15:06:13 +03:00
data = {
2019-03-01 16:27:49 +03:00
title : gettext ( 'Mixed Subscriptions' ) ,
iconCls : PVE . Utils . get _health _icon ( 'warning' , true ) ,
2021-01-19 19:31:03 +03:00
text : gettext ( 'Warning: Your subscription levels are not the same.' ) ,
2019-05-03 15:06:13 +03:00
} ;
2019-04-05 14:02:46 +03:00
subs . setUserCls ( 'pointer' ) ;
2019-05-03 15:06:13 +03:00
} else if ( level ) {
data = {
2019-03-01 16:27:49 +03:00
title : PVE . Utils . render _support _level ( level ) ,
iconCls : PVE . Utils . get _health _icon ( 'good' , true ) ,
2021-01-19 19:31:03 +03:00
text : gettext ( 'Your subscription status is valid.' ) ,
2019-05-03 15:06:13 +03:00
} ;
2019-04-05 14:02:46 +03:00
subs . setUserCls ( '' ) ;
2019-03-01 16:27:49 +03:00
}
2019-05-03 15:06:13 +03:00
subs . setData ( data ) ;
2019-03-01 16:27:49 +03:00
} ) ;
2021-01-19 19:39:15 +03:00
me . on ( 'destroy' , function ( ) {
2016-10-28 14:11:46 +03:00
rstore . stopUpdate ( ) ;
} ) ;
2019-12-04 15:41:36 +03:00
me . mon ( sp , 'statechange' , function ( provider , key , value ) {
if ( key !== 'summarycolumns' ) {
return ;
}
2021-04-19 14:00:47 +03:00
Proxmox . Utils . updateColumns ( me ) ;
2019-12-04 15:41:36 +03:00
} ) ;
2016-10-28 14:11:46 +03:00
rstore . startUpdate ( ) ;
2021-01-19 19:31:03 +03:00
} ,
2016-10-28 14:11:47 +03:00
2015-06-16 18:42:36 +03:00
} ) ;