Module: kamailio
Branch: master
Commit: d8bd9825fa401ad0a3489d246f29d05485b72831
URL:
https://github.com/kamailio/kamailio/commit/d8bd9825fa401ad0a3489d246f29d05…
Author: Alex Hermann <alex(a)hexla.nl>
Committer: Alex Hermann <alex(a)hexla.nl>
Date: 2020-10-19T15:29:40+02:00
mqueue: Add rpc mqueue.sizes
Return sizes for all queues
---
Modified: src/modules/mqueue/doc/mqueue_admin.xml
Modified: src/modules/mqueue/mqueue_api.c
Modified: src/modules/mqueue/mqueue_api.h
Modified: src/modules/mqueue/mqueue_mod.c
---
Diff:
https://github.com/kamailio/kamailio/commit/d8bd9825fa401ad0a3489d246f29d05…
Patch:
https://github.com/kamailio/kamailio/commit/d8bd9825fa401ad0a3489d246f29d05…
---
diff --git a/src/modules/mqueue/doc/mqueue_admin.xml
b/src/modules/mqueue/doc/mqueue_admin.xml
index 5309098058..7d785ac90b 100644
--- a/src/modules/mqueue/doc/mqueue_admin.xml
+++ b/src/modules/mqueue/doc/mqueue_admin.xml
@@ -300,6 +300,24 @@ xlog("L_INFO", "Size of queue is:
$var(q_size)\n");
...
&kamcmd; mqueue.fetch xyz
...
+</programlisting>
+ </example>
+ </section>
+
+ <section id="mqueue.r.get_sizes">
+ <title>mqueue.get_sizes</title>
+ <para>
+ Get the size for all memory queues.
+ </para>
+ <para>
+ Parameters: none
+ </para>
+ <example>
+ <title><function>mqueue.get_sizes</function> usage</title>
+ <programlisting format="linespecific">
+...
+&kamcmd; mqueue.get_sizes
+...
</programlisting>
</example>
</section>
diff --git a/src/modules/mqueue/mqueue_api.c b/src/modules/mqueue/mqueue_api.c
index 93204bba3c..4dd61c3e72 100644
--- a/src/modules/mqueue/mqueue_api.c
+++ b/src/modules/mqueue/mqueue_api.c
@@ -173,6 +173,9 @@ mq_head_t *mq_head_get(str *name)
mq_head_t *mh = NULL;
mh = _mq_head_list;
+ if (!name) {
+ return mh;
+ }
while(mh!=NULL)
{
if(name->len == mh->name.len
diff --git a/src/modules/mqueue/mqueue_api.h b/src/modules/mqueue/mqueue_api.h
index 843a7d7967..d60dfdf29a 100644
--- a/src/modules/mqueue/mqueue_api.h
+++ b/src/modules/mqueue/mqueue_api.h
@@ -77,6 +77,7 @@ int mq_head_add(str *name, int msize);
int mq_head_fetch(str *name);
void mq_pv_free(str *name);
int mq_item_add(str *qname, str *key, str *val);
+mq_head_t *mq_head_get(str *name);
int _mq_get_csize(str *);
int mq_set_dbmode(str *, int dbmode);
diff --git a/src/modules/mqueue/mqueue_mod.c b/src/modules/mqueue/mqueue_mod.c
index e3b984484e..325c84b472 100644
--- a/src/modules/mqueue/mqueue_mod.c
+++ b/src/modules/mqueue/mqueue_mod.c
@@ -327,6 +327,34 @@ static const char* mqueue_rpc_get_size_doc[2] = {
0
};
+static void mqueue_rpc_get_sizes(rpc_t* rpc, void* ctx)
+{
+ mq_head_t* mh = mq_head_get(NULL);
+ void* vh;
+ int size;
+
+ while(mh!=NULL)
+ {
+ if (rpc->add(ctx, "{", &vh) < 0) {
+ rpc->fault(ctx, 500, "Server error");
+ return;
+ }
+ lock_get(&mh->lock);
+ size = mh->csize;
+ lock_release(&mh->lock);
+ rpc->struct_add(vh, "Sd",
+ "name", &mh->name,
+ "size", size
+ );
+ mh = mh->next;
+ }
+}
+
+static const char* mqueue_rpc_get_sizes_doc[2] = {
+ "Get sizes of all mqueues.",
+ 0
+};
+
static void mqueue_rpc_fetch(rpc_t* rpc, void* ctx)
{
str mqueue_name;
@@ -392,6 +420,7 @@ static const char* mqueue_rpc_fetch_doc[2] = {
rpc_export_t mqueue_rpc[] = {
{"mqueue.get_size", mqueue_rpc_get_size, mqueue_rpc_get_size_doc, 0},
+ {"mqueue.get_sizes", mqueue_rpc_get_sizes, mqueue_rpc_get_sizes_doc,
RET_ARRAY},
{"mqueue.fetch", mqueue_rpc_fetch, mqueue_rpc_fetch_doc, 0},
{0, 0, 0, 0}
};