Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
menshen
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
Analyze
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
leap
menshen
Commits
f4712aa5
Verified
Commit
f4712aa5
authored
4 years ago
by
meskio
Committed by
Sam Whited
3 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Add packets per second metric
- Related:
#10
parent
cc8ea5f0
No related branches found
No related tags found
1 merge request
!11
Add a load balancer
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
agent/main.go
+11
-2
11 additions, 2 deletions
agent/main.go
agent/net.go
+22
-10
22 additions, 10 deletions
agent/net.go
lb.go
+10
-0
10 additions, 0 deletions
lb.go
with
43 additions
and
12 deletions
agent/main.go
+
11
−
2
View file @
f4712aa5
...
...
@@ -52,7 +52,8 @@ func main() {
}
agent
:=
lbagent
.
New
(
os
.
Args
[
1
],
nil
,
dialer
)
registerBwmon
(
agent
,
config
)
registerBandwidth
(
agent
,
config
)
registerPackets
(
agent
,
config
)
agent
.
RegisterUtilization
(
"conntrack"
,
lbpb
.
Utilization_GAUGE
,
conntrackUtilization
)
agent
.
SetUpdateInterval
(
updateInterval
)
...
...
@@ -66,7 +67,7 @@ func main() {
}
}
func
registerB
wmon
(
agent
*
lbagent
.
Agent
,
config
Config
)
{
func
registerB
andwidth
(
agent
*
lbagent
.
Agent
,
config
Config
)
{
txBandwidth
:=
config
.
TxBandwidth
if
txBandwidth
==
0
{
txBandwidth
=
config
.
Bandwidth
...
...
@@ -81,3 +82,11 @@ func registerBwmon(agent *lbagent.Agent, config Config) {
rxBwFunc
:=
getBandwidthUtilization
(
config
.
NetDevice
,
rxBandwidth
,
RX
)
agent
.
RegisterUtilization
(
"bandwidth_rx"
,
lbpb
.
Utilization_GAUGE
,
rxBwFunc
)
}
func
registerPackets
(
agent
*
lbagent
.
Agent
,
config
Config
)
{
txPacketsFunc
:=
getPacketUtilization
(
config
.
NetDevice
,
TX
)
agent
.
RegisterUtilization
(
"packets_tx"
,
lbpb
.
Utilization_COUNTER
,
txPacketsFunc
)
rxPacketsFunc
:=
getPacketUtilization
(
config
.
NetDevice
,
RX
)
agent
.
RegisterUtilization
(
"packets_rx"
,
lbpb
.
Utilization_COUNTER
,
rxPacketsFunc
)
}
This diff is collapsed.
Click to expand it.
agent/
bwmon
.go
→
agent/
net
.go
+
22
−
10
View file @
f4712aa5
...
...
@@ -36,7 +36,11 @@ const (
func
getBandwidthUtilization
(
device
string
,
max
int64
,
direction
int
)
func
()
float64
{
var
lastRead
uint64
return
func
()
float64
{
n
,
err
:=
parseProcNetDev
(
device
,
direction
)
field
:=
1
if
direction
==
TX
{
field
=
9
}
n
,
err
:=
parseProcNetDev
(
device
,
field
)
if
err
!=
nil
{
log
.
Printf
(
"Error reading /proc/net/dev: %v"
,
err
)
lastRead
=
0
...
...
@@ -55,7 +59,22 @@ func getBandwidthUtilization(device string, max int64, direction int) func() flo
}
}
func
parseProcNetDev
(
dev
string
,
direction
int
)
(
uint64
,
error
)
{
func
getPacketUtilization
(
device
string
,
direction
int
)
func
()
float64
{
return
func
()
float64
{
field
:=
2
if
direction
==
TX
{
field
=
10
}
n
,
err
:=
parseProcNetDev
(
device
,
field
)
if
err
!=
nil
{
log
.
Printf
(
"Error reading /proc/net/dev: %v"
,
err
)
return
0
}
return
float64
(
n
)
}
}
func
parseProcNetDev
(
dev
string
,
field
int
)
(
uint64
,
error
)
{
file
,
err
:=
os
.
Open
(
"/proc/net/dev"
)
if
err
!=
nil
{
return
0
,
err
...
...
@@ -65,18 +84,11 @@ func parseProcNetDev(dev string, direction int) (uint64, error) {
// Device name (+ ':') in field 0
devCol
:=
[]
byte
(
dev
+
":"
)
// Receive bytes: field 1
// Transmit bytes: field 9
counterIndex
:=
1
if
direction
==
TX
{
counterIndex
=
9
}
input
:=
bufio
.
NewScanner
(
file
)
for
input
.
Scan
()
{
fields
:=
bytes
.
Fields
(
input
.
Bytes
())
if
bytes
.
Equal
(
fields
[
0
],
devCol
)
{
n
,
err
:=
strconv
.
ParseUint
(
string
(
fields
[
counterIndex
]),
10
,
64
)
n
,
err
:=
strconv
.
ParseUint
(
string
(
fields
[
field
]),
10
,
64
)
if
err
!=
nil
{
return
0
,
err
}
...
...
This diff is collapsed.
Click to expand it.
lb.go
+
10
−
0
View file @
f4712aa5
...
...
@@ -42,6 +42,16 @@ var limits = []*lb.Limit{
Min
:
0
,
Max
:
1
,
},
{
Dimension
:
"packets_tx"
,
Min
:
0
,
Max
:
100
_000
,
},
{
Dimension
:
"packets_rx"
,
Min
:
0
,
Max
:
100
_000
,
},
{
Dimension
:
"conntrack"
,
Min
:
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