|
@@ -67,6 +67,7 @@ sub generate_response {
|
|
|
|
|
|
|
|
$response .= print_totals($data);
|
|
$response .= print_totals($data);
|
|
|
|
|
|
|
|
|
|
+ my @data_resolutions = ('fiveminute', 'hour', 'day', 'month', 'year');
|
|
|
foreach my $data_resolution ( @data_resolutions ) {
|
|
foreach my $data_resolution ( @data_resolutions ) {
|
|
|
$response .= print_data_resolution($data_resolution, $data);
|
|
$response .= print_data_resolution($data_resolution, $data);
|
|
|
}
|
|
}
|
|
@@ -74,74 +75,79 @@ sub generate_response {
|
|
|
return $response;
|
|
return $response;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-################
|
|
|
|
|
|
|
+sub print_totals {
|
|
|
|
|
+ my ($data) = @_;
|
|
|
|
|
|
|
|
|
|
+ my $output = "";
|
|
|
|
|
|
|
|
-sub get_interface_alias
|
|
|
|
|
-{
|
|
|
|
|
- my ($interface) = @_;
|
|
|
|
|
- my $interface_alias = $interface->{'alias'};
|
|
|
|
|
- if (length($interface_alias) == 0) {
|
|
|
|
|
- $interface_alias = $interface->{'name'};
|
|
|
|
|
- }
|
|
|
|
|
- return $interface_alias;
|
|
|
|
|
|
|
+ $output .= "\n# HELP vnstat_interface_total_received_bytes All time total received (rx) bytes\n";
|
|
|
|
|
+ $output .= "# TYPE vnstat_interface_total_received_bytes counter\n";
|
|
|
|
|
+
|
|
|
|
|
+ foreach my $interface ( @{ $data->{'interfaces'} } ) {
|
|
|
|
|
+ my $interface_alias = get_interface_alias($interface);
|
|
|
|
|
+ $output .= "vnstat_interface_total_received_bytes{interface=\"$interface->{'name'}\",alias=\"$interface_alias\"} $interface->{'traffic'}{'total'}{'rx'} $interface->{'updated'}{'timestamp'}000\n";
|
|
|
|
|
+ }
|
|
|
|
|
+$output .= "\n# HELP vnstat_interface_total_transmitted_bytes All time total transmitted (tx) bytes\n";
|
|
|
|
|
+$output .= "# TYPE vnstat_interface_total_transmitted_bytes counter\n";
|
|
|
|
|
+
|
|
|
|
|
+foreach my $interface ( @{ $data->{'interfaces'} } ) {
|
|
|
|
|
+ my $interface_alias = get_interface_alias($interface);
|
|
|
|
|
+ $output .= "vnstat_interface_total_transmitted_bytes{interface=\"$interface->{'name'}\",alias=\"$interface_alias\"} $interface->{'traffic'}{'total'}{'tx'} $interface->{'updated'}{'timestamp'}000\n";
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-sub print_totals
|
|
|
|
|
-{
|
|
|
|
|
- my ($data) = @_;
|
|
|
|
|
|
|
+return $output;
|
|
|
|
|
+}
|
|
|
|
|
|
|
|
- print "\n# HELP vnstat_interface_total_received_bytes All time total received (rx) bytes\n";
|
|
|
|
|
- print "# TYPE vnstat_interface_total_received_bytes counter\n";
|
|
|
|
|
|
|
+sub print_data_resolution {
|
|
|
|
|
+ my ($resolution, $data) = @_;
|
|
|
|
|
+ my $output_count = 0;
|
|
|
|
|
+ my $output = "";
|
|
|
|
|
|
|
|
- foreach my $interface ( @{ $data->{'interfaces'} } ) {
|
|
|
|
|
- my $interface_alias = get_interface_alias($interface);
|
|
|
|
|
- print "vnstat_interface_total_received_bytes{interface=\"$interface->{'name'}\",alias=\"$interface_alias\"} $interface->{'traffic'}{'total'}{'rx'} $interface->{'updated'}{'timestamp'}000\n";
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ $output .= "\n# HELP vnstat_interface_".$resolution."_received_bytes Received (rx) bytes for current $resolution\n";
|
|
|
|
|
+ $output .= "# TYPE vnstat_interface_".$resolution."_received_bytes gauge\n";
|
|
|
|
|
|
|
|
- print "\n# HELP vnstat_interface_total_transmitted_bytes All time total transmitted (tx) bytes\n";
|
|
|
|
|
- print "# TYPE vnstat_interface_total_transmitted_bytes counter\n";
|
|
|
|
|
|
|
+ $output_count = 0;
|
|
|
|
|
+ foreach my $interface ( @{ $data->{'interfaces'} } ) {
|
|
|
|
|
+ my $interface_alias = get_interface_alias($interface);
|
|
|
|
|
+ if (defined $interface->{'traffic'}{$resolution}) {
|
|
|
|
|
+ $output .= "vnstat_interface_".$resolution."_received_bytes{interface=\"$interface->{'name'}\",alias=\"$interface_alias\"} $interface->{'traffic'}{$resolution}[0]{'rx'} $interface->{'updated'}{'timestamp'}000\n";
|
|
|
|
|
+ $output_count++;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ if ($output_count == 0) {
|
|
|
|
|
+ $output .= "# no data\n";
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- foreach my $interface ( @{ $data->{'interfaces'} } ) {
|
|
|
|
|
- my $interface_alias = get_interface_alias($interface);
|
|
|
|
|
- print "vnstat_interface_total_transmitted_bytes{interface=\"$interface->{'name'}\",alias=\"$interface_alias\"} $interface->{'traffic'}{'total'}{'tx'} $interface->{'updated'}{'timestamp'}000\n";
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ $output .= "\n# HELP vnstat_interface_".$resolution."_transmitted_bytes Transmitted (tx) bytes for current $resolution\n";
|
|
|
|
|
+ $output .= "# TYPE vnstat_interface_".$resolution."_transmitted_bytes gauge\n";
|
|
|
|
|
+
|
|
|
|
|
+ $output_count = 0;
|
|
|
|
|
+ foreach my $interface ( @{ $data->{'interfaces'} } ) {
|
|
|
|
|
+ my $interface_alias = get_interface_alias($interface);
|
|
|
|
|
+ if (defined $interface->{'traffic'}{$resolution}) {
|
|
|
|
|
+ $output .= "vnstat_interface_".$resolution."_transmitted_bytes{interface=\"$interface->{'name'}\",alias=\"$interface_alias\"} $interface->{'traffic'}{$resolution}[0]{'tx'} $interface->{'updated'}{'timestamp'}000\n";
|
|
|
|
|
+ $output_count++;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ if ($output_count == 0) {
|
|
|
|
|
+ $output .= "# no data\n";
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return $output;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-sub print_data_resolution
|
|
|
|
|
-{
|
|
|
|
|
- my ($resolution, $data) = @_;
|
|
|
|
|
- my $output_count = 0;
|
|
|
|
|
-
|
|
|
|
|
- print "\n# HELP vnstat_interface_".$resolution."_received_bytes Received (rx) bytes for current $resolution\n";
|
|
|
|
|
- print "# TYPE vnstat_interface_".$resolution."_received_bytes gauge\n";
|
|
|
|
|
-
|
|
|
|
|
- $output_count = 0;
|
|
|
|
|
- foreach my $interface ( @{ $data->{'interfaces'} } ) {
|
|
|
|
|
- my $interface_alias = get_interface_alias($interface);
|
|
|
|
|
- if (defined $interface->{'traffic'}{$resolution}) {
|
|
|
|
|
- print "vnstat_interface_".$resolution."_received_bytes{interface=\"$interface->{'name'}\",alias=\"$interface_alias\"} $interface->{'traffic'}{$resolution}[0]{'rx'} $interface->{'updated'}{'timestamp'}000\n";
|
|
|
|
|
- $output_count++;
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- if ($output_count == 0) {
|
|
|
|
|
- print "# no data\n";
|
|
|
|
|
- }
|
|
|
|
|
|
|
|
|
|
- print "\n# HELP vnstat_interface_".$resolution."_transmitted_bytes Transmitted (tx) bytes for current $resolution\n";
|
|
|
|
|
- print "# TYPE vnstat_interface_".$resolution."_transmitted_bytes gauge\n";
|
|
|
|
|
|
|
+################
|
|
|
|
|
+
|
|
|
|
|
|
|
|
- $output_count = 0;
|
|
|
|
|
- foreach my $interface ( @{ $data->{'interfaces'} } ) {
|
|
|
|
|
- my $interface_alias = get_interface_alias($interface);
|
|
|
|
|
- if (defined $interface->{'traffic'}{$resolution}) {
|
|
|
|
|
- print "vnstat_interface_".$resolution."_transmitted_bytes{interface=\"$interface->{'name'}\",alias=\"$interface_alias\"} $interface->{'traffic'}{$resolution}[0]{'tx'} $interface->{'updated'}{'timestamp'}000\n";
|
|
|
|
|
- $output_count++;
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- if ($output_count == 0) {
|
|
|
|
|
- print "# no data\n";
|
|
|
|
|
|
|
+sub get_interface_alias
|
|
|
|
|
+{
|
|
|
|
|
+ my ($interface) = @_;
|
|
|
|
|
+ my $interface_alias = $interface->{'alias'};
|
|
|
|
|
+ if (length($interface_alias) == 0) {
|
|
|
|
|
+ $interface_alias = $interface->{'name'};
|
|
|
}
|
|
}
|
|
|
|
|
+ return $interface_alias;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
print "Content-Type: text/plain\n\n";
|
|
print "Content-Type: text/plain\n\n";
|