Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
resmon
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mirrors
resmon
Commits
f4e1f328
Commit
f4e1f328
authored
11 years ago
by
Chris Nehren
Browse files
Options
Downloads
Patches
Plain Diff
add NetUsage module for Linux, reading from /sys/class/net/$interface/statistics
parent
f36c0bee
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
lib/Core/Linux/NetUsage.pm
+99
-0
99 additions, 0 deletions
lib/Core/Linux/NetUsage.pm
with
99 additions
and
0 deletions
lib/Core/Linux/NetUsage.pm
0 → 100644
+
99
−
0
View file @
f4e1f328
package
Core::Linux::
NetUsage
;
use
strict
;
use
warnings
;
use
base
'
Resmon::Module
';
use
POSIX
qw(strftime)
;
use
Time::
HiRes
qw(gettimeofday usleep)
;
use
Resmon::
ExtComm
qw(run_command cache_command)
;
=pod
=head1 NAME
Core::Linux::NetUsage - Linux network interface throughput stats
=head1 SYNOPSIS
Core::Sample {
check_name : interface => arg1
}
=head1 DESCRIPTION
This module obtains network usage statistics on a Linux machine
by reading the /proc filesystem (like netstat and ifconfig do).
=head1 CONFIGURATION
=over
=item check_name
Description only, non-normative.
=item interface
The interface to obtain statistics for, like C<eth0>. Defaults to
C<eth0> if not specified.
=back
=head1 METRICS
=over
=item rx_bytes
Count, in bytes, of packets received on the interface.
=item tx_bytes
Count, in bytes, of packets sent on the interface.
=back
=cut
sub
new
{
my
(
$class
,
$check_name
,
$config
)
=
@_
;
my
$self
=
$class
->
SUPER::
new
(
$check_name
,
$config
);
bless
(
$self
,
$class
);
return
$self
;
}
sub
handler
{
my
$self
=
shift
;
my
$config
=
$self
->
{
config
};
my
$interface
=
$config
->
{
interface
};
print
"
I have
${interface}
\n
";
my
$stats
=
get_network_statistics_for
(
$interface
);
return
$stats
;
};
sub
get_network_statistics_for
{
my
(
$interface
)
=
@_
;
my
$dir
=
"
/sys/class/net/
$interface
/statistics
";
my
$stats
=
{};
my
@stats
=
qw/rx_bytes tx_bytes/
;
for
my
$stat
(
@stats
)
{
$stats
->
{
$stat
}
=
do
{
open
my
$fh
,
'
<
',
"
${dir}
/
${stat}
"
or
die
"
${dir}
/
${stat}
: $!
";
local
$/
;
<
$fh
>
;
};
chomp
$stats
->
{
$stat
};
}
return
$stats
;
}
1
;
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment