Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
monitoring
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
cylab
monitoring
Commits
ff769a4b
Commit
ff769a4b
authored
4 years ago
by
Tibo
Browse files
Options
Downloads
Patches
Plain Diff
add support for ifconfig on ubuntu 18.04. Fix issue
#18
parent
e291f340
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Pipeline
#3654
failed
4 years ago
Stage: test
Stage: deploy
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
app/Sensor/Ifconfig.php
+21
-7
21 additions, 7 deletions
app/Sensor/Ifconfig.php
tests/Unit/ExampleTest.php
+19
-1
19 additions, 1 deletion
tests/Unit/ExampleTest.php
tests/Unit/ifconfig1804
+36
-0
36 additions, 0 deletions
tests/Unit/ifconfig1804
with
76 additions
and
8 deletions
app/Sensor/Ifconfig.php
+
21
−
7
View file @
ff769a4b
...
...
@@ -94,9 +94,11 @@ class Ifconfig extends AbstractSensor
return
self
::
STATUS_OK
;
}
const
IFNAME
=
"/^(
\\
S+)
\\
s+Link encap:/m"
;
const
IPV4
=
'/^\\s+inet addr:(\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3})/m'
;
const
RXTX
=
'/^\\s+RX bytes:(\\d+) .*TX bytes:(\\d+)/m'
;
const
IFNAME
=
'/^(?|(\S+)\s+Link encap:|(\S+): flags)/m'
;
const
IPV4
=
'/^\s+inet (?>addr:)?(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})/m'
;
const
RXTX
=
'/^\s+RX bytes:(\d+) .*TX bytes:(\d+)/m'
;
const
RX
=
'/^\s+RX packets (?>\d+) bytes (\d+)/m'
;
const
TX
=
'/^\s+TX packets (?>\d+) bytes (\d+)/m'
;
public
function
parseIfconfigRecord
(
$record
)
{
...
...
@@ -128,6 +130,7 @@ class Ifconfig extends AbstractSensor
$if
=
null
;
foreach
(
$lines
as
$line
)
{
$name
=
$this
->
pregMatchOne
(
self
::
IFNAME
,
$line
);
if
(
$name
!==
false
)
{
// Starting the section of a new interface
$if
=
new
NetworkInterface
();
...
...
@@ -142,12 +145,23 @@ class Ifconfig extends AbstractSensor
continue
;
}
$matches
=
array
()
;
$matches
=
[]
;
if
(
preg_match
(
self
::
RXTX
,
$line
,
$matches
)
===
1
)
{
$if
->
rx
=
$matches
[
1
];
$if
->
tx
=
$matches
[
2
];
continue
;
}
$rx
=
$this
->
pregMatchOne
(
self
::
RX
,
$line
);
if
(
$rx
!==
false
)
{
$if
->
rx
=
$rx
;
}
$tx
=
$this
->
pregMatchOne
(
self
::
TX
,
$line
);
if
(
$tx
!==
false
)
{
$if
->
tx
=
$tx
;
}
}
// filter out uninteresting interfaces
...
...
@@ -161,11 +175,11 @@ class Ifconfig extends AbstractSensor
return
$filtered
;
}
public
function
pregMatchOne
(
$pattern
,
$
string
)
public
function
pregMatchOne
(
string
$pattern
,
string
$string
,
int
$match_group
=
1
)
{
$matches
=
array
()
;
$matches
=
[]
;
if
(
preg_match
(
$pattern
,
$string
,
$matches
)
===
1
)
{
return
$matches
[
1
];
return
$matches
[
$match_group
];
}
return
false
;
...
...
This diff is collapsed.
Click to expand it.
tests/Unit/ExampleTest.php
+
19
−
1
View file @
ff769a4b
...
...
@@ -71,10 +71,28 @@ class ExampleTest extends TestCase
$this
->
assertEquals
(
2074977132
,
$interfaces
[
1
]
->
tx
);
}
/**
* Test parsing of ifconfig string from a ubuntu 18.04 server
*
* @group ifconfig
* @group sensors
*/
public
function
testIfconfig1804
()
{
$string
=
file_get_contents
(
__DIR__
.
"/ifconfig1804"
);
$sensor
=
new
Ifconfig
(
new
\App\Server
());
$interfaces
=
$sensor
->
parseIfconfig
(
$string
);
$this
->
assertEquals
(
2
,
count
(
$interfaces
));
$this
->
assertEquals
(
"eno1"
,
$interfaces
[
0
]
->
name
);
$this
->
assertEquals
(
"172.20.0.8"
,
$interfaces
[
1
]
->
address
);
$this
->
assertEquals
(
185252610
,
$interfaces
[
1
]
->
rx
);
$this
->
assertEquals
(
266912412
,
$interfaces
[
1
]
->
tx
);
}
/**
* @group Disks
*/
public
function
testDisksSensor
()
{
$string
=
file_get_contents
(
__DIR__
.
"/df"
);
...
...
This diff is collapsed.
Click to expand it.
tests/Unit/ifconfig1804
0 → 100644
+
36
−
0
View file @
ff769a4b
eno1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 193.190.205.212 netmask 255.255.255.0 broadcast 193.190.205.255
ether 10:98:36:af:d4:bf txqueuelen 1000 (Ethernet)
RX packets 4982592 bytes 448456149 (448.4 MB)
RX errors 0 dropped 43612 overruns 0 frame 0
TX packets 707408 bytes 79299197 (79.2 MB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
device interrupt 16
eno2: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 172.20.0.8 netmask 255.255.0.0 broadcast 172.20.255.255
inet6 fe80::1298:36ff:feaf:d4b0 prefixlen 64 scopeid 0x20<link>
ether 10:98:36:af:d4:b0 txqueuelen 1000 (Ethernet)
RX packets 1941945 bytes 185252610 (185.2 MB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 1414316 bytes 266912412 (266.9 MB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
device interrupt 17
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1000 (Local Loopback)
RX packets 425874 bytes 30710973 (30.7 MB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 425874 bytes 30710973 (30.7 MB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
tun0: flags=4305<UP,POINTOPOINT,RUNNING,NOARP,MULTICAST> mtu 1500
inet 172.21.0.1 netmask 255.255.0.0 destination 172.21.0.1
inet6 fe80::8b10:9f7e:131:c4a1 prefixlen 64 scopeid 0x20<link>
unspec 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00 txqueuelen 100 (UNSPEC)
RX packets 2870 bytes 196496 (196.4 KB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 20201 bytes 4312778 (4.3 MB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
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