Skip to content

Commit

Permalink
xenstats: Add new module
Browse files Browse the repository at this point in the history
  • Loading branch information
marcosmamorim committed Jan 22, 2011
1 parent cb14a3d commit 1563083
Show file tree
Hide file tree
Showing 4 changed files with 286 additions and 0 deletions.
37 changes: 37 additions & 0 deletions xenstats/conf.d/xenstats.pyconf
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
modules {
module {
name = "xenstats"
language = "python"
}
}

collection_group {
collect_every = 15
time_threshold = 30

metric {
name = "xen_vms"
value_threshold = 0
}

metric {
name = "xen_mem_use"
value_threshold = 1.0
}
}

collection_group {
collect_once = yes
time_threshold = 20
metric {
name = "xen_mem"
value_threshold = 1.0
}

metric {
name = "xen_cpu"
value_threshold = 0
}
}


66 changes: 66 additions & 0 deletions xenstats/graph.d/xen_mem_report.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?php
/*
* xen_mem_report.php
*
* Copyright 2011 Marcos Amorim <marcosmamorim@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, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*/

/* Pass in by reference! */
function graph_xen_mem_report ( &$rrdtool_graph ) {

global $context,
$hostname,
$mem_shared_color,
$mem_cached_color,
$mem_buffered_color,
$mem_swapped_color,
$mem_used_color,
$cpu_num_color,
$range,
$rrd_dir,
$size;

$title = 'Xen Memory';
if ($context != 'host') {
$rrdtool_graph['title'] = $title;
} else {
$rrdtool_graph['title'] = "$hostname $title last $range";
}
$rrdtool_graph['lower-limit'] = '0';
$rrdtool_graph['vertical-label'] = 'Bytes';
$rrdtool_graph['extras'] = '--rigid --base 1024';

$series = "DEF:'xen_mem'='${rrd_dir}/xen_mem.rrd':'sum':AVERAGE "
."CDEF:'bxen_mem'=xen_mem,1024,* "

."DEF:'xen_mem_use'='${rrd_dir}/xen_mem_use.rrd':'sum':AVERAGE "
."CDEF:'bxen_mem_use'=xen_mem_use,1024,* "

."CDEF:'bxen_mem_free'='bxen_mem','xen_mem_use',- "

."AREA:'bxen_mem_use'#$mem_used_color:'Memory Used' ";
$series .= "LINE2:'bxen_mem'#$cpu_num_color:'Total In-Core Memory' ";


$rrdtool_graph['series'] = $series;

return $rrdtool_graph;

}

?>
56 changes: 56 additions & 0 deletions xenstats/graph.d/xen_vms_report.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php
/*
* xen_vms_report.php
*
* Copyright 2011 Marcos Amorim <marcosmamorim@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, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*/


/* Pass in by reference! */
function graph_xen_vms_report ( &$rrdtool_graph ) {

global $context,
$hostname,
$mem_cached_color,
$mem_used_color,
$cpu_num_color,
$range,
$rrd_dir,
$size;

$title = 'Virtual Machines';
$rrdtool_graph['height'] += $size == 'medium' ? 28 : 0 ;
if ($context != 'host') {
$rrdtool_graph['title'] = $title;
} else {
$rrdtool_graph['title'] = "$hostname $title last $range";
}
$rrdtool_graph['lower-limit'] = '0';
$rrdtool_graph['vertical-label'] = 'Qtd';
$rrdtool_graph['extras'] = '--rigid --base 1024';

$series = "DEF:'xen_vms'='${rrd_dir}/xen_vms.rrd':'sum':AVERAGE "
."LINE2:'xen_vms'#$mem_used_color:'VMS' ";

$rrdtool_graph['series'] = $series;

return $rrdtool_graph;

}

?>
127 changes: 127 additions & 0 deletions xenstats/python_modules/xenstats.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
# xenstats.py
#
# Copyright 2011 Marcos Amorim <marcosmamorim@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, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA.

import libvirt
import os
import time

descriptors = list()
conn = libvirt.openReadOnly("xen:///")
conn_info = conn.getInfo()

def xen_vms(name):
'''Return number of virtual is running'''
global conn

vm_count = conn.numOfDomains()

return vm_count

def xen_mem(name):
'''Return node memory '''
global conn
global conn_info

# O xen retorna o valor da memoria em MB, vamos passar por KB
return conn_info[1] * 1024

def xen_cpu(name):
'''Return numbers of CPU's'''
global conn
global conn_info

return conn_info[2]


def xen_mem_use(name):
'''Return total memory usage'''
global conn

vm_mem = 0

for id in conn.listDomainsID():
dom = conn.lookupByID(id)
info = dom.info()
vm_mem = vm_mem + info[2]

return vm_mem

def metric_init(params):
global descriptors

d1 = {'name': 'xen_vms',
'call_back': xen_vms,
'time_max': 20,
'value_type': 'uint',
'units': 'Qtd',
'slope': 'both',
'format': '%d',
'description': 'Total number of running vms',
'groups': 'xen',
}
d2 = {'name': 'xen_cpu',
'call_back': xen_cpu,
'time_max': 20,
'value_type': 'uint',
'units': 'CPUs',
'slope': 'both',
'format': '%d',
'description': 'CPUs',
'groups': 'xen'
}

d3 = {'name': 'xen_mem',
'call_back': xen_mem,
'time_max': 20,
'value_type': 'uint',
'units': 'KB',
'slope': 'both',
'format': '%d',
'description': 'Total memory Xen',
'groups': 'xen'
}

d4 = {'name': 'xen_mem_use',
'call_back': xen_mem_use,
'time_max': 20,
'value_type': 'uint',
'units': 'KB',
'slope': 'both',
'format': '%d',
'description': 'Memory Usage',
'groups': 'xen'
}

descriptors = [d1,d2,d3,d4]

return descriptors

def metric_cleanup():
'''Clean up the metric module.'''
global conn
conn.close()
pass

#This code is for debugging and unit testing
if __name__ == '__main__':
metric_init('init')
for d in descriptors:
v = d['call_back'](d['name'])
print 'value for %s is %u' % (d['name'], v)

0 comments on commit 1563083

Please sign in to comment.