Răsfoiți Sursa

kex: expose access to pkg stats

Ovidiu Sas 1 an în urmă
părinte
comite
b0d16cafcf

+ 53 - 0
src/modules/kex/api.c

@@ -0,0 +1,53 @@
+/**
+ * Copyright (C) 2024 Ovidiu Sas (VoIP Embedded, Inc)
+ *
+ * This file is part of Kamailio, a free SIP server.
+ *
+ * This file is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version
+ *
+ *
+ * This file is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ */
+
+/*!
+ * \file
+ * \brief API integration
+ * \ingroup kex
+ * Module: \ref kex
+ */
+
+#include <stddef.h>
+
+#include "api.h"
+#include "pkg_stats.h"
+#include "../../core/mod_fix.h"
+
+int get_pkmem_stats_api(pkg_proc_stats_t **_pkg_procstatslist)
+{
+	*_pkg_procstatslist = get_pkg_proc_stats_list();
+	return get_pkg_proc_stats_no();
+}
+
+/*
+ * Function to load the kex api.
+ */
+int bind_kex(kex_api_t *kob)
+{
+	if(kob == NULL) {
+		LM_WARN("Cannot load kex API into a NULL pointer\n");
+		return -1;
+	}
+	kob->get_pkmem_stats = get_pkmem_stats_api;
+	return 0;
+}

+ 68 - 0
src/modules/kex/api.h

@@ -0,0 +1,68 @@
+/**
+ * Copyright (C) 2024 Ovidiu Sas (VoIP Embedded, Inc)
+ *
+ * This file is part of Kamailio, a free SIP server.
+ *
+ * This file is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version
+ *
+ *
+ * This file is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ */
+
+/*!
+ * \file
+ * \brief API
+ * \ingroup kex
+ * Module: \ref kex
+ */
+
+#include "pkg_stats.h"
+#include "../../core/sr_module.h"
+
+#ifndef _KEX_API_H_
+#define _KEX_API_H_
+
+typedef int (*kex_get_pkmem_stats_f)(pkg_proc_stats_t **_pkg_procstatslist);
+
+/*
+ * Struct with the kex api.
+ */
+typedef struct kex_binds
+{
+	kex_get_pkmem_stats_f get_pkmem_stats;
+} kex_api_t;
+
+typedef int (*bind_kex_f)(kex_api_t *);
+
+/*
+ * function exported by module - it will load the other functions
+ */
+int bind_kex(kex_api_t *);
+
+/*
+ * Function to be called directly from other modules to load
+ * the kex API.
+ */
+inline static int load_kex_api(kex_api_t *kob)
+{
+	bind_kex_f bind_kex_exports;
+
+	if(!(bind_kex_exports = (bind_kex_f)find_export("bind_kex", 0, 0))) {
+		LM_ERR("Failed to import bind_kex\n");
+		return -1;
+	}
+	return bind_kex_exports(kob);
+}
+
+#endif /*_KEX_API_H_*/

+ 2 - 0
src/modules/kex/kex_mod.c

@@ -41,6 +41,7 @@
 #include "core_stats.h"
 #include "pkg_stats.h"
 #include "mod_stats.h"
+#include "api.h"
 
 
 MODULE_VERSION
@@ -105,6 +106,7 @@ static cmd_export_t cmds[] = {
 	{"setdebug", (cmd_function)w_setdebug, 1, fixup_igp_null,
 			fixup_free_igp_null, ANY_ROUTE},
 	{"resetdebug", (cmd_function)w_resetdebug, 0, 0, 0, ANY_ROUTE},
+	{"bind_kex", (cmd_function)bind_kex, 0, 0, 0, 0},
 
 	{0, 0, 0, 0, 0, 0}
 };

+ 13 - 11
src/modules/kex/pkg_stats.c

@@ -39,31 +39,33 @@
 #include "../../core/mem/shm_mem.h"
 #include "../../core/rpc.h"
 #include "../../core/rpc_lookup.h"
+#include "pkg_stats.h"
 
+/**
+ *
+ */
+static pkg_proc_stats_t *_pkg_proc_stats_list = NULL;
 
 /**
  *
  */
-typedef struct pkg_proc_stats
+pkg_proc_stats_t *get_pkg_proc_stats_list(void)
 {
-	int rank;
-	unsigned int pid;
-	unsigned long used;
-	unsigned long available;
-	unsigned long real_used;
-	unsigned long total_frags;
-	unsigned long total_size;
-} pkg_proc_stats_t;
+	return _pkg_proc_stats_list;
+}
 
 /**
  *
  */
-static pkg_proc_stats_t *_pkg_proc_stats_list = NULL;
+static int _pkg_proc_stats_no = 0;
 
 /**
  *
  */
-static int _pkg_proc_stats_no = 0;
+int get_pkg_proc_stats_no(void)
+{
+	return _pkg_proc_stats_no;
+}
 
 /**
  *

+ 17 - 0
src/modules/kex/pkg_stats.h

@@ -25,14 +25,31 @@
  * \ingroup kex
  */
 
+#include "../../core/dprint.h"
 
 #ifndef _PKG_STATS_H_
 #define _PKG_STATS_H_
 
+/*
+ *
+ */
+typedef struct pkg_proc_stats
+{
+	int rank;
+	unsigned int pid;
+	unsigned long used;
+	unsigned long available;
+	unsigned long real_used;
+	unsigned long total_frags;
+	unsigned long total_size;
+} pkg_proc_stats_t;
+
 int pkg_proc_stats_init(void);
 int pkg_proc_stats_myinit(int rank);
 int pkg_proc_stats_destroy(void);
 int register_pkg_proc_stats(void);
 int pkg_proc_stats_init_rpc(void);
+pkg_proc_stats_t *get_pkg_proc_stats_list(void);
+int get_pkg_proc_stats_no(void);
 
 #endif /*_PKG_STATS_H_*/