Skip to content
This repository has been archived by the owner on Feb 13, 2025. It is now read-only.

cmd/scollector: Get Ip Addresses and subnetmask in windows. #1389

Merged
merged 1 commit into from
Oct 7, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions cmd/scollector/collectors/collectors.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"net"
"os"
"sort"
"strings"
"sync"
"time"
Expand Down Expand Up @@ -283,6 +284,7 @@ func metaIfaces(f func(iface net.Interface, tags opentsdb.TagSet)) {
for i, rAd := range rawAds {
addrs[i] = rAd.String()
}
sort.Strings(addrs)
j, _ := json.Marshal(addrs)
metadata.AddMeta("", tags, "addresses", string(j), true)
if f != nil {
Expand Down
28 changes: 23 additions & 5 deletions cmd/scollector/collectors/metadata_windows.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package collectors

import (
"encoding/json"
"fmt"
"net"
"sort"
"strings"
"time"

Expand Down Expand Up @@ -114,6 +117,22 @@ func c_meta_windows_ifaces() (opentsdb.MultiDataPoint, error) {
return md, err
}

mNicIndextoIPs := make(map[int]string)
ifaces, _ := net.Interfaces()
for _, iface := range ifaces {
if iface.Flags&(net.FlagLoopback|net.FlagPointToPoint) != 0 {
continue
}
rawAds, _ := iface.Addrs()
addrs := make([]string, len(rawAds))
for i, rAd := range rawAds {
addrs[i] = rAd.String()
}
sort.Strings(addrs)
j, _ := json.Marshal(addrs)
mNicIndextoIPs[iface.Index] = string(j)
}

for _, v := range dstAdapters {
tag := opentsdb.TagSet{"iface": fmt.Sprint("Interface", v.InterfaceIndex)}
metadata.AddMeta("", tag, "description", v.Description, true)
Expand All @@ -131,12 +150,11 @@ func c_meta_windows_ifaces() (opentsdb.MultiDataPoint, error) {
metadata.AddMeta("", tag, "master", nicMaster, true)
}

nicConfig := mNicConfigs[v.InterfaceIndex]
if nicConfig != nil {
for _, ip := range *nicConfig.IPAddress {
metadata.AddMeta("", tag, "addr", ip, true) // blocked by array support in WMI See https://github.com/StackExchange/wmi/issues/5
}
nicIPs := mNicIndextoIPs[int(v.InterfaceIndex)]
if nicIPs == "" {
nicIPs = "[]"
}
metadata.AddMeta("", tag, "addresses", nicIPs, true)
}
return md, nil
}
Expand Down