TSG-13626 tsg-service-chaining-engine发送Metrics

This commit is contained in:
luwenpeng
2023-02-28 19:03:35 +08:00
parent 92af3e1fee
commit ecfcc3d2d8
14 changed files with 554 additions and 9 deletions

View File

@@ -16,6 +16,7 @@
#include "log.h"
#include "uthash.h"
#include "bfd.h"
#include "sf_status.h"
#include "health_check.h"
@@ -32,6 +33,7 @@ struct session_table
};
static struct session_table g_handle;
static struct sf_status *g_sf_status = NULL;
struct session_iterm
{
@@ -72,6 +74,7 @@ void health_check_session_init(const char *profile)
MESA_load_profile_string_def(profile, "bfdd", "local_address", local_address, sizeof(local_address), "127.0.0.1");
MESA_load_profile_string_def(profile, "bfdd", "gateway", gateway_address, sizeof(gateway_address), "127.0.0.1");
g_sf_status = sf_status_create(profile);
// TODO: 循环获取?
get_mac_by_addr(gateway_address, default_gw_mac);
health_check_session_foreach();
@@ -239,10 +242,17 @@ static int get_mac_by_addr(char *addr, uint8_t *buf)
static void *_health_check_session_foreach(void *arg)
{
int is_active = 0;
int interval_s = sf_status_get_interval(g_sf_status);
struct bfd_vtysh_client client;
struct session_iterm *tmp = NULL;
struct session_iterm *node = NULL;
struct timespec current_time;
struct timespec g_status_last_send_time;
clock_gettime(CLOCK_MONOTONIC, &current_time);
clock_gettime(CLOCK_MONOTONIC, &g_status_last_send_time);
health_check_session_init_bfd_client(&client);
bfd_vtysh_connect(&client);
@@ -260,16 +270,45 @@ static void *_health_check_session_foreach(void *arg)
node->is_active = is_active;
if (node->is_active == 1) {
get_mac_by_addr(node->policy.address, node->mac);
sf_status_update(g_sf_status, node->session_id, 1, 0);
}
else {
memset(node->mac, 0, sizeof(node->mac));
sf_status_update(g_sf_status, node->session_id, 0, 0);
}
}
if (sleep_ms > node->policy.interval_ms)
sleep_ms = node->policy.interval_ms;
}
pthread_rwlock_unlock(&g_handle.rwlock);
usleep(sleep_ms*1000);
clock_gettime(CLOCK_MONOTONIC, &current_time);
if (current_time.tv_sec - g_status_last_send_time.tv_sec >= interval_s)
{
sf_status_send(g_sf_status);
clock_gettime(CLOCK_MONOTONIC, &g_status_last_send_time);
}
// interval_s : 1000 ms
// sleep_ms : 900 ms
if (interval_s * 1000 > sleep_ms)
{
usleep(sleep_ms * 1000);
}
// interval_s : 900 ms
// sleep_ms : 1000 ms
else
{
usleep(interval_s * 1000 * 1000);
clock_gettime(CLOCK_MONOTONIC, &current_time);
if (current_time.tv_sec - g_status_last_send_time.tv_sec >= interval_s)
{
sf_status_send(g_sf_status);
clock_gettime(CLOCK_MONOTONIC, &g_status_last_send_time);
}
usleep(sleep_ms * 1000 - interval_s * 1000 * 1000);
}
}
bfd_vtysh_close(&client);
}