diff options
Diffstat (limited to 'adapter')
-rw-r--r-- | adapter/stats_api.go | 2 | ||||
-rw-r--r-- | adapter/vppapiclient/stat_client.go | 7 | ||||
-rw-r--r-- | adapter/vppapiclient/stat_client_wrapper.h | 20 |
3 files changed, 24 insertions, 5 deletions
diff --git a/adapter/stats_api.go b/adapter/stats_api.go index 4087865..146914d 100644 --- a/adapter/stats_api.go +++ b/adapter/stats_api.go @@ -86,7 +86,7 @@ type Name string type ScalarStat float64 // ErrorStat represents stat for ErrorIndex. -type ErrorStat uint64 +type ErrorStat Counter // SimpleCounterStat represents stat for SimpleCounterVector. // The outer array represents workers and the inner array represents interface/node/.. indexes. diff --git a/adapter/vppapiclient/stat_client.go b/adapter/vppapiclient/stat_client.go index 2615b65..389c93b 100644 --- a/adapter/vppapiclient/stat_client.go +++ b/adapter/vppapiclient/stat_client.go @@ -71,6 +71,13 @@ func (c *statClient) Connect() error { sockName = c.socketName } + if _, err := os.Stat(sockName); err != nil { + if os.IsNotExist(err) { + return fmt.Errorf("stats socket file %q does not exists, ensure that VPP is running with `statseg { ... }` section in config", sockName) + } + return fmt.Errorf("stats socket file error: %v", err) + } + rc := C.govpp_stat_connect(C.CString(sockName)) if rc != 0 { return fmt.Errorf("connecting to VPP stats API failed (rc=%v)", rc) diff --git a/adapter/vppapiclient/stat_client_wrapper.h b/adapter/vppapiclient/stat_client_wrapper.h index 9178fb5..3fe0460 100644 --- a/adapter/vppapiclient/stat_client_wrapper.h +++ b/adapter/vppapiclient/stat_client_wrapper.h @@ -32,6 +32,10 @@ #if STAT_VERSION_MAJOR >= 1 && STAT_VERSION_MINOR >= 1 #define SUPPORTS_NAME_VECTOR // VPP 19.04 is required! #endif +// Error value was changed into vector in VPP 19.08 +#if STAT_VERSION_MAJOR >= 1 && STAT_VERSION_MINOR >= 2 + #define SUPPORTS_ERROR_VECTOR // VPP 19.08 is required! +#endif static int govpp_stat_connect(char *socket_name) @@ -93,10 +97,18 @@ govpp_stat_segment_data_get_scalar_value(stat_segment_data_t *data) return data->scalar_value; } -static double +static counter_t govpp_stat_segment_data_get_error_value(stat_segment_data_t *data) { - return data->error_value; +#ifdef SUPPORTS_ERROR_VECTOR + counter_t value = 0; + int j; + for (j = 0; j < stat_segment_vec_len(data->error_vector); j++) // VPP 19.08+ is required! + value += data->error_vector[j]; + return value; +#else + return data->error_value; // VPP <19.08 +#endif } static uint64_t** @@ -168,9 +180,9 @@ govpp_stat_segment_data_free(stat_segment_data_t *data) } static uint8_t** -govpp_stat_segment_string_vector(uint8_t ** string_vector, char *string) +govpp_stat_segment_string_vector(uint8_t **string_vec, char *s) { - return stat_segment_string_vector(string_vector, string); + return stat_segment_string_vector(string_vec, s); } #endif /* included_stat_client_wrapper_h */ |