Skip to content
Browse files

add Cluster and Host into csv export

  • Loading branch information...
1 parent 251927e commit b48d3697ced2121be1fd5cfe162d9650a6519c1c @koebi001 committed Jun 7, 2011
Showing with 26 additions and 10 deletions.
  1. +26 −10 ganglia-web/graph.php
View
36 ganglia-web/graph.php
@@ -553,24 +553,40 @@
if ( $user['csv_output'] ) {
+ $csv_array=array();
+ $metrics_name_array=array();
+ foreach ( $output_array as $key => $metric_array ) {
+ foreach ($metric_array['metrics'] as $key => $value ) {
+ $timestamp = $value['timestamp'];
+ $cluster_name = $metric_array['cluster_name'];
+ $host_name = strip_domainname( $metric_array['host_name'] );
+ $metric_name = $metric_array['metric_name'];
+ $csv_array[$timestamp][$cluster_name][$host_name][$metric_name] = $value['value'];
+ $metrics_name_array[$metric_name] = 1;
+ }
+ }
+
header("Content-Type: application/csv");
header("Content-Disposition: inline; filename=\"ganglia-metrics.csv\"");
- print "Timestamp";
-
// Print out headers
- for ( $i = 0 ; $i < sizeof($output_array) ; $i++ ) {
- print "," . $output_array[$i]["metric_name"];
+ print "Timestamp,Cluster,Host";
+ foreach ( $metrics_name_array as $key => $value) {
+ print "," . $key;
}
-
print "\n";
- foreach ( $output_array[0]["metrics"] as $key => $row ) {
- print date("c", $row["timestamp"]);
- for ( $j = 0 ; $j < $num_of_metrics ; $j++ ) {
- print "," .$output_array[$j]["metrics"][$key]["value"];
+ // Print out data
+ foreach ( $csv_array as $timestamp => $clusters ){
+ foreach ( $clusters as $cluster => $hosts ){
+ foreach ( $hosts as $host => $metrics){
+ print date("c", $timestamp) . "," . $cluster . "," . $host;
+ foreach ( $metrics_name_array as $key => $value) {
+ print "," . $metrics[$key];
+ }
+ print "\n";
+ }
}
- print "\n";
}
}

1 comment on commit b48d369

@vvuksan
vvuksan commented on b48d369 Jun 7, 2011

This is gonna get a bit tricky since CSV can also export aggregate graphs or graphs in general. Those graphs may cover metrics from multiple hosts. Not sure how that could be addressed with CSV

Please sign in to comment.
Something went wrong with that request. Please try again.