-
Notifications
You must be signed in to change notification settings - Fork 24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add per-process network stats #62
Merged
fearful-symmetry
merged 3 commits into
elastic:main
from
fearful-symmetry:add-process-netstats
Nov 10, 2022
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,60 @@ | ||
// Licensed to Elasticsearch B.V. under one or more contributor | ||
// license agreements. See the NOTICE file distributed with | ||
// this work for additional information regarding copyright | ||
// ownership. Elasticsearch B.V. licenses this file to you under | ||
// the Apache License, Version 2.0 (the "License"); you may | ||
// not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
package network | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/elastic/go-sysinfo/types" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestFilter(t *testing.T) { | ||
exampleData := &types.NetworkCountersInfo{SNMP: types.SNMP{ | ||
IP: map[string]uint64{"DefaultTTL": 0x40, "ForwDatagrams": 0x3ef68, "Forwarding": 0x1, "FragCreates": 0x0, "FragFails": 0x0, "FragOKs": 0x0, "InAddrErrors": 0x2, | ||
"InDelivers": 0x132b5d, "InReceives": 0x1904f4, "InUnknownProtos": 0x0, "OutDiscards": 0x0, "OutNoRoutes": 0xe, | ||
"OutRequests": 0x143a7e}, | ||
ICMP: map[string]uint64{"InAddrMaskReps": 0x0}, | ||
ICMPMsg: map[string]uint64{"InType3": 0x2, "OutType3": 0x85}, | ||
TCP: map[string]uint64{"ActiveOpens": 0x63d, "AttemptFails": 0x72, "CurrEstab": 0x9, "EstabResets": 0x54, "InCsumErrors": 0x0, "InErrs": 0x0, "InSegs": 0x13270b, | ||
"MaxConn": 0xffffffffffffffff, "OutRsts": 0x2f6, "OutSegs": 0x111424}, | ||
UDP: map[string]uint64{"NoPorts": 0x1, "OutDatagrams": 0x4d5}, | ||
UDPLite: map[string]uint64{"SndbufErrors": 0x0}, | ||
}, | ||
Netstat: types.Netstat{ | ||
TCPExt: map[string]uint64{"TCPAbortOnClose": 0x6, "TCPAbortOnData": 0x51, "TCPAbortOnLinger": 0x0, "TCPAbortOnMemory": 0x0, | ||
"TCPAbortOnTimeout": 0x7f, "TCPAckCompressed": 0x3346, "TCPAutoCorking": 0x1063, "TCPBacklogCoalesce": 0x38a, "TCPBacklogDrop": 0x0, "TCPChallengeACK": 0x0, "TCPDSACKIgnoredDubious": 0x0, | ||
"TCPHPHits": 0x99fc8, "TCPHystartDelayCwnd": 0x294, "TCPHystartDelayDetect": 0x3, "TCPHystartTrainCwnd": 0xa1e}, | ||
IPExt: map[string]uint64{"InBcastOctets": 0x514d4c, "InBcastPkts": 0x1e999, "InCEPkts": 0x0, "InCsumErrors": 0x0, "InECT0Pkts": 0x0, "InECT1Pkts": 0x0, "InMcastOctets": 0x44a, | ||
"InMcastPkts": 0x12, "InNoECTPkts": 0x1ec6d9, "InNoRoutes": 0x0, "InOctets": 0x50701313, "OutMcastPkts": 0x71, "OutOctets": 0x47f14f8c, "ReasmOverlaps": 0x0}, | ||
}, | ||
} | ||
// test with no filter | ||
testAll := []string{"all"} | ||
allMap := MapProcNetCountersWithFilter(exampleData, testAll) | ||
require.Equal(t, len(exampleData.SNMP.ICMP)+len(exampleData.SNMP.ICMPMsg), len(allMap["icmp"].(map[string]interface{}))) | ||
require.Equal(t, len(exampleData.SNMP.TCP)+len(exampleData.Netstat.TCPExt), len(allMap["tcp"].(map[string]interface{}))) | ||
|
||
//test With filter | ||
testTwo := []string{"TCPAbortOnClose", "InBcastOctets"} | ||
filteredMap := MapProcNetCountersWithFilter(exampleData, testTwo) | ||
require.Equal(t, 1, len(filteredMap["tcp"].(map[string]interface{}))) | ||
require.Equal(t, uint64(0x6), filteredMap["tcp"].(map[string]interface{})["TCPAbortOnClose"]) | ||
|
||
require.Equal(t, uint64(0x514d4c), filteredMap["ip"].(map[string]interface{})["InBcastOctets"]) | ||
} |
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
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what if 2 maps have the same key, do we check twice?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, these values are only being merged across a given protocol, and in my experience, the kernel won't report the same metric for a given protocol twice, so it should be fine? Not sure how we would recover from that anyway, since it would seemingly be the same metric reported in two different places?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just realised that
checkMaxConn
would just do a type cast, it's not really a big deal to run it twice for the same key. So, the current logic is that the second map has a priority over the first if the keys collide, which I think is fine.