Browse Source

snmpstats Add support for the Websocket module statistics

Hint to developers: If you add statistics and selects in your module, you
make it very easy to add SNMP support for your module. Then SNMPstats
can just use generic APIs to find your data. Please also add a generic
way of finding out if a module is configured and used too, if possible.
Sometimes modules are just loaded, but not used anywhere. Better to
reflect real data in SNMP if possible.

Using the old "SER" way of using selects for config data that
is allowed to change at runtime opens up for SNMP writes to manage
your module as well.

And of course, using selects and counters/statistics variables also
helps the RPC interface, so it's both cool and the Right Thing To Do (TM).

Yes, commit messages can be informative as well. :-)
Olle E. Johansson 12 years ago
parent
commit
f139948421
3 changed files with 382 additions and 10 deletions
  1. 272 7
      modules/snmpstats/kamailioNet.c
  2. 9 0
      modules/snmpstats/kamailioNet.h
  3. 101 3
      modules/snmpstats/mibs/KAMAILIO-MIB

+ 272 - 7
modules/snmpstats/kamailioNet.c

@@ -85,6 +85,17 @@ init_kamailioNet(void)
     const oid kamailioNetTcpAcceptAliases_oid[] = { 1,3,6,1,4,1,34352,3,1,3,1,4,1,3,23 };
     const oid kamailioNetTcpAcceptNoCl_oid[] = { 1,3,6,1,4,1,34352,3,1,3,1,4,1,3,24 };
 
+    /* WebSockets */
+    const oid kamailioNetWsConnsActive_oid[] = { 1,3,6,1,4,1,34352,3,1,3,1,4,2,1,1 };
+    const oid kamailioNetWsConnsActiveMax_oid[] = { 1,3,6,1,4,1,34352,3,1,3,1,4,2,1,2 };
+    const oid kamailioNetWsConnsFailed_oid[] = { 1,3,6,1,4,1,34352,3,1,3,1,4,2,1,3 };
+    const oid kamailioNetWsConnsClosedLocal_oid[] = { 1,3,6,1,4,1,34352,3,1,3,1,4,2,1,4 };
+    const oid kamailioNetWsConnsClosedRemote_oid[] = { 1,3,6,1,4,1,34352,3,1,3,1,4,2,1,5 };
+    const oid kamailioNetWsFramesRx_oid[] = { 1,3,6,1,4,1,34352,3,1,3,1,4,2,1,6 };
+    const oid kamailioNetWsFramesTx_oid[] = { 1,3,6,1,4,1,34352,3,1,3,1,4,2,1,7 };
+    const oid kamailioNetWsHandshakeSuccess_oid[] = { 1,3,6,1,4,1,34352,3,1,3,1,4,2,1,8 };
+    const oid kamailioNetWsHandshakeFailed_oid[] = { 1,3,6,1,4,1,34352,3,1,3,1,4,2,1,9 };
+
   DEBUGMSGTL(("kamailioNet", "Initializing\n"));
 
     netsnmp_register_scalar(
@@ -237,6 +248,51 @@ init_kamailioNet(void)
                                kamailioNetTcpAcceptNoCl_oid, OID_LENGTH(kamailioNetTcpAcceptNoCl_oid),
                                HANDLER_CAN_RONLY
         ));
