Skip to content

Commit

Permalink
Merge branch 'master' into bugfix/hex-tc-names
Browse files Browse the repository at this point in the history
  • Loading branch information
mum4k committed Mar 1, 2018
2 parents 576220a + 98a0b4b commit 668a9d3
Show file tree
Hide file tree
Showing 9 changed files with 138 additions and 120 deletions.
12 changes: 12 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
language: go
go:
- 1.8.x
- stable
script:
- go test ./...
- go tool vet .
- go tool vet ./lib
- diff -u <(echo -n) <(gofmt -d -s .)
- diff -u <(echo -n) <(gofmt -d -s ./lib)
after_success:
- ./scripts/coverage.sh
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
[![Build Status](https://travis-ci.org/mum4k/tc_reader.svg?branch=master)](https://travis-ci.org/mum4k/tc_reader)
[![Coverage Status](https://coveralls.io/repos/github/mum4k/tc_reader/badge.svg?branch=master)](
https://coveralls.io/github/mum4k/tc_reader?branch=master)

tc\_reader
=========

Expand Down
9 changes: 4 additions & 5 deletions lib/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ See the License for the specific language governing permissions and
limitations under the License.
*/


package lib

import (
Expand Down Expand Up @@ -45,10 +44,10 @@ func TestConfig(t *testing.T) {
[]string{"-s", "class", "show", "dev"},
[]string{"eth0", "eth1", "eth2"},
map[string]userClass{
"eth0:2:3": userClass{uploadDirection, "user1"},
"eth0:2:4": userClass{uploadDirection, "user2"},
"eth1:2:3": userClass{downloadDirection, "user1"},
"eth1:2:4": userClass{downloadDirection, "user2"},
"eth0:2:3": {uploadDirection, "user1"},
"eth0:2:4": {uploadDirection, "user2"},
"eth1:2:3": {downloadDirection, "user1"},
"eth1:2:4": {downloadDirection, "user2"},
},
true,
},
Expand Down
1 change: 0 additions & 1 deletion lib/oid_sorter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ See the License for the specific language governing permissions and
limitations under the License.
*/


package lib

import (
Expand Down
26 changes: 13 additions & 13 deletions lib/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ func (t *tcParser) start() {
t.parseTc()

go func() {
for _ = range time.Tick(time.Duration(t.options.parseInterval()) * time.Second) {
for range time.Tick(time.Duration(t.options.parseInterval()) * time.Second) {
t.parseTc()
}
}()
Expand All @@ -243,23 +243,23 @@ func (t *tcParser) executeTc(iface string) (string, string, error) {
// Executes the TC command to get statistics for Qdiscs and Classes on a interfaces and parses the output.
//
// Example output of 'tc -s qdisc show dev eth0':
// qdisc dsmark 1: root refcnt 2 indices 0x0010 default_index 0x0000
// Sent 8165477580 bytes 5927092 pkt (dropped 49112, overlimits 0 requeues 0)
// rate 0bit 0pps backlog 0b 0p requeues 0
// qdisc dsmark 1: root refcnt 2 indices 0x0010 default_index 0x0000
// Sent 8165477580 bytes 5927092 pkt (dropped 49112, overlimits 0 requeues 0)
// rate 0bit 0pps backlog 0b 0p requeues 0
// qdisc htb 2: parent 1: r2q 10 default 0 direct_packets_stat 42920
// Sent 8165477220 bytes 5927088 pkt (dropped 49112, overlimits 9389236 requeues 0)
// rate 0bit 0pps backlog 0b 0p requeues 0
// Sent 8165477220 bytes 5927088 pkt (dropped 49112, overlimits 9389236 requeues 0)
// rate 0bit 0pps backlog 0b 0p requeues 0
//
// Example output of 'tc -s class show dev eth0':
// class htb 2:1 root rate 3072Kbit ceil 3072Kbit burst 3141b cburst 3141b
// Sent 8092853284 bytes 5693309 pkt (dropped 0, overlimits 0 requeues 0)
// rate 22528bit 34pps backlog 0b 0p requeues 0
// class htb 2:1 root rate 3072Kbit ceil 3072Kbit burst 3141b cburst 3141b
// Sent 8092853284 bytes 5693309 pkt (dropped 0, overlimits 0 requeues 0)
// rate 22528bit 34pps backlog 0b 0p requeues 0
// lended: 4348128 borrowed: 0 giants: 0
// tokens: 124922 ctokens: 124922
//
// class htb 2:2 parent 2:1 leaf 3: prio 0 rate 614400bit ceil 614400bit burst 1907b cburst 1907b
// Sent 0 bytes 0 pkt (dropped 0, overlimits 0 requeues 0)
// rate 0bit 0pps backlog 0b 0p requeues 0
//
// class htb 2:2 parent 2:1 leaf 3: prio 0 rate 614400bit ceil 614400bit burst 1907b cburst 1907b
// Sent 0 bytes 0 pkt (dropped 0, overlimits 0 requeues 0)
// rate 0bit 0pps backlog 0b 0p requeues 0
// lended: 0 borrowed: 0 giants: 0
// tokens: 388171 ctokens: 388171
func (t *tcParser) parseTc() {
Expand Down
71 changes: 35 additions & 36 deletions lib/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ See the License for the specific language governing permissions and
limitations under the License.
*/


package lib

import (
Expand Down Expand Up @@ -132,8 +131,8 @@ func TestTcParserOptionsUserNameClass(t *testing.T) {
}{
{nil, map[string]userClass{}},
{
map[string]userClass{"1": userClass{1, "username"}},
map[string]userClass{"1": userClass{1, "username"}},
map[string]userClass{"1": {1, "username"}},
map[string]userClass{"1": {1, "username"}},
},
}

Expand Down Expand Up @@ -240,7 +239,7 @@ func TestTcParserExecuteTc(t *testing.T) {
[]error{nil, nil},
"eth0",
[]string{"/sbin/tc", "/sbin/tc"},
[][]string{[]string{"-s", "qdisc", "show", "dev", "eth0"}, []string{"-s", "class", "show", "dev", "eth0"}},
[][]string{{"-s", "qdisc", "show", "dev", "eth0"}, {"-s", "class", "show", "dev", "eth0"}},
"qdiscOutput",
"classOutput",
nil,
Expand All @@ -252,7 +251,7 @@ func TestTcParserExecuteTc(t *testing.T) {
[]error{nil, fmt.Errorf("an error")},
"eth0",
[]string{"/sbin/tc", "/sbin/tc"},
[][]string{[]string{"-s", "qdisc", "show", "dev", "eth0"}, []string{"-s", "class", "show", "dev", "eth0"}},
[][]string{{"-s", "qdisc", "show", "dev", "eth0"}, {"-s", "class", "show", "dev", "eth0"}},
"",
"",
fmt.Errorf("an error"),
Expand All @@ -264,7 +263,7 @@ func TestTcParserExecuteTc(t *testing.T) {
[]error{fmt.Errorf("an error"), nil},
"eth0",
[]string{"/sbin/tc"},
[][]string{[]string{"-s", "qdisc", "show", "dev", "eth0"}},
[][]string{{"-s", "qdisc", "show", "dev", "eth0"}},
"",
"",
fmt.Errorf("an error"),
Expand Down Expand Up @@ -386,18 +385,18 @@ func TestTcParserParse(t *testing.T) {
"testdata/tc_class_custom",
nil,
nil,
map[string]userClass{"1": userClass{1, "username"}},
map[string]userClass{"1": {1, "username"}},
"",
[]parsedData{
parsedData{"eth0:1:0", 12548819, 124105, 13, 25, nil},
parsedData{"eth0:2:0", 12548819, 24106, 128, 29, nil},
parsedData{"eth0:10:0", 123432, 1027, 11, 2048, nil},
parsedData{"eth0:110:0", 9397865, 102745, 0, 0, nil},
parsedData{"eth0:2:1", 931528, 9571, 127, 25, nil},
parsedData{"eth0:2:2", 11630676, 114607, 13, 5211, nil},
parsedData{"eth0:4:1", 11601665, 114364, 0, 0, nil},
parsedData{"eth0:4:10", 1096857, 7059, 0, 0, nil},
parsedData{"eth0:4:110", 256, 13, 7, 0, nil},
{"eth0:1:0", 12548819, 124105, 13, 25, nil},
{"eth0:2:0", 12548819, 24106, 128, 29, nil},
{"eth0:10:0", 123432, 1027, 11, 2048, nil},
{"eth0:110:0", 9397865, 102745, 0, 0, nil},
{"eth0:2:1", 931528, 9571, 127, 25, nil},
{"eth0:2:2", 11630676, 114607, 13, 5211, nil},
{"eth0:4:1", 11601665, 114364, 0, 0, nil},
{"eth0:4:10", 1096857, 7059, 0, 0, nil},
{"eth0:4:110", 256, 13, 7, 0, nil},
},
1,
1,
Expand All @@ -411,22 +410,22 @@ func TestTcParserParse(t *testing.T) {
nil,
nil,
map[string]userClass{
"eth0:4:1": userClass{0, "username"},
"eth0:4:10": userClass{1, "username"},
"eth0:4:1": {0, "username"},
"eth0:4:10": {1, "username"},
},
"",
[]parsedData{
parsedData{"eth0:1:0", 12548819, 124105, 13, 25, nil},
parsedData{"eth0:2:0", 12548819, 24106, 128, 29, nil},
parsedData{"eth0:10:0", 123432, 1027, 11, 2048, nil},
parsedData{"eth0:110:0", 9397865, 102745, 0, 0, nil},
parsedData{"eth0:2:1", 931528, 9571, 127, 25, nil},
parsedData{"eth0:2:2", 11630676, 114607, 13, 5211, nil},
parsedData{"eth0:4:1", 11601665, 114364, 0, 0, nil},
parsedData{"eth0:4:1", 11601665, 114364, 0, 0, &userClass{0, "username"}},
parsedData{"eth0:4:10", 1096857, 7059, 0, 0, nil},
parsedData{"eth0:4:10", 1096857, 7059, 0, 0, &userClass{1, "username"}},
parsedData{"eth0:4:110", 256, 13, 7, 0, nil},
{"eth0:1:0", 12548819, 124105, 13, 25, nil},
{"eth0:2:0", 12548819, 24106, 128, 29, nil},
{"eth0:10:0", 123432, 1027, 11, 2048, nil},
{"eth0:110:0", 9397865, 102745, 0, 0, nil},
{"eth0:2:1", 931528, 9571, 127, 25, nil},
{"eth0:2:2", 11630676, 114607, 13, 5211, nil},
{"eth0:4:1", 11601665, 114364, 0, 0, nil},
{"eth0:4:1", 11601665, 114364, 0, 0, &userClass{0, "username"}},
{"eth0:4:10", 1096857, 7059, 0, 0, nil},
{"eth0:4:10", 1096857, 7059, 0, 0, &userClass{1, "username"}},
{"eth0:4:110", 256, 13, 7, 0, nil},
},
1,
1,
Expand All @@ -440,12 +439,12 @@ func TestTcParserParse(t *testing.T) {
nil,
nil,
map[string]userClass{
"eth0:4:1": userClass{0, "username"},
"eth0:4:10": userClass{1, "username"},
"eth0:4:1": {0, "username"},
"eth0:4:10": {1, "username"},
},
"",
[]parsedData{
parsedData{"eth0:0:0", 8214, 48, 0, 10, nil},
{"eth0:0:0", 8214, 48, 0, 10, nil},
},
1,
1,
Expand All @@ -459,8 +458,8 @@ func TestTcParserParse(t *testing.T) {
fmt.Errorf("cannot execute"),
nil,
map[string]userClass{
"eth0:4:1": userClass{0, "username"},
"eth0:4:10": userClass{1, "username"},
"eth0:4:1": {0, "username"},
"eth0:4:10": {1, "username"},
},
"parseTc(): Unable to get TC command output, error: cannot execute",
[]parsedData{},
Expand All @@ -476,8 +475,8 @@ func TestTcParserParse(t *testing.T) {
nil,
nil,
map[string]userClass{
"eth0:4:1": userClass{0, "username"},
"eth0:4:10": userClass{1, "username"},
"eth0:4:1": {0, "username"},
"eth0:4:10": {1, "username"},
},
"",
[]parsedData{},
Expand Down
2 changes: 1 addition & 1 deletion lib/snmp.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ type snmpData struct {
// oid is the OID of this SNMP data.
oid string

// objectType is the SNMP object type, one of: integer, gauge, counter, timeticks, ipaddress, objectid, or string
// objectType is the SNMP object type, one of: integer, gauge, counter, timeticks, ipaddress, objectid, or string
objectType string

// objectValue is the value stored in this OID.
Expand Down
Loading

0 comments on commit 668a9d3

Please sign in to comment.