Browse Source

snmpstats Add SNMP support for shared memory

This is just the first proof-of-concept addition, will add more of the
core variables for memory and TCP connections
Olle E. Johansson 12 years ago
parent
commit
3580d7fbc3

+ 126 - 0
modules/snmpstats/kamailioServer.c

@@ -0,0 +1,126 @@
+/*
+ *
+ * SNMPStats Module 
+ * Copyright (C) 2006 SOMA Networks, INC.
+ * Written by: Jeffrey Magder ([email protected])
+ *
+ * Kamailio Server core objects addition
+ * Copyright (C) 2013 Edvina AB, Sollentuna, Sweden
+ * Written by Olle E. Johansson
+ *
+ * This file is part of Kamailio, a free SIP server.
+ *
+ * Kamailio 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
+ *
+ * Kamailio 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA
+ *
+ * History:
+ * --------
+ * 2013-03-24 initial version (oej)
+ * 
+ * Note: this file originally auto-generated by mib2c 
+ *
+ */
+
+#include <net-snmp/net-snmp-config.h>
+#include <net-snmp/net-snmp-includes.h>
+#include <net-snmp/agent/net-snmp-agent-includes.h>
+#include "kamailioServer.h"
+
+#include "snmpstats_globals.h"
+#include "utilities.h"
+#include "../../lib/kcore/statistics.h"
+
+/** Initializes the kamailioServer module */
+void
+init_kamailioServer(void)
+{
+    const oid kamailioSrvMaxMemory_oid[] = { 1,3,6,1,4,1,34352,3,1,3,1,1,1,1 };
+    const oid kamailioSrvFreeMemory_oid[] = { 1,3,6,1,4,1,34352,3,1,3,1,1,1,2 };
+
+     DEBUGMSGTL(("kamailioServer", "Initializing\n"));
+     LM_DBG("initializing Kamailio Server OID's X\n");
+
+    netsnmp_register_scalar(
+        netsnmp_create_handler_registration("kamailioSrvMaxMemory", handle_kamailioSrvMaxMemory,
+                               kamailioSrvMaxMemory_oid, OID_LENGTH(kamailioSrvMaxMemory_oid),
+                               HANDLER_CAN_RONLY
+        ));
+    netsnmp_register_scalar(
+        netsnmp_create_handler_registration("kamailioSrvFreeMemory", handle_kamailioSrvFreeMemory,
+                               kamailioSrvFreeMemory_oid, OID_LENGTH(kamailioSrvFreeMemory_oid),
+                               HANDLER_CAN_RONLY
+        ));
+}
+
+int
+handle_kamailioSrvMaxMemory(netsnmp_mib_handler *handler,
+                          netsnmp_handler_registration *reginfo,
+                          netsnmp_agent_request_info   *reqinfo,
+                          netsnmp_request_info         *requests)
+{
+    /* We are never called for a GETNEXT if it's registered as a
+       "instance", as it's "magically" handled for us.  */
+
+    /* a instance handler also only hands us one request at a time, so
+       we don't need to loop over a list of requests; we'll only get one. */
+
+    int maxmemory = get_statistic("total_size");
+    
+    switch(reqinfo->mode) {
+
+        case MODE_GET:
+            snmp_set_var_typed_value(requests->requestvb, ASN_GAUGE,
+                        	(u_char *) &maxmemory, sizeof(int));
+            break;
+
+
+        default:
+            /* we should never get here, so this is a really bad error */
+            snmp_log(LOG_ERR, "unknown mode (%d) in handle_kamailioSrvMaxMemory\n", reqinfo->mode );
+            return SNMP_ERR_GENERR;
+    }
+
+    return SNMP_ERR_NOERROR;
+}
+int
+handle_kamailioSrvFreeMemory(netsnmp_mib_handler *handler,
+                          netsnmp_handler_registration *reginfo,
+                          netsnmp_agent_request_info   *reqinfo,
+                          netsnmp_request_info         *requests)
+{
+    int freememory = get_statistic("free_size");
+
+    /* We are never called for a GETNEXT if it's registered as a
+       "instance", as it's "magically" handled for us.  */
+
+    /* a instance handler also only hands us one request at a time, so
+       we don't need to loop over a list of requests; we'll only get one. */
+    
+    switch(reqinfo->mode) {
+
+        case MODE_GET:
+            snmp_set_var_typed_value(requests->requestvb, ASN_GAUGE,
+                        	(u_char *) &freememory, sizeof(int));
+            break;
+
+
+        default:
+            /* we should never get here, so this is a really bad error */
+            snmp_log(LOG_ERR, "unknown mode (%d) in handle_kamailioSrvFreeMemory\n", reqinfo->mode );
+            return SNMP_ERR_GENERR;
+    }
+
+    return SNMP_ERR_NOERROR;
+}

+ 42 - 0
modules/snmpstats/kamailioServer.h

@@ -0,0 +1,42 @@
+/*
+ * SNMPStats Module 
+ * Copyright (C) 2006 SOMA Networks, INC.
+ * Written by: Jeffrey Magder ([email protected])
+ *
+ * Kamailio Server core objects addition
+ * Copyright (C) 2013 Edvina AB, Sollentuna, Sweden
+ * Written by Olle E. Johansson
+ *
+ * This file is part of Kamailio, a free SIP server.
+ *
+ * Kamailio 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
+ *
+ * Kamailio 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA
+ *
+ * History:
+ * --------
+ * 2013-03-24 initial version (oej)
+ * 
+ * Note: this file originally auto-generated by mib2c 
+ *
+ */
+#ifndef KAMAILIOSERVER_H
+#define KAMAILIOSERVER_H
+
+/* function declarations */
+void init_kamailioServer(void);
+Netsnmp_Node_Handler handle_kamailioSrvMaxMemory;
+Netsnmp_Node_Handler handle_kamailioSrvFreeMemory;
+
+#endif /* KAMAILIOSERVER_H */

