Merge branch 'master' into patch-1

This commit is contained in:
Baptiste Mille-Mathias 2016-05-11 07:17:54 +02:00
commit 1f78983f96
4 changed files with 76 additions and 60 deletions

View File

@ -48,7 +48,15 @@ based on _prefix_ in addition to globs. This means that a filter like
- disque: `host -> disque_host`
- rethinkdb: `host -> rethinkdb_host`
- **Breaking Change**: The `win_perf_counters` input has been changed to sanitize field names, replacing `/Sec` and `/sec` with `_persec`, as well as spaces with underscores. This is needed because Graphite doesn't like slashes and spaces, and was failing to accept metrics that had them. The `/[sS]ec` -> `_persec` is just to make things clearer and uniform.
- **Breaking Change**: The `win_perf_counters` input has been changed to
sanitize field names, replacing `/Sec` and `/sec` with `_persec`, as well as
spaces with underscores. This is needed because Graphite doesn't like slashes
and spaces, and was failing to accept metrics that had them.
The `/[sS]ec` -> `_persec` is just to make things clearer and uniform.
- **Breaking Change**: snmp plugin. The `host` tag of the snmp plugin has been
changed to the `snmp_host` tag.
- The `disk` input plugin can now be configured with the `HOST_MOUNT_PREFIX` environment variable.
This value is prepended to any mountpaths discovered before retrieving stats.
It is not included on the report path. This is necessary for reporting host disk stats when running from within a container.

View File

@ -638,8 +638,8 @@
#
# ## If no servers are specified, then default to 127.0.0.1:1936
# servers = ["http://myhaproxy.com:1936", "http://anotherhaproxy.com:1936"]
# ## Or you can also use local socket(not work yet)
# ## servers = ["socket://run/haproxy/admin.sock"]
# ## Or you can also use local socket
# ## servers = ["socket:/run/haproxy/admin.sock"]
# # HTTP/HTTPS request given an address a method and a timeout

View File

@ -26,9 +26,6 @@ type Snmp struct {
nameToOid map[string]string
initNode Node
subTableMap map[string]Subtable
// TODO change as unexportable
//OidInstanceMapping map[string]map[string]string
}
type Host struct {
@ -53,6 +50,8 @@ type Host struct {
// array of processed oids
// to skip oid duplication
processedOids []string
OidInstanceMapping map[string]map[string]string
}
type Table struct {
@ -116,9 +115,6 @@ type Node struct {
subnodes map[string]Node
}
// TODO move this var to snmp struct
var OidInstanceMapping = make(map[string]map[string]string)
var sampleConfig = `
## Use 'oids.txt' file to translate oids to names
## To generate 'oids.txt' you need to run:
@ -396,7 +392,7 @@ func (s *Snmp) Gather(acc telegraf.Accumulator) error {
// TODO save mapping and computed oids
// to do it only the first time
// only if len(s.OidInstanceMapping) == 0
if len(OidInstanceMapping) >= 0 {
if len(host.OidInstanceMapping) >= 0 {
if err := host.SNMPMap(acc, s.nameToOid, s.subTableMap); err != nil {
log.Printf("SNMP Mapping error for host '%s': %s", host.Address, err)
continue
@ -413,7 +409,14 @@ func (s *Snmp) Gather(acc telegraf.Accumulator) error {
return nil
}
func (h *Host) SNMPMap(acc telegraf.Accumulator, nameToOid map[string]string, subTableMap map[string]Subtable) error {
func (h *Host) SNMPMap(
acc telegraf.Accumulator,
nameToOid map[string]string,
subTableMap map[string]Subtable,
) error {
if h.OidInstanceMapping == nil {
h.OidInstanceMapping = make(map[string]map[string]string)
}
// Get snmp client
snmpClient, err := h.GetSNMPClient()
if err != nil {
@ -523,11 +526,11 @@ func (h *Host) SNMPMap(acc telegraf.Accumulator, nameToOid map[string]string, su
// Building mapping table
mapping := map[string]string{strings.Trim(key, "."): string(variable.Value.([]byte))}
_, exists := OidInstanceMapping[table.oid]
_, exists := h.OidInstanceMapping[table.oid]
if exists {
OidInstanceMapping[table.oid][strings.Trim(key, ".")] = string(variable.Value.([]byte))
h.OidInstanceMapping[table.oid][strings.Trim(key, ".")] = string(variable.Value.([]byte))
} else {
OidInstanceMapping[table.oid] = mapping
h.OidInstanceMapping[table.oid] = mapping
}
// Add table oid in bulk oid list
@ -720,7 +723,12 @@ func (h *Host) GetSNMPClient() (*gosnmp.GoSNMP, error) {
return snmpClient, nil
}
func (h *Host) HandleResponse(oids map[string]Data, result *gosnmp.SnmpPacket, acc telegraf.Accumulator, initNode Node) (string, error) {
func (h *Host) HandleResponse(
oids map[string]Data,
result *gosnmp.SnmpPacket,
acc telegraf.Accumulator,
initNode Node,
) (string, error) {
var lastOid string
for _, variable := range result.Variables {
lastOid = variable.Name
@ -755,7 +763,7 @@ func (h *Host) HandleResponse(oids map[string]Data, result *gosnmp.SnmpPacket, a
strings.Split(string(variable.Name[1:]), "."))
// Set instance tag
// From mapping table
mapping, inMappingNoSubTable := OidInstanceMapping[oid_key]
mapping, inMappingNoSubTable := h.OidInstanceMapping[oid_key]
if inMappingNoSubTable {
// filter if the instance in not in
// OidInstanceMapping mapping map
@ -784,7 +792,7 @@ func (h *Host) HandleResponse(oids map[string]Data, result *gosnmp.SnmpPacket, a
// Because the result oid is equal to inputs.snmp.get section
field_name = oid.Name
}
tags["host"], _, _ = net.SplitHostPort(h.Address)
tags["snmp_host"], _, _ = net.SplitHostPort(h.Address)
fields := make(map[string]interface{})
fields[string(field_name)] = variable.Value

View File

@ -102,8 +102,8 @@ func TestSNMPGet1(t *testing.T) {
"oid1": uint(543846),
},
map[string]string{
"unit": "octets",
"host": testutil.GetLocalHost(),
"unit": "octets",
"snmp_host": testutil.GetLocalHost(),
},
)
}
@ -140,8 +140,8 @@ func TestSNMPGet2(t *testing.T) {
"ifNumber": int(4),
},
map[string]string{
"instance": "0",
"host": testutil.GetLocalHost(),
"instance": "0",
"snmp_host": testutil.GetLocalHost(),
},
)
}
@ -180,9 +180,9 @@ func TestSNMPGet3(t *testing.T) {
"ifSpeed": uint(10000000),
},
map[string]string{
"unit": "octets",
"instance": "1",
"host": testutil.GetLocalHost(),
"unit": "octets",
"instance": "1",
"snmp_host": testutil.GetLocalHost(),
},
)
}
@ -222,9 +222,9 @@ func TestSNMPEasyGet4(t *testing.T) {
"ifSpeed": uint(10000000),
},
map[string]string{
"unit": "octets",
"instance": "1",
"host": testutil.GetLocalHost(),
"unit": "octets",
"instance": "1",
"snmp_host": testutil.GetLocalHost(),
},
)
@ -234,8 +234,8 @@ func TestSNMPEasyGet4(t *testing.T) {
"ifNumber": int(4),
},
map[string]string{
"instance": "0",
"host": testutil.GetLocalHost(),
"instance": "0",
"snmp_host": testutil.GetLocalHost(),
},
)
}
@ -275,9 +275,9 @@ func TestSNMPEasyGet5(t *testing.T) {
"ifSpeed": uint(10000000),
},
map[string]string{
"unit": "octets",
"instance": "1",
"host": testutil.GetLocalHost(),
"unit": "octets",
"instance": "1",
"snmp_host": testutil.GetLocalHost(),
},
)
@ -287,8 +287,8 @@ func TestSNMPEasyGet5(t *testing.T) {
"ifNumber": int(4),
},
map[string]string{
"instance": "0",
"host": testutil.GetLocalHost(),
"instance": "0",
"snmp_host": testutil.GetLocalHost(),
},
)
}
@ -320,8 +320,8 @@ func TestSNMPEasyGet6(t *testing.T) {
"ifNumber": int(4),
},
map[string]string{
"instance": "0",
"host": testutil.GetLocalHost(),
"instance": "0",
"snmp_host": testutil.GetLocalHost(),
},
)
}
@ -360,9 +360,9 @@ func TestSNMPBulk1(t *testing.T) {
"ifOutOctets": uint(543846),
},
map[string]string{
"unit": "octets",
"instance": "1",
"host": testutil.GetLocalHost(),
"unit": "octets",
"instance": "1",
"snmp_host": testutil.GetLocalHost(),
},
)
@ -372,9 +372,9 @@ func TestSNMPBulk1(t *testing.T) {
"ifOutOctets": uint(26475179),
},
map[string]string{
"unit": "octets",
"instance": "2",
"host": testutil.GetLocalHost(),
"unit": "octets",
"instance": "2",
"snmp_host": testutil.GetLocalHost(),
},
)
@ -384,9 +384,9 @@ func TestSNMPBulk1(t *testing.T) {
"ifOutOctets": uint(108963968),
},
map[string]string{
"unit": "octets",
"instance": "3",
"host": testutil.GetLocalHost(),
"unit": "octets",
"instance": "3",
"snmp_host": testutil.GetLocalHost(),
},
)
@ -396,9 +396,9 @@ func TestSNMPBulk1(t *testing.T) {
"ifOutOctets": uint(12991453),
},
map[string]string{
"unit": "octets",
"instance": "36",
"host": testutil.GetLocalHost(),
"unit": "octets",
"instance": "36",
"snmp_host": testutil.GetLocalHost(),
},
)
}
@ -438,9 +438,9 @@ func dTestSNMPBulk2(t *testing.T) {
"ifOutOctets": uint(543846),
},
map[string]string{
"unit": "octets",
"instance": "1",
"host": testutil.GetLocalHost(),
"unit": "octets",
"instance": "1",
"snmp_host": testutil.GetLocalHost(),
},
)
@ -450,9 +450,9 @@ func dTestSNMPBulk2(t *testing.T) {
"ifOutOctets": uint(26475179),
},
map[string]string{
"unit": "octets",
"instance": "2",
"host": testutil.GetLocalHost(),
"unit": "octets",
"instance": "2",
"snmp_host": testutil.GetLocalHost(),
},
)
@ -462,9 +462,9 @@ func dTestSNMPBulk2(t *testing.T) {
"ifOutOctets": uint(108963968),
},
map[string]string{
"unit": "octets",
"instance": "3",
"host": testutil.GetLocalHost(),
"unit": "octets",
"instance": "3",
"snmp_host": testutil.GetLocalHost(),
},
)
@ -474,9 +474,9 @@ func dTestSNMPBulk2(t *testing.T) {
"ifOutOctets": uint(12991453),
},
map[string]string{
"unit": "octets",
"instance": "36",
"host": testutil.GetLocalHost(),
"unit": "octets",
"instance": "36",
"snmp_host": testutil.GetLocalHost(),
},
)
}