Add additionals statistics counters
authorDaniel Wagner <daniel.wagner@bmw-carit.de>
Thu, 8 Jul 2010 13:32:02 +0000 (15:32 +0200)
committerMarcel Holtmann <marcel@holtmann.org>
Thu, 8 Jul 2010 13:35:46 +0000 (10:35 -0300)
Adding rx_packets, tx_packets, rx_errors, tx_errors,
rx_dropped and tx_dropped counters.

doc/counter-api.txt
src/connman.h
src/counter.c
src/ipconfig.c
src/service.c
test/test-counter

index 14e5a01..98d7a17 100644 (file)
@@ -21,13 +21,41 @@ Methods             void Release()
 
                        The dict argument contains following entries:
 
+                               RX.Packets
+
+                                       Total number of packets received.
+
                                TX.Bytes
 
-                                       Total number of bytes sent.
+                                       Total number of packets sent.
 
                                RX.Bytes
 
                                        Total number of bytes received.
 
+                               TX.Bytes
+
+                                       Total number of bytes sent.
+
+                               RX.Errors
+
+                                       Total number of erronous packets
+                                       received.
+
+                               TX.Errors
+
+                                       Total number of erronous packets
+                                       sent.
+
+                               RX.Dropped
+
+                                       Total number of dropped packets
+                                       while receiving.
+
+                               TX.Dropped
+
+                                       Total number of dropped packets
+                                       while sending.
+
                                Time
                                        Total number of seconds online.
index 2359620..3b8f7c2 100644 (file)
@@ -74,7 +74,10 @@ int __connman_counter_register(const char *owner, const char *path,
 int __connman_counter_unregister(const char *owner, const char *path);
 
 void __connman_counter_notify(struct connman_ipconfig *config,
-                               unsigned int rx_bytes, unsigned int tx_bytes);
+                       unsigned int rx_packets, unsigned int tx_packets,
+                       unsigned int rx_bytes, unsigned int tx_bytes,
+                       unsigned int rx_error, unsigned int tx_error,
+                       unsigned int rx_dropped, unsigned int tx_dropped);
 
 int __connman_counter_add_service(struct connman_service *service);
 void __connman_counter_remove_service(struct connman_service *service);
@@ -446,12 +449,20 @@ void __connman_service_append_nameserver(struct connman_service *service,
 void __connman_service_remove_nameserver(struct connman_service *service,
                                                const char *nameserver);
 
-unsigned long __connman_service_stats_get_tx_bytes(struct connman_service *service);
+unsigned long __connman_service_stats_get_rx_packets(struct connman_service *service);
+unsigned long __connman_service_stats_get_tx_packets(struct connman_service *service);
 unsigned long __connman_service_stats_get_rx_bytes(struct connman_service *service);
+unsigned long __connman_service_stats_get_tx_bytes(struct connman_service *service);
+unsigned long __connman_service_stats_get_rx_errors(struct connman_service *service);
+unsigned long __connman_service_stats_get_tx_errors(struct connman_service *service);
+unsigned long __connman_service_stats_get_rx_dropped(struct connman_service *service);
+unsigned long __connman_service_stats_get_tx_dropped(struct connman_service *service);
 unsigned long __connman_service_stats_get_time(struct connman_service *service);
 void __connman_service_stats_update(struct connman_service *service,
-                                       unsigned long rx_bytes,
-                                       unsigned long tx_bytes);
+                               unsigned int rx_packets, unsigned int tx_packets,
+                               unsigned int rx_bytes, unsigned int tx_bytes,
+                               unsigned int rx_error, unsigned int tx_error,
+                               unsigned int rx_dropped, unsigned int tx_dropped);
 
 #include <connman/location.h>
 
