Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Influxdb incorrect storage types #3354

Merged
merged 4 commits into from Apr 19, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 23 additions & 3 deletions includes/functions.php
Expand Up @@ -1252,10 +1252,30 @@ function function_check($function) {
return function_exists($function);
}

function force_influx_data($type,$data) {
if ($type == 'f' || $type == 'float') {
return(sprintf("%.1f",$data));
function force_influx_data($data) {
/*
* It is not trivial to detect if something is a float or an integer, and
* therefore may cause breakages on inserts.
* Just setting every number to a float gets around this, but may introduce
* inefficiencies.
* I've left the detection statement in there for a possible change in future,
* but currently everything just gets set to a float.
*/

if (is_numeric($data)) {
// If it is an Integer
if (ctype_digit($data)) {
return floatval($data);
// Else it is a float
}
else {
return floatval($data);
}
}
else {
return $data;
}

}// end force_influx_data

/**
Expand Down
12 changes: 10 additions & 2 deletions includes/influxdb.inc.php
Expand Up @@ -58,7 +58,10 @@ function influx_update($device,$measurement,$tags=array(),$fields) {
$tmp_tags[$k] = $v;
}
foreach ($fields as $k => $v) {
$tmp_fields[$k] = force_influx_data('f',$v);
$tmp_fields[$k] = force_influx_data($v);
if( $tmp_fields[$k] === null) {
unset($tmp_fields[$k]);
}
}

d_echo("\nInfluxDB data:\n");
Expand All @@ -76,7 +79,12 @@ function influx_update($device,$measurement,$tags=array(),$fields) {
$tmp_fields // optional additional fields
)
);
$result = $influxdb->writePoints($points);
try {
$result = $influxdb->writePoints($points);
} catch (Exception $e) {
d_echo("Caught exception: ", $e->getMessage(), "\n");
d_echo($e->getTrace());
}
}
else {
print $console_color->convert('[%gInfluxDB Disabled%n] ', false);
Expand Down
11 changes: 1 addition & 10 deletions includes/polling/netstats-snmp.inc.php
Expand Up @@ -48,16 +48,7 @@

$data_array = snmpwalk_cache_oid($device, 'snmp', array(), 'SNMPv2-MIB');

$fields = array();
foreach ($oids as $oid) {
if (is_numeric($data_array[0][$oid])) {
$value = $data_array[0][$oid];
}
else {
$value = 'U';
}
$fields[$oid] = $value;
}
$fields = $data_array[0];

if (isset($data_array[0]['snmpInPkts']) && isset($data_array[0]['snmpOutPkts'])) {
if (!file_exists($rrd_file)) {
Expand Down