diff options
Diffstat (limited to 'decoders/ftp/ftp_decoder_stat.c')
| -rw-r--r-- | decoders/ftp/ftp_decoder_stat.c | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/decoders/ftp/ftp_decoder_stat.c b/decoders/ftp/ftp_decoder_stat.c new file mode 100644 index 0000000..f06e5bf --- /dev/null +++ b/decoders/ftp/ftp_decoder_stat.c @@ -0,0 +1,55 @@ +#ifdef __cplusplus +extern "C" +{ +#endif +#include <assert.h> +#include <fieldstat/fieldstat_easy.h> +#include "ftp_decoder_stat.h" +#include "ftp_decoder_inner.h" +#include "ftp_decoder_util.h" + + static const struct ftpd_stat_name_id_tuple g_ftpd_stat_tuple[] = + { + {FTPD_STAT_CTRL_LINK_NEW, "clink_open"}, + {FTPD_STAT_CTRL_LINK_FREE, "clink_close"}, + {FTPD_STAT_DATA_LINK_NEW, "dlink_open"}, + {FTPD_STAT_DATA_LINK_FREE, "dlink_close"}, + {FTPD_STAT_NEGOTIATE_DATA_LINK, "negotiate_dlink"}, + {FTPD_STAT_CTRL_LINK_BYTES_C2S, "clink_bytes_c2s"}, + {FTPD_STAT_CTRL_LINK_BYTES_S2C, "clink_bytes_s2c"}, + {FTPD_STAT_DATA_LINK_BYTES_C2S, "dlink_bytes_c2s"}, + {FTPD_STAT_DATA_LINK_BYTES_S2C, "dlink_bytes_s2c"}, + {FTPD_STAT_DATA_LINK_HTABLE_ITEMS, "dlink_hash_items"}, + {FTPD_STAT_CTRL_CMD, "ctrl_commands"}, + }; + + void ftp_decoder_stat_incrby(int thread_idx, struct ftp_decoder *ftp_env, enum ftp_decoder_stat_type stattype, long long increment) + { + if (ftp_env->stat.fs4_instance) + { + fieldstat_easy_counter_incrby(ftp_env->stat.fs4_instance, thread_idx, ftp_env->stat.fs4_counter_id[stattype], NULL, 0, increment); + } + } + + int ftp_decoder_stat_init(struct module_manager *mod_mgr, struct ftp_decoder *ftp_env) + { + assert(sizeof(g_ftpd_stat_tuple) / sizeof(struct ftpd_stat_name_id_tuple) == FTPD_STAT_MAX); + int thread_count = module_manager_get_max_thread_num(mod_mgr); + ftp_env->stat.fs4_instance = fieldstat_easy_new(thread_count, FTP_DECODER_FIELDSTAT_NAME, NULL, 0); + for (int i = 0; i < FTPD_STAT_MAX; i++) + { + ftp_env->stat.fs4_counter_id[i] = fieldstat_easy_register_counter(ftp_env->stat.fs4_instance, g_ftpd_stat_tuple[i].name); + } + fieldstat_easy_enable_auto_output(ftp_env->stat.fs4_instance, FTP_DECODER_FIELDSTAT_OUTPUT_FILE, FTP_DECODER_FIELDSTAT_OUTPUT_INTERVAL); + return 0; + } + + void ftp_decoder_stat_free(struct ftp_decoder *ftp_env) + { + fieldstat_easy_free(ftp_env->stat.fs4_instance); + ftp_env->stat.fs4_instance = NULL; + } + +#ifdef __cplusplus +} +#endif
\ No newline at end of file |