+    netsnmp_register_scalar(
+        netsnmp_create_handler_registration("kamailioNetWsConnsActive", handle_kamailioNetWsConnsActive,
+                               kamailioNetWsConnsActive_oid, OID_LENGTH(kamailioNetWsConnsActive_oid),
+                               HANDLER_CAN_RONLY
+        ));
+    netsnmp_register_scalar(
+        netsnmp_create_handler_registration("kamailioNetWsConnsActiveMax", handle_kamailioNetWsConnsActiveMax,
+                               kamailioNetWsConnsActiveMax_oid, OID_LENGTH(kamailioNetWsConnsActiveMax_oid),
+                               HANDLER_CAN_RONLY
+        ));
+    netsnmp_register_scalar(
+        netsnmp_create_handler_registration("kamailioNetWsConnsFailed", handle_kamailioNetWsConnsFailed,
+                               kamailioNetWsConnsFailed_oid, OID_LENGTH(kamailioNetWsConnsFailed_oid),
+                               HANDLER_CAN_RONLY
+        ));
+    netsnmp_register_scalar(
+        netsnmp_create_handler_registration("kamailioNetWsConnsClosedLocal", handle_kamailioNetWsConnsClosedLocal,
+                               kamailioNetWsConnsClosedLocal_oid, OID_LENGTH(kamailioNetWsConnsClosedLocal_oid),
+                               HANDLER_CAN_RONLY
+        ));
+    netsnmp_register_scalar(
+        netsnmp_create_handler_registration("kamailioNetWsConnsClosedRemote", handle_kamailioNetWsConnsClosedRemote,
+                               kamailioNetWsConnsClosedRemote_oid, OID_LENGTH(kamailioNetWsConnsClosedRemote_oid),
+                               HANDLER_CAN_RONLY
+        ));
+    netsnmp_register_scalar(
+        netsnmp_create_handler_registration("kamailioNetWsFramesRx", handle_kamailioNetWsFramesRx,
+                               kamailioNetWsFramesRx_oid, OID_LENGTH(kamailioNetWsFramesRx_oid),
+                               HANDLER_CAN_RONLY
+        ));
+    netsnmp_register_scalar(
+        netsnmp_create_handler_registration("kamailioNetWsFramesTx", handle_kamailioNetWsFramesTx,
+                               kamailioNetWsFramesTx_oid, OID_LENGTH(kamailioNetWsFramesTx_oid),
+                               HANDLER_CAN_RONLY
+        ));
+    netsnmp_register_scalar(
+        netsnmp_create_handler_registration("kamailioNetWsHandshakeSuccess", handle_kamailioNetWsHandshakeSuccess,
+                               kamailioNetWsHandshakeSuccess_oid, OID_LENGTH(kamailioNetWsHandshakeSuccess_oid),
+                               HANDLER_CAN_RONLY
+        ));
+    netsnmp_register_scalar(
+        netsnmp_create_handler_registration("kamailioNetWsHandshakeFailed", handle_kamailioNetWsHandshakeFailed,
+                               kamailioNetWsHandshakeFailed_oid, OID_LENGTH(kamailioNetWsHandshakeFailed_oid),
+                               HANDLER_CAN_RONLY
+        ));
 }
 
 int
@@ -1063,8 +1119,7 @@ handle_kamailioNetTcpAcceptAliases(netsnmp_mib_handler *handler,
     return SNMP_ERR_NOERROR;
 }
 
