From 1949f2f4eaefd5511eeace54e698078811c7b4cc Mon Sep 17 00:00:00 2001 From: Tony Murray Date: Fri, 12 Aug 2016 11:05:58 -0500 Subject: [PATCH] Proxmox rrd fix Attempt to fix proxmox rrd naming. Create a separate function to generate it's file names. --- .../application/proxmox_traffic.inc.php | 2 +- includes/polling/applications/proxmox.inc.php | 98 +++++++++---------- includes/rrdtool.inc.php | 28 +++++- 3 files changed, 77 insertions(+), 51 deletions(-) diff --git a/html/includes/graphs/application/proxmox_traffic.inc.php b/html/includes/graphs/application/proxmox_traffic.inc.php index ea7f75c63e..eb2055ac99 100644 --- a/html/includes/graphs/application/proxmox_traffic.inc.php +++ b/html/includes/graphs/application/proxmox_traffic.inc.php @@ -18,7 +18,7 @@ require 'includes/graphs/common.inc.php'; -$proxmox_rrd = $config['rrd_dir'].'/proxmox/'.$vars['cluster'].'/'.$vars['vmid'].'_netif_'.$vars['port'].'.rrd'; +$proxmox_rrd = proxmox_rrd_name($vars['cluster'], $vars['vmid'], $vars['port']); if (rrdtool_check_rrd_exists($proxmox_rrd)) { $rrd_filename = $proxmox_rrd; diff --git a/includes/polling/applications/proxmox.inc.php b/includes/polling/applications/proxmox.inc.php index 0807c06b51..c11bdb1aa4 100644 --- a/includes/polling/applications/proxmox.inc.php +++ b/includes/polling/applications/proxmox.inc.php @@ -1,11 +1,5 @@ $device['device_id'], 'app_type' => $name, 'app_instance' => $pmxcluster), + 'applications', '`device_id` = ? AND `app_type` = ?', array($device['device_id'], $name)); -$pmxcdir = join('/', array($config['rrd_dir'], $name, $pmxcluster)); -if (!is_dir($pmxcdir)) { - mkdir($pmxcdir, 0775, true); -} + if (count($pmxlines) > 0) { + $pmxcache = array(); -dbUpdate(array('device_id' => $device['device_id'], 'app_type' => $name, 'app_instance' => $pmxcluster), 'applications', '`device_id` = ? AND `app_type` = ?', array($device['device_id'], $name)); + foreach ($pmxlines as $vm) { + list($vmid, $vmport, $vmpin, $vmpout, $vmdesc) = explode('/', $vm, 5); + print "Proxmox ($pmxcluster): $vmdesc: $vmpin/$vmpout/$vmport\n"; -if (count($pmxlines) > 0) { - $pmxcache = array(); + $rrd_proxmox_name = array( + 'pmxcluster' => $pmxcluster, + 'vmid' => $vmid, + 'vmport' => $vmport + ); + $rrd_def = array( + 'DS:INOCTETS:DERIVE:600:0:12500000000', + 'DS:OUTOCTETS:DERIVE:600:0:12500000000' + ); + $fields = array( + 'INOCTETS' => $vmpin, + 'OUTOCTETS' => $vmpout + ); - foreach ($pmxlines as $vm) { - list($vmid, $vmport, $vmpin, $vmpout, $vmdesc) = explode('/', $vm, 5); - print "Proxmox ($pmxcluster): $vmdesc: $vmpin/$vmpout/$vmport\n"; + $tags = compact('name', 'app_id', 'pmxcluster', 'vmid', 'vmport', 'rrd_proxmox_name', 'rrd_def'); + data_update($device, 'app', $tags, $fields); - $rrd_name = join('/', array($name, $pmxcluster, $vmid)).'_netif_'.$vmport; - $rrd_def = array( - 'DS:INOCTETS:DERIVE:600:0:12500000000', - 'DS:OUTOCTETS:DERIVE:600:0:12500000000' - ); - $fields = array( - 'INOCTETS' => $vmpin, - 'OUTOCTETS' => $vmpout - ); + if (proxmox_vm_exists($vmid, $pmxcluster, $pmxcache) === true) { + dbUpdate(array( + 'device_id' => $device['device_id'], + 'last_seen' => array('NOW()'), + 'description' => $vmdesc + ), $name, '`vmid` = ? AND `cluster` = ?', array($vmid, $pmxcluster)); + } else { + $pmxcache[$pmxcluster][$vmid] = dbInsert(array( + 'cluster' => $pmxcluster, + 'vmid' => $vmid, + 'description' => $vmdesc, + 'device_id' => $device['device_id'] + ), $name); + } - $tags = compact('name', 'app_id', 'pmxcluster', 'vmid', 'vmport', 'rrd_name', 'rrd_def'); - data_update($device, 'app', $tags, $fields); - - if (proxmox_vm_exists($vmid, $pmxcluster, $pmxcache) === true) { - dbUpdate(array('device_id' => $device['device_id'], 'last_seen' => array('NOW()'), 'description' => $vmdesc), $name, '`vmid` = ? AND `cluster` = ?', array($vmid, $pmxcluster)); + if ($portid = proxmox_port_exists($vmid, $pmxcluster, $vmport) !== false) { + dbUpdate(array('last_seen' => array('NOW()')), 'proxmox_ports', '`vm_id` = ? AND `port` = ?', + array($pmxcache[$pmxcluster][$vmid], $vmport)); + } else { + dbInsert(array('vm_id' => $pmxcache[$pmxcluster][$vmid], 'port' => $vmport), 'proxmox_ports'); + } } - else { - $pmxcache[$pmxcluster][$vmid] = dbInsert(array('cluster' => $pmxcluster, 'vmid' => $vmid, 'description' => $vmdesc, 'device_id' => $device['device_id']), $name); - } - - if ($portid = proxmox_port_exists($vmid, $pmxcluster, $vmport) !== false) { - dbUpdate(array('last_seen' => array('NOW()')), 'proxmox_ports', '`vm_id` = ? AND `port` = ?', array($pmxcache[$pmxcluster][$vmid], $vmport)); - } - else { - dbInsert(array('vm_id' => $pmxcache[$pmxcluster][$vmid], 'port' => $vmport), 'proxmox_ports'); - } - } } - -unset($pmxlines); -unset($pmxcluster); -unset($pmxcdir); -unset($proxmox); -unset($pmxcache); +unset($pmxlines, $pmxcluster, $pmxcdir, $proxmox, $pmxcache); diff --git a/includes/rrdtool.inc.php b/includes/rrdtool.inc.php index 6030782052..ab51ea25ff 100644 --- a/includes/rrdtool.inc.php +++ b/includes/rrdtool.inc.php @@ -292,6 +292,26 @@ function rrd_name($host, $extra, $extension = ".rrd") return implode("/", array($config['rrd_dir'], $host, $filename.$extension)); } // rrd_name +/** + * Generates a filename for a proxmox cluster rrd + * + * @param $pmxcluster + * @param $vmid + * @param $vmport + * @return string full path to the rrd. + */ +function proxmox_rrd_name($pmxcluster, $vmid, $vmport) { + global $config; + + $pmxcdir = join('/', array($config['rrd_dir'], 'proxmox', safename($pmxcluster))); + // this is not needed for remote rrdcached + if (!is_dir($pmxcdir)) { + mkdir($pmxcdir, 0775, true); + } + + return join('/', array($pmxcdir, safename($vmid.'_netif_'.$vmport.'.rrd'))); +} + /** * Modify an rrd file's max value and trim the peaks as defined by rrdtool * @@ -358,7 +378,13 @@ function rrdtool_data_update($device, $measurement, $tags, $fields) rrd_file_rename($device, $oldname, $rrd_name); } - $rrd = rrd_name($device['hostname'], $rrd_name); + if (isset($tags['rrd_proxmox_name'])) { + $pmxvars = $tags['rrd_proxmox_name']; + $rrd = proxmox_rrd_name($pmxvars['pmxcluster'], $pmxvars['vmid'], $pmxvars['vmport']); + } else { + $rrd = rrd_name($device['hostname'], $rrd_name); + } + if ($tags['rrd_def']) { $rrd_def = is_array($tags['rrd_def']) ? $tags['rrd_def'] : array($tags['rrd_def']); // add the --step and the rra definitions to the command