diff options
author | Ondrej Fabry <ofabry@cisco.com> | 2019-04-11 10:59:49 +0200 |
---|---|---|
committer | Ondrej Fabry <ofabry@cisco.com> | 2019-04-11 10:59:49 +0200 |
commit | df1b888a2bfadefadc7dbfce59d34f811ff002ec (patch) | |
tree | 054ac4d90c744b867255e8e88ac0c38bd46e8d64 /adapter | |
parent | 3dc9b9885e3d7041a7c349185dc88f3bed50be6d (diff) |
Add support for names vector and fill name in interface/node stats
Change-Id: I3a6bcb635701c0f00e47d04fce2113e1ac23b67b
Signed-off-by: Ondrej Fabry <ofabry@cisco.com>
Diffstat (limited to 'adapter')
-rw-r--r-- | adapter/stats_api.go | 18 | ||||
-rw-r--r-- | adapter/vppapiclient/stat_client.go | 28 |
2 files changed, 40 insertions, 6 deletions
diff --git a/adapter/stats_api.go b/adapter/stats_api.go index 3538176..4087865 100644 --- a/adapter/stats_api.go +++ b/adapter/stats_api.go @@ -39,10 +39,11 @@ type StatType int const ( _ StatType = 0 - ScalarIndex = 1 - SimpleCounterVector = 2 - CombinedCounterVector = 3 - ErrorIndex = 4 + ScalarIndex StatType = 1 + SimpleCounterVector StatType = 2 + CombinedCounterVector StatType = 3 + ErrorIndex StatType = 4 + NameVector StatType = 5 ) func (d StatType) String() string { @@ -55,6 +56,8 @@ func (d StatType) String() string { return "CombinedCounterVector" case ErrorIndex: return "ErrorIndex" + case NameVector: + return "NameVector" } return fmt.Sprintf("UnknownStatType(%d)", d) } @@ -76,6 +79,9 @@ type CombinedCounter struct { Bytes Counter } +// Name represents string value stored under name vector. +type Name string + // ScalarStat represents stat for ScalarIndex. type ScalarStat float64 @@ -92,6 +98,9 @@ type SimpleCounterStat [][]Counter // Values should be aggregated per interface/node for every worker. type CombinedCounterStat [][]CombinedCounter +// NameStat represents stat for NameVector. +type NameStat []Name + // Data represents some type of stat which is usually defined by StatType. type Stat interface { // isStat is unexported to limit implementations of Data interface to this package, @@ -102,3 +111,4 @@ func (ScalarStat) isStat() {} func (ErrorStat) isStat() {} func (SimpleCounterStat) isStat() {} func (CombinedCounterStat) isStat() {} +func (NameStat) isStat() {} diff --git a/adapter/vppapiclient/stat_client.go b/adapter/vppapiclient/stat_client.go index df192f6..a2a9826 100644 --- a/adapter/vppapiclient/stat_client.go +++ b/adapter/vppapiclient/stat_client.go @@ -40,7 +40,7 @@ govpp_stat_disconnect() } static uint32_t* -govpp_stat_segment_ls(uint8_t ** pattern) +govpp_stat_segment_ls(uint8_t **pattern) { return stat_segment_ls(pattern); } @@ -135,6 +135,18 @@ govpp_stat_segment_data_get_combined_counter_index_bytes(stat_segment_data_t *da return data->combined_counter_vec[index][index2].bytes; } +static uint8_t** +govpp_stat_segment_data_get_name_vector(stat_segment_data_t *data) +{ + return data->name_vector; +} + +static char* +govpp_stat_segment_data_get_name_vector_index(stat_segment_data_t *data, int index) +{ + return data->name_vector[index]; +} + static void govpp_stat_segment_data_free(stat_segment_data_t *data) { @@ -268,8 +280,20 @@ func (c *statClient) DumpStats(patterns ...string) (stats []*adapter.StatEntry, } stat.Data = adapter.CombinedCounterStat(vector) + case adapter.NameVector: + length := int(C.govpp_stat_segment_vec_len(unsafe.Pointer(C.govpp_stat_segment_data_get_name_vector(&v)))) + var vector []adapter.Name + for k := 0; k < length; k++ { + s := C.govpp_stat_segment_data_get_name_vector_index(&v, C.int(k)) + if s == nil { + continue + } + vector = append(vector, adapter.Name(C.GoString(s))) + } + stat.Data = adapter.NameStat(vector) + default: - fmt.Fprintf(os.Stderr, "invalid stat type: %v (%d)", typ, typ) + fmt.Fprintf(os.Stderr, "invalid stat type: %v (%v)\n", typ, name) continue } |