This repository has been archived on 2025-09-14. You can view files and clone it, but cannot push or open issues or pull requests.
Files
tango-tfe/common/src/tfe_fieldstat.cpp

70 lines
2.2 KiB
C++
Raw Normal View History

#include <stdlib.h>
#include <tfe_fieldstat.h>
#include "tfe_stream.h"
#include "tfe_resource.h"
2024-01-19 10:52:42 +08:00
#include "tfe_packet_io.h"
int tfe_fieldstat_easy_incrby(struct tfe_fieldstat_easy_t *fieldstat, unsigned int counter_id, long long value, const struct fieldstat_tag tags[], int n_tags, int thread_id)
{
return fieldstat_easy_counter_incrby(fieldstat->fseasy, thread_id, counter_id, tags, (size_t)n_tags, value);
}
struct tfe_fieldstat_easy_t *tfe_fieldstat_easy_create(char *app_name, char *outpath, int cycle, int max_thread, void *local_logger)
{
const char *counter_field[COLUMN_MAX] = {"hit_count", "in_bytes", "out_bytes", "in_pkts", "out_pkts"};
struct fieldstat_tag metric_tags[TAG_MAX - 1] = {{"vsys_id", TAG_INTEGER, -1}, {"rule_id", TAG_INTEGER, -1}, {"action", TAG_INTEGER, -1}, {"sub_action", TAG_CSTRING, -1}};
struct tfe_fieldstat_easy_t *fieldstat = ALLOC(struct tfe_fieldstat_easy_t, 1);
fieldstat->fseasy = fieldstat_easy_new(max_thread, app_name, NULL, 0);
if(!fieldstat->fseasy)
{
TFE_LOG_ERROR(local_logger, "fieldstat4 easy instance init failed.");
FREE(&fieldstat);
return NULL;
}
fieldstat_easy_enable_auto_output(fieldstat->fseasy, outpath, cycle);
for(int i=0; i<COLUMN_MAX; i++)
{
fieldstat->counter_array[i]=fieldstat_easy_register_counter(fieldstat->fseasy, counter_field[i]);
if(fieldstat->counter_array[i] < 0)
{
TFE_LOG_ERROR(local_logger, "fieldstat4 easy register counter failed.");
FREE(&fieldstat);
return NULL;
}
}
fieldstat->tags = ALLOC(struct fieldstat_tag*, max_thread);
for (int i = 0; i < max_thread; i++)
{
fieldstat->tags[i] = ALLOC(struct fieldstat_tag, TAG_MAX-1);
memcpy(fieldstat->tags[i], metric_tags, sizeof(struct fieldstat_tag) * (size_t)(TAG_MAX-1));
}
return fieldstat;
}
void tfe_fieldstat_easy_destroy(struct tfe_fieldstat_easy_t *fieldstat)
{
if(fieldstat)
{
if(fieldstat->fseasy)
{
fieldstat_easy_free(fieldstat->fseasy);
}
for (int i = 0; i < fieldstat->max_thread; i++)
{
if (fieldstat->tags[i])
{
FREE(&fieldstat->tags[i]);
}
}
FREE(&fieldstat->tags);
FREE(&fieldstat);
}
}