forked from elastic/beats
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Report network stats for processes on Linux.
- Loading branch information
1 parent
0f59764
commit 7dd6ba8
Showing
7 changed files
with
471 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package process | ||
|
||
import ( | ||
"strings" | ||
|
||
"github.com/elastic/beats/libbeat/common" | ||
) | ||
|
||
func (m *MetricSet) getNetworkInterfaceStats(pid int) (common.MapStr, error) { | ||
proc, err := m.procfs.NewProc(pid) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
ns, err := proc.NewNamespaces() | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
// Only report network metrics if they differ from the overall hosts. We | ||
// check if the process is in a different network namespace. | ||
if net, found := ns["net"]; !found || net.Inode == m.hostNetNamespace { | ||
return nil, nil | ||
} | ||
|
||
networkStats, err := proc.NewNetDev() | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
if len(m.interfaces) > 0 { | ||
// Filter network devices by name. | ||
for i, stats := range networkStats { | ||
name := strings.ToLower(stats.Name) | ||
if _, include := m.interfaces[name]; !include { | ||
networkStats = append(networkStats[:i], networkStats[i+1:]...) | ||
} | ||
} | ||
} | ||
|
||
// Report metrics in aggregate (to avoid having an array). | ||
total := networkStats.Total() | ||
|
||
return common.MapStr{ | ||
"name": total.Name, | ||
"in": common.MapStr{ | ||
"errors": total.RxErrors, | ||
"dropped": total.RxDropped, | ||
"bytes": total.RxBytes, | ||
"packets": total.RxPackets, | ||
}, | ||
"out": common.MapStr{ | ||
"errors": total.TxErrors, | ||
"dropped": total.TxDropped, | ||
"packets": total.TxPackets, | ||
"bytes": total.TxBytes, | ||
}, | ||
}, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.