index a4613ca..a457a22 100644 (file)
@@ -133,8 +133,14 @@ static void send_usage(struct connman_counter *counter,
        DBusMessage *message;
        DBusMessageIter array, dict;
        const char *service_path;
+       unsigned long rx_packets;
+       unsigned long tx_packets;
        unsigned long rx_bytes;
        unsigned long tx_bytes;
+       unsigned long rx_errors;
+       unsigned long tx_errors;
+       unsigned long rx_dropped;
+       unsigned long tx_dropped;
        unsigned long time;
 
        message = dbus_message_new_method_call(counter->owner, counter->path,
@@ -152,14 +158,32 @@ static void send_usage(struct connman_counter *counter,
 
        connman_dbus_dict_open(&array, &dict);
 
+       rx_packets = __connman_service_stats_get_rx_packets(service);
+       tx_packets = __connman_service_stats_get_tx_packets(service);
        rx_bytes = __connman_service_stats_get_rx_bytes(service);
        tx_bytes = __connman_service_stats_get_tx_bytes(service);
+       rx_errors = __connman_service_stats_get_rx_errors(service);
+       tx_errors = __connman_service_stats_get_tx_errors(service);
+       rx_dropped = __connman_service_stats_get_rx_dropped(service);
+       tx_dropped = __connman_service_stats_get_tx_dropped(service);
        time = __connman_service_stats_get_time(service);
 
+       connman_dbus_dict_append_basic(&dict, "RX.Packets", DBUS_TYPE_UINT32,
+                               &rx_packets);
+       connman_dbus_dict_append_basic(&dict, "TX.Packets", DBUS_TYPE_UINT32,
+                               &tx_packets);
        connman_dbus_dict_append_basic(&dict, "RX.Bytes", DBUS_TYPE_UINT32,
                                &rx_bytes);
        connman_dbus_dict_append_basic(&dict, "TX.Bytes", DBUS_TYPE_UINT32,
                                &tx_bytes);
+       connman_dbus_dict_append_basic(&dict, "RX.Errors", DBUS_TYPE_UINT32,
+                               &rx_errors);
+       connman_dbus_dict_append_basic(&dict, "TX.Errors", DBUS_TYPE_UINT32,
+                               &tx_errors);
+       connman_dbus_dict_append_basic(&dict, "RX.Dropped", DBUS_TYPE_UINT32,
+                               &rx_dropped);
+       connman_dbus_dict_append_basic(&dict, "TX.Dropped", DBUS_TYPE_UINT32,
+                               &tx_dropped);
        connman_dbus_dict_append_basic(&dict, "Time", DBUS_TYPE_UINT32,
                                &time);
 
@@ -169,7 +193,10 @@ static void send_usage(struct connman_counter *counter,
 }
 
 void __connman_counter_notify(struct connman_ipconfig *config,
-                               unsigned int rx_bytes, unsigned int tx_bytes)
+                       unsigned int rx_packets, unsigned int tx_packets,
+                       unsigned int rx_bytes, unsigned int tx_bytes,
+                       unsigned int rx_errors, unsigned int tx_errors,
+                       unsigned int rx_dropped, unsigned int tx_dropped)
 {
        struct counter_data *data;
        GHashTableIter iter;
@@ -179,7 +206,11 @@ void __connman_counter_notify(struct connman_ipconfig *config,
        if (data == NULL)
                return;
 
-       __connman_service_stats_update(data->service, rx_bytes, tx_bytes);
+       __connman_service_stats_update(data->service,
+                               rx_packets, tx_packets,
+                               rx_bytes, tx_bytes,
+                               rx_errors, tx_errors,
+                               rx_dropped, tx_dropped);
 
        if (data->first_update == TRUE) {
                data->first_update = FALSE;
index a7d5d32..2ef600b 100644 (file)
@@ -56,8 +56,14 @@ struct connman_ipdevice {
        unsigned int flags;
        char *address;
        uint16_t mtu;
-       uint32_t tx_bytes;
+       uint32_t rx_packets;
+       uint32_t tx_packets;
        uint32_t rx_bytes;
+       uint32_t tx_bytes;
+       uint32_t rx_errors;
+       uint32_t tx_errors;
+       uint32_t rx_dropped;
+       uint32_t tx_dropped;
 
        GSList *address_list;
        char *gateway;
@@ -364,11 +370,20 @@ static void update_stats(struct connman_ipdevice *ipdevice,
        if (ipdevice->config == NULL)
                return;
 
+       ipdevice->rx_packets = stats->rx_packets;
+       ipdevice->tx_packets = stats->tx_packets;
        ipdevice->rx_bytes = stats->rx_bytes;
        ipdevice->tx_bytes = stats->tx_bytes;
+       ipdevice->rx_errors = stats->rx_errors;
+       ipdevice->tx_errors = stats->tx_errors;
+       ipdevice->rx_dropped = stats->rx_dropped;
+       ipdevice->tx_dropped = stats->tx_dropped;
 
        __connman_counter_notify(ipdevice->config,
-                               ipdevice->rx_bytes, ipdevice->tx_bytes);
+                               ipdevice->rx_packets, ipdevice->tx_packets,
+                               ipdevice->rx_bytes, ipdevice->tx_bytes,
+                               ipdevice->rx_errors, ipdevice->tx_errors,
+                               ipdevice->rx_dropped, ipdevice->tx_dropped);
 }
 
 void __connman_ipconfig_newlink(int index, unsigned short type,
index 3027cc8..c76a9ee 100644 (file)
@@ -38,10 +38,22 @@ static GHashTable *service_hash = NULL;
 
 struct connman_stats {
        connman_bool_t valid;
+       unsigned int rx_packets_last;
+       unsigned int tx_packets_last;
+       unsigned int rx_packets;
+       unsigned int tx_packets;
        unsigned int rx_bytes_last;
        unsigned int tx_bytes_last;
        unsigned int rx_bytes;
        unsigned int tx_bytes;
+       unsigned int rx_errors_last;
+       unsigned int tx_errors_last;
+       unsigned int rx_errors;
+       unsigned int tx_errors;
+       unsigned int rx_dropped_last;
+       unsigned int tx_dropped_last;
+       unsigned int rx_dropped;
+       unsigned int tx_dropped;
        unsigned int time_start;
        unsigned int time;
        GTimer *timer;
@@ -395,10 +407,22 @@ static void __connman_service_stats_stop(struct connman_service *service)
 static int __connman_service_stats_load(struct connman_service *service,
                GKeyFile *keyfile, const char *identifier)
 {
+       service->stats.rx_packets = g_key_file_get_integer(keyfile,
+                               identifier, "rx_packets", NULL);
+       service->stats.tx_packets = g_key_file_get_integer(keyfile,
+                               identifier, "tx_packets", NULL);
        service->stats.rx_bytes = g_key_file_get_integer(keyfile,
                                identifier, "rx_bytes", NULL);
        service->stats.tx_bytes = g_key_file_get_integer(keyfile,
                                identifier, "tx_bytes", NULL);
+       service->stats.rx_errors = g_key_file_get_integer(keyfile,
+                               identifier, "rx_errors", NULL);
+       service->stats.tx_errors = g_key_file_get_integer(keyfile,
+                               identifier, "tx_errors", NULL);
+       service->stats.rx_dropped = g_key_file_get_integer(keyfile,
+                               identifier, "rx_dropped", NULL);
+       service->stats.tx_dropped = g_key_file_get_integer(keyfile,
+                               identifier, "tx_dropped", NULL);
        service->stats.time = g_key_file_get_integer(keyfile,
                                identifier, "time", NULL);
 
@@ -408,10 +432,22 @@ static int __connman_service_stats_load(struct connman_service *service,
 static int __connman_service_stats_save(struct connman_service *service,
                GKeyFile *keyfile, const char *identifier)
 {
+       g_key_file_set_integer(keyfile, identifier, "rx_packets",
+                       service->stats.rx_packets);
+       g_key_file_set_integer(keyfile, identifier, "tx_packets",
+                       service->stats.tx_packets);
        g_key_file_set_integer(keyfile, identifier, "rx_bytes",
                        service->stats.rx_bytes);
        g_key_file_set_integer(keyfile, identifier, "tx_bytes",
                        service->stats.tx_bytes);
+       g_key_file_set_integer(keyfile, identifier, "rx_errors",
+                       service->stats.rx_errors);
+       g_key_file_set_integer(keyfile, identifier, "tx_errors",
+                       service->stats.tx_errors);
+       g_key_file_set_integer(keyfile, identifier, "rx_dropped",
+                       service->stats.rx_dropped);
+       g_key_file_set_integer(keyfile, identifier, "tx_dropped",
+                       service->stats.tx_dropped);
        g_key_file_set_integer(keyfile, identifier, "time",
                        service->stats.time);
 
@@ -423,17 +459,28 @@ static void __connman_service_reset_stats(struct connman_service *service)
        DBG("service %p", service);
 
        service->stats.valid = FALSE;
+       service->stats.rx_packets = 0;
+       service->stats.tx_packets = 0;
        service->stats.rx_bytes = 0;
        service->stats.tx_bytes = 0;
+       service->stats.rx_errors = 0;
+       service->stats.tx_errors = 0;
+       service->stats.rx_dropped = 0;
+       service->stats.tx_dropped = 0;
        service->stats.time = 0;
        service->stats.time_start = 0;
        g_timer_reset(service->stats.timer);
 
 }
 
-unsigned long __connman_service_stats_get_tx_bytes(struct connman_service *service)
+unsigned long __connman_service_stats_get_rx_packets(struct connman_service *service)
 {
-       return service->stats.tx_bytes;
+       return service->stats.rx_packets;
+}
+
+unsigned long __connman_service_stats_get_tx_packets(struct connman_service *service)
+{
+       return service->stats.tx_packets;
 }
 
 unsigned long __connman_service_stats_get_rx_bytes(struct connman_service *service)
@@ -441,6 +488,31 @@ unsigned long __connman_service_stats_get_rx_bytes(struct connman_service *servi
        return service->stats.rx_bytes;
 }
 
+unsigned long __connman_service_stats_get_tx_bytes(struct connman_service *service)
+{
+       return service->stats.tx_bytes;
+}
+
+unsigned long __connman_service_stats_get_rx_errors(struct connman_service *service)
+{
+       return service->stats.rx_errors;
+}
+
+unsigned long __connman_service_stats_get_tx_errors(struct connman_service *service)
+{
+       return service->stats.tx_errors;
+}
+
+unsigned long __connman_service_stats_get_rx_dropped(struct connman_service *service)
+{
+       return service->stats.rx_dropped;
+}
+
+unsigned long __connman_service_stats_get_tx_dropped(struct connman_service *service)
+{
+       return service->stats.tx_dropped;
+}
+
 unsigned long __connman_service_stats_get_time(struct connman_service *service)
 {
        return service->stats.time;
@@ -3075,8 +3147,10 @@ void __connman_service_remove_from_network(struct connman_network *network)
 }
 
 void __connman_service_stats_update(struct connman_service *service,
-                                       unsigned long rx_bytes,
-                                       unsigned long tx_bytes)
+                               unsigned int rx_packets, unsigned int tx_packets,
+                               unsigned int rx_bytes, unsigned int tx_bytes,
+                               unsigned int rx_errors, unsigned int tx_errors,
+                               unsigned int rx_dropped, unsigned int tx_dropped)
 {
        unsigned int seconds;
        struct connman_stats *stats = &service->stats;
@@ -3087,16 +3161,34 @@ void __connman_service_stats_update(struct connman_service *service,
                return;
 
        if (stats->valid == TRUE) {
+               stats->rx_packets +=
+                       rx_packets - stats->rx_packets_last;
+               stats->tx_packets +=
+                       tx_packets - stats->tx_packets_last;
                stats->rx_bytes +=
                        rx_bytes - stats->rx_bytes_last;
                stats->tx_bytes +=
                        tx_bytes - stats->tx_bytes_last;
+               stats->rx_errors +=
+                       rx_errors - stats->rx_errors_last;
+               stats->tx_errors +=
+                       tx_errors - stats->tx_errors_last;
+               stats->rx_dropped +=
+                       rx_dropped - stats->rx_dropped_last;
+               stats->tx_dropped +=
+                       tx_dropped - stats->tx_dropped_last;
        } else {
                stats->valid = TRUE;
        }
 
+       stats->rx_packets_last = rx_packets;
+       stats->tx_packets_last = tx_packets;
        stats->rx_bytes_last = rx_bytes;
        stats->tx_bytes_last = tx_bytes;
+       stats->rx_errors_last = rx_errors;
+       stats->tx_errors_last = tx_errors;
+       stats->rx_dropped_last = rx_dropped;
+       stats->tx_dropped_last = tx_dropped;
 
        seconds = g_timer_elapsed(stats->timer, NULL);
        stats->time = stats->time_start + seconds;
index 7c2fa4a..111d4fc 100755 (executable)
@@ -34,7 +34,11 @@ class Counter(dbus.service.Object):
                                        in_signature='oa{sv}', out_signature='')
        def Usage(self, path, stats):
                print "%s" % (path)
-               for key in stats.keys():
+
+               keys = stats.keys()
+               keys.sort()
+
+               for key in keys:
                        val = int(stats[key])
                        str = "  %s = %s" % (key, val)