+ 65 - 0
modules/snmpstats/mibs/KAMAILIO-MIB

@@ -7,6 +7,7 @@
 -- 
 -- Copyright (c) The Internet Society (2006)
 -- Ammendments (c) Soma Networks, Inc. (2006)
+-- Kamailio extras (c) Edvina AB, 2013
 --
 -- All rights reserved.
 -- *****************************************************************
@@ -72,6 +73,30 @@ KAMAILIO-MIB DEFINITIONS ::= BEGIN
         REVISION   "201301081200Z"
         DESCRIPTION
            "Renamed MIB and mib entries to new product name, Kamailio."
+        REVISION   "201303231200Z"
+        DESCRIPTION
+           "Added Kamailio core memory allocation data."
+        ::= { kamailioModules 5 }
+
+--
+-- Top-Level Components of this MIB.
+--
+    kamailioObjects OBJECT-IDENTITY
+        STATUS current
+        DESCRIPTION 
+        "Sub-tree for accessible objects in the MIB."
+        ::= { kamailioMIB 1 } 
+
+    kamailioMIBEvents OBJECT-IDENTITY
+        STATUS current
+        DESCRIPTION
+        "A sub-tree for all the KAMAILIO-MIB related events and traps."
+        ::= {kamailioMIB 2 }
+
+    kamailioConform OBJECT-IDENTITY
+        STATUS current
+        DESCRIPTION 
+	"Some stuff here"
         ::= { kamailioModules 5 }
 
 --
@@ -119,6 +144,46 @@ KAMAILIO-MIB DEFINITIONS ::= BEGIN
 
 -- 
 -- Kamailio Server Objects
+--
+    kamailioSrvMemory OBJECT-IDENTITY
+        STATUS current
+        DESCRIPTION 
+        "Sub-tree for Core Memory Statistics." 
+        ::= { kamailioServer 1 }
+
+    kamailioSrvCounters OBJECT-IDENTITY
+        STATUS current
+        DESCRIPTION 
+        "Sub-tree for Core Counters/Statistic variables." 
+        ::= { kamailioServer 2 }
+
+    kamailioSrvProcess OBJECT-IDENTITY
+        STATUS current
+        DESCRIPTION 
+        "Sub-tree for Core Processes." 
+        ::= { kamailioServer 3 }
+
+-- 
+-- Kamailio Server Memory data
+--
+    kamailioSrvMaxMemory OBJECT-TYPE
+        SYNTAX      Gauge32
+        MAX-ACCESS  read-only
+        STATUS current
+        DESCRIPTION 
+        "Maximum available Shared Memory"
+        ::= { kamailioSrvMemory 1 }
+
+    kamailioSrvFreeMemory OBJECT-TYPE
+        SYNTAX      Gauge32
+        MAX-ACCESS  read-only
+        STATUS current
+        DESCRIPTION 
+        "Available free memory in the Shared Memory pool"
+        ::= { kamailioSrvMemory 2 }
+
+-- 
+-- Kamailio Server Core counters
 --
 
 

+ 0 - 1
modules/snmpstats/mibs/KAMAILIO-SIP-COMMON-MIB

@@ -113,7 +113,6 @@ KAMAILIO-SIP-COMMON-MIB DEFINITIONS ::= BEGIN
               Registrar: A registrar is a server that accepts
               REGISTER requests and places the information it
               receives in those requests into the location service
-
               for the domain it handles.
 
               Copyright (C) The Internet Society (2005). This version

+ 8 - 0
modules/snmpstats/sub_agent.c

@@ -63,6 +63,7 @@
 #include "snmpSIPContactTable.h"
 #include "snmpSIPRegUserLookupTable.h"
 #include "snmpMIBNotifications.h"
+#include "kamailioServer.h"
 
 #include "../../dprint.h"
 #include "../../cfg/cfg_struct.h"
@@ -91,6 +92,8 @@ static int initialize_agentx(void)
 {
 	/* We register with a master agent */
 	register_with_master_agent(AGENT_PROCESS_NAME);
+
+	LM_DBG("Initializing Kamailio OID's for SNMPD MasterX\n");
 	
 	/* Initialize all scalars, and let the master agent know we want to
 	 * handle all OID's pertaining to these scalars. */
@@ -106,6 +109,8 @@ static int initialize_agentx(void)
 	init_kamailioSIPRegUserTable();
 	init_kamailioSIPContactTable();
 	init_kamailioSIPRegUserLookupTable();
+	init_kamailioServer();
+	LM_DBG("Done initializing Kamailio OID's for SNMPD MasterX\n");
 
 	/* In case we recevie a request to stop (kill -TERM or kill -INT) */
 	keep_running = 1;
@@ -117,6 +122,7 @@ static int initialize_agentx(void)
 		agent_check_and_process(1); /* 0 == don't block */
 	}
 
+	LM_DBG("Shutting down Kamailio SNMPD MasterX sub agent.\n");
 	snmp_shutdown(AGENT_PROCESS_NAME);
 	SOCK_CLEANUP;
 	exit (0);
@@ -181,10 +187,12 @@ void register_with_master_agent(char *name_to_register_under)
 	/* Initialize TCP if necessary.  (Its here for WIN32) compatibility. */
 	SOCK_STARTUP;
 
+	LM_DBG("Connecting to SNMPD MasterX\n");
 	/* Read in our configuration file to determine master agent ping times
 	 * what port communication is to take place over, etc. */
 	init_agent("snmpstats");
 
 	/* Use a name we can register our agent under. */
 	init_snmp(name_to_register_under);
+	LM_DBG("** Connected to SNMPD MasterX\n");
 }