summaryrefslogtreecommitdiff
path: root/src/ftp_decoder_stat.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/ftp_decoder_stat.cpp')
-rw-r--r--src/ftp_decoder_stat.cpp54
1 files changed, 54 insertions, 0 deletions
diff --git a/src/ftp_decoder_stat.cpp b/src/ftp_decoder_stat.cpp
new file mode 100644
index 0000000..ac5f1ce
--- /dev/null
+++ b/src/ftp_decoder_stat.cpp
@@ -0,0 +1,54 @@
+#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_config_tuple g_ftpd_stat_tuple[] =
+ {
+ {FTPD_STAT_CTRL_LINK_OPEN, "clink_open"},
+ {FTPD_STAT_CTRL_LINK_CLOSE, "clink_close"},
+ {FTPD_STAT_DATA_LINK_OPEN, "dlink_open"},
+ {FTPD_STAT_DATA_LINK_CLOSE, "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_CTRL_CMD, "ctrl_cmd"},
+};
+
+void ftp_decoder_stat_incrby(int thread_idx, struct ftp_decoder_env *fenv, enum ftp_decoder_stat_type stattype, long long increment)
+{
+ if (fenv->fstat.fs4_instance)
+ {
+ fieldstat_easy_counter_incrby(fenv->fstat.fs4_instance, thread_idx, fenv->fstat.fs4_counter_id[stattype], NULL, 0, increment);
+ }
+}
+
+int ftp_decoder_stat_init(struct ftp_decoder_env *fenv)
+{
+ assert(sizeof(g_ftpd_stat_tuple) / sizeof(struct ftpd_stat_config_tuple) == FTPD_STAT_MAX);
+ fenv->fstat.fs4_instance = fieldstat_easy_new(fenv->thread_count, FTP_DECODER_FIELDSTAT_NAME, NULL, 0);
+
+ for (int i = 0; i < FTPD_STAT_MAX; i++)
+ {
+ fenv->fstat.fs4_counter_id[i] = fieldstat_easy_register_counter(fenv->fstat.fs4_instance, g_ftpd_stat_tuple[i].name);
+ }
+ ftp_mkdir_p("./metrics", 0644);
+ int ret = fieldstat_easy_enable_auto_output(fenv->fstat.fs4_instance, FTP_DECODER_FIELDSTAT_OUTPUT_FILE, FTP_DECODER_FIELDSTAT_OUTPUT_INTERVAL);
+ if (ret < 0)
+ {
+ fprintf(stderr, "fieldstat_easy_enable_auto_output '%s' failed\n", FTP_DECODER_FIELDSTAT_OUTPUT_FILE);
+ fieldstat_easy_free(fenv->fstat.fs4_instance);
+ fenv->fstat.fs4_instance = NULL;
+ return -1;
+ }
+ return 0;
+}
+
+void ftp_decoder_stat_free(struct ftp_decoder_env *fenv)
+{
+ fieldstat_easy_free(fenv->fstat.fs4_instance);
+ fenv->fstat.fs4_instance = NULL;
+} \ No newline at end of file