diff options
author | Antoine Eiche <antoine.eiche@cloudwatt.com> | 2016-06-08 14:02:31 +0000 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2016-06-09 13:13:06 +0900 |
commit | 370f4ba1f03a52ffb6ecea2bfd56feb86b7c537f (patch) | |
tree | a9122be189ab1f3bd87d58face4792d2ae425281 /server | |
parent | 3d89b9245a6ccaa160de2e10c3ec57f966d62e2c (diff) |
collector: use AddrPrefixInterface.Flat to generate Prefix
The tag NLRI is also added to the update table.
Diffstat (limited to 'server')
-rw-r--r-- | server/collector.go | 16 |
1 files changed, 6 insertions, 10 deletions
diff --git a/server/collector.go b/server/collector.go index 2c0a47da..c1930d09 100644 --- a/server/collector.go +++ b/server/collector.go @@ -21,7 +21,6 @@ import ( "github.com/influxdata/influxdb/client/v2" "github.com/osrg/gobgp/packet/bgp" "github.com/osrg/gobgp/table" - "strings" "time" ) @@ -111,21 +110,18 @@ func path2data(path *table.Path) (map[string]interface{}, map[string]string) { fields["Med"] = med } - var prefix, prefixLen string - l := strings.Split(path.GetNlri().String(), "/") - if len(l) == 2 { - prefix = l[0] - prefixLen = l[1] - } tags := map[string]string{ "PeerAddress": path.GetSource().Address.String(), "PeerAS": fmt.Sprintf("%v", path.GetSource().AS), - "Prefix": prefix, - "PrefixLen": prefixLen, "NextHop": path.GetNexthop().String(), "OriginAS": fmt.Sprintf("%v", path.GetSourceAs()), "Timestamp": path.GetTimestamp().String(), } + + flat := path.GetNlri().Flat() + for key, value := range flat { + tags[key] = value + } return fields, tags } @@ -214,7 +210,7 @@ func NewCollector(grpcCh chan *GrpcRequest, url, dbName string, interval uint64) return nil, err } - q := client.NewQuery("CREATE DATABASE " + dbName, "", "") + q := client.NewQuery("CREATE DATABASE "+dbName, "", "") if response, err := c.Query(q); err != nil || response.Error() != nil { log.Error("can not create database " + dbName) return nil, err |