-int
-handle_kamailioNetTcpAcceptNoCl(netsnmp_mib_handler *handler,
+int handle_kamailioNetTcpAcceptNoCl(netsnmp_mib_handler *handler,
                           netsnmp_handler_registration *reginfo,
                           netsnmp_agent_request_info   *reqinfo,
                           netsnmp_request_info         *requests)
@@ -1074,11 +1129,6 @@ handle_kamailioNetTcpAcceptNoCl(netsnmp_mib_handler *handler,
 
     tcp_options_get(&t);
     value = t.accept_no_cl;
-    /* 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) {
 
@@ -1096,3 +1146,218 @@ handle_kamailioNetTcpAcceptNoCl(netsnmp_mib_handler *handler,
 
     return SNMP_ERR_NOERROR;
 }
+
+int handle_kamailioNetWsConnsActive(netsnmp_mib_handler *handler,
+                          netsnmp_handler_registration *reginfo,
+                          netsnmp_agent_request_info   *reqinfo,
+                          netsnmp_request_info         *requests)
+{
+   int datafield = get_statistic("ws_current_connections");
+    
+    switch(reqinfo->mode) {
+        case MODE_GET:
+            snmp_set_var_typed_value(requests->requestvb, ASN_GAUGE,
+			(u_char *) &datafield, 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_kamailioNetWsConnsActive\n", reqinfo->mode );
+            return SNMP_ERR_GENERR;
+    }
+
+    return SNMP_ERR_NOERROR;
+}
+int
+handle_kamailioNetWsConnsActiveMax(netsnmp_mib_handler *handler,
+                          netsnmp_handler_registration *reginfo,
+                          netsnmp_agent_request_info   *reqinfo,
+                          netsnmp_request_info         *requests)
+{
+   int datafield = get_statistic("ws_max_concurrent_connections");
+    
+    switch(reqinfo->mode) {
+
+        case MODE_GET:
+            snmp_set_var_typed_value(requests->requestvb, ASN_GAUGE,
+				(u_char *) &datafield, 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_kamailioNetWsConnsActiveMax\n", reqinfo->mode );
+            return SNMP_ERR_GENERR;
+    }
+
+    return SNMP_ERR_NOERROR;
+}
+int
+handle_kamailioNetWsConnsFailed(netsnmp_mib_handler *handler,
+                          netsnmp_handler_registration *reginfo,
+                          netsnmp_agent_request_info   *reqinfo,
+                          netsnmp_request_info         *requests)
+{
+   int datafield = get_statistic("ws_failed_connections");
+    
+    switch(reqinfo->mode) {
+
+        case MODE_GET:
+            snmp_set_var_typed_value(requests->requestvb, ASN_COUNTER,
+			(u_char *) &datafield, 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_kamailioNetWsConnsFailed\n", reqinfo->mode );
+            return SNMP_ERR_GENERR;
+    }
+
+    return SNMP_ERR_NOERROR;
+}
+int
+handle_kamailioNetWsConnsClosedLocal(netsnmp_mib_handler *handler,
+                          netsnmp_handler_registration *reginfo,
+                          netsnmp_agent_request_info   *reqinfo,
+                          netsnmp_request_info         *requests)
+{
+   int datafield = get_statistic("ws_local_closed_connections");
+    
+    switch(reqinfo->mode) {
+
+        case MODE_GET:
+            snmp_set_var_typed_value(requests->requestvb, ASN_COUNTER,
+			(u_char *) &datafield, 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_kamailioNetWsConnsClosedLocal\n", reqinfo->mode );
+            return SNMP_ERR_GENERR;
+    }
+
+    return SNMP_ERR_NOERROR;
+}
+int
+handle_kamailioNetWsConnsClosedRemote(netsnmp_mib_handler *handler,
+                          netsnmp_handler_registration *reginfo,
+                          netsnmp_agent_request_info   *reqinfo,
+                          netsnmp_request_info         *requests)
+{
+   int datafield = get_statistic("ws_remote_closed_connections");
+    
+    switch(reqinfo->mode) {
+
+        case MODE_GET:
+            snmp_set_var_typed_value(requests->requestvb, ASN_COUNTER,
+			(u_char *) &datafield, 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_kamailioNetWsConnsClosedRemote\n", reqinfo->mode );
+            return SNMP_ERR_GENERR;
+    }
+
+    return SNMP_ERR_NOERROR;
+}
+int
+handle_kamailioNetWsFramesRx(netsnmp_mib_handler *handler,
+                          netsnmp_handler_registration *reginfo,
+                          netsnmp_agent_request_info   *reqinfo,
+                          netsnmp_request_info         *requests)
+{
+   int datafield = get_statistic("ws_received_frames");
+    
+    switch(reqinfo->mode) {
+
+        case MODE_GET:
+            snmp_set_var_typed_value(requests->requestvb, ASN_COUNTER,
+			(u_char *) &datafield, 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_kamailioNetWsFramesRx\n", reqinfo->mode );
+            return SNMP_ERR_GENERR;
+    }
+
+    return SNMP_ERR_NOERROR;
+}
+int
+handle_kamailioNetWsFramesTx(netsnmp_mib_handler *handler,
+                          netsnmp_handler_registration *reginfo,
+                          netsnmp_agent_request_info   *reqinfo,
+                          netsnmp_request_info         *requests)
+{
+   int datafield = get_statistic("ws_transmitted_frames");
+    
+    switch(reqinfo->mode) {
+
+        case MODE_GET:
+            snmp_set_var_typed_value(requests->requestvb, ASN_COUNTER,
+			(u_char *) &datafield, 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_kamailioNetWsFramesTx\n", reqinfo->mode );
+            return SNMP_ERR_GENERR;
+    }
+
+    return SNMP_ERR_NOERROR;
+}
+int
+handle_kamailioNetWsHandshakeSuccess(netsnmp_mib_handler *handler,
+                          netsnmp_handler_registration *reginfo,
+                          netsnmp_agent_request_info   *reqinfo,
+                          netsnmp_request_info         *requests)
+{
+   int datafield = get_statistic("ws_successful_handshakes");
+    
+    switch(reqinfo->mode) {
+
+        case MODE_GET:
+            snmp_set_var_typed_value(requests->requestvb, ASN_COUNTER,
+			(u_char *) &datafield, 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_kamailioNetWsHandshakeSuccess\n", reqinfo->mode );
+            return SNMP_ERR_GENERR;
+    }
+
+    return SNMP_ERR_NOERROR;
+}
+int
+handle_kamailioNetWsHandshakeFailed(netsnmp_mib_handler *handler,
+                          netsnmp_handler_registration *reginfo,
+                          netsnmp_agent_request_info   *reqinfo,
+                          netsnmp_request_info         *requests)
+{
+   int datafield = get_statistic("ws_failed_handshakes");
+    
+    switch(reqinfo->mode) {
+
+        case MODE_GET:
+            snmp_set_var_typed_value(requests->requestvb, ASN_COUNTER,
+			(u_char *) &datafield, 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_kamailioNetWsHandshakeFailed\n", reqinfo->mode );
+            return SNMP_ERR_GENERR;
+    }
+
+    return SNMP_ERR_NOERROR;
+}

+ 9 - 0
modules/snmpstats/kamailioNet.h

@@ -38,5 +38,14 @@ Netsnmp_Node_Handler handle_kamailioNetTcpKeepCnt;
 Netsnmp_Node_Handler handle_kamailioNetTcpCrlfPing;
 Netsnmp_Node_Handler handle_kamailioNetTcpAcceptAliases;
 Netsnmp_Node_Handler handle_kamailioNetTcpAcceptNoCl;
+Netsnmp_Node_Handler handle_kamailioNetWsConnsActive;
+Netsnmp_Node_Handler handle_kamailioNetWsConnsActiveMax;
+Netsnmp_Node_Handler handle_kamailioNetWsConnsFailed;
+Netsnmp_Node_Handler handle_kamailioNetWsConnsClosedLocal;
+Netsnmp_Node_Handler handle_kamailioNetWsConnsClosedRemote;
+Netsnmp_Node_Handler handle_kamailioNetWsFramesRx;
+Netsnmp_Node_Handler handle_kamailioNetWsFramesTx;
+Netsnmp_Node_Handler handle_kamailioNetWsHandshakeSuccess;
+Netsnmp_Node_Handler handle_kamailioNetWsHandshakeFailed;
 
 #endif /* KAMAILIONET_H */

+ 101 - 3
modules/snmpstats/mibs/KAMAILIO-MIB

@@ -77,9 +77,9 @@ KAMAILIO-MIB DEFINITIONS ::= BEGIN
         REVISION   "201301081200Z"
         DESCRIPTION
            "Renamed MIB and mib entries to new product name, Kamailio."
-        REVISION   "201303231200Z"
+        REVISION   "201303301200Z"
         DESCRIPTION
-           "Added Kamailio core memory allocation data."
+           "Added Kamailio process information - memory, transports, core configuration"
         ::= { kamailioModules 5 }
 
 --
@@ -316,7 +316,7 @@ KAMAILIO-MIB DEFINITIONS ::= BEGIN
     kamailioNetTcpTls OBJECT-IDENTITY
         STATUS current
         DESCRIPTION 
-        "Sub-tree for TCP/TLS objects." 
+        "Sub-tree for TCP/TLS specific objects." 
         ::= { kamailioNetTcp 1 }
 
     kamailioNetTcpStat OBJECT-IDENTITY
@@ -718,6 +718,104 @@ KAMAILIO-MIB DEFINITIONS ::= BEGIN
         DESCRIPTION 
         "True if the STUN Server server (SIP Outbound) is loaded in this server."
         ::= { kamailioNetConfig 11 }
+
+--
+-- Websocket Connection Objects
+--
+    kamailioNetWsStat OBJECT-IDENTITY
+        STATUS current
+        DESCRIPTION 
+        "Sub-tree for Websocket statistics." 
+        ::= { kamailioNetWebsocket 1 }
+
+   kamailioNetWsConfig OBJECT-IDENTITY
+        STATUS current
+        DESCRIPTION 
+        "Sub-tree for Websocket configuration objects." 
+        ::= { kamailioNetWebsocket 2 }
+
+--
+-- Kamailio WebSocket Configuration  Objects
+--
+	--- Currently empty.
+
+--
+-- Kamailio WebSocket Statistics  Objects
+--
+
+    kamailioNetWsConnsActive OBJECT-TYPE
+        SYNTAX      Gauge
+        MAX-ACCESS  read-only
+        STATUS current
+        DESCRIPTION 
+        "Number of currently active websocket connections"
+        ::= { kamailioNetWsStat 1 }
+
+    kamailioNetWsConnsActiveMax OBJECT-TYPE
+        SYNTAX      Gauge
+        MAX-ACCESS  read-only
+        STATUS current
+        DESCRIPTION 
+        "The maximum number of active websocket connections since process start"
+        ::= { kamailioNetWsStat 2 }
+
+    kamailioNetWsConnsFailed OBJECT-TYPE
+        SYNTAX      Counter32
+        MAX-ACCESS  read-only
+        STATUS current
+        DESCRIPTION 
+        "The number of failed websocket connections since process start"
+        ::= { kamailioNetWsStat 3 }
+
+    kamailioNetWsConnsClosedLocal OBJECT-TYPE
+        SYNTAX      Counter32
+        MAX-ACCESS  read-only
+        STATUS current
+        DESCRIPTION 
+        "The number of locally closed websocket connections"
+        ::= { kamailioNetWsStat 4 }
+
+    kamailioNetWsConnsClosedRemote OBJECT-TYPE
+        SYNTAX      Counter32
+        MAX-ACCESS  read-only
+        STATUS current
+        DESCRIPTION 
+        "The number of closed websocket connections by remote peer"
+        ::= { kamailioNetWsStat 5 }
+
+    kamailioNetWsFramesRx OBJECT-TYPE
+        SYNTAX      Counter32
+        MAX-ACCESS  read-only
+        STATUS current
+        DESCRIPTION 
+        "The number of received websocket frames"
+        ::= { kamailioNetWsStat 6 }
+
+    kamailioNetWsFramesTx OBJECT-TYPE
+        SYNTAX      Counter32
+        MAX-ACCESS  read-only
+        STATUS current
+        DESCRIPTION 
+        "The number of transmitted websocket frames"
+        ::= { kamailioNetWsStat 7 }
+
+    kamailioNetWsHandshakeSuccess OBJECT-TYPE
+        SYNTAX      Counter32
+        MAX-ACCESS  read-only
+        STATUS current
+        DESCRIPTION 
+        "The number of transmitted websocket frames"
+        ::= { kamailioNetWsStat 8 }
+
+    kamailioNetWsHandshakeFailed OBJECT-TYPE
+        SYNTAX      Counter32
+        MAX-ACCESS  read-only
+        STATUS current
+        DESCRIPTION 
+        "The number of transmitted websocket frames"
+        ::= { kamailioNetWsStat 9 }
+
+
 --
 -- Kamailio Message Objects
 --