summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Wagner <daniel.wagner@bmw-carit.de>2010-07-08 15:32:02 +0200
committerMarcel Holtmann <marcel@holtmann.org>2010-07-08 10:35:46 -0300
commite9d553694c5863a89121ca9458ce95cdb478f3f1 (patch)
tree754b4d3b765bab61a924ca1a621be344ccf4ffcb
parent94d84fcb66a9a2ffce3a2ae688c3e2e958a21a3f (diff)
downloadconnman-e9d553694c5863a89121ca9458ce95cdb478f3f1.tar.gz
connman-e9d553694c5863a89121ca9458ce95cdb478f3f1.tar.bz2
connman-e9d553694c5863a89121ca9458ce95cdb478f3f1.zip
Add additionals statistics counters
Adding rx_packets, tx_packets, rx_errors, tx_errors, rx_dropped and tx_dropped counters.
-rw-r--r--doc/counter-api.txt30
-rw-r--r--src/connman.h19
-rw-r--r--src/counter.c35
-rw-r--r--src/ipconfig.c19
-rw-r--r--src/service.c100
-rwxr-xr-xtest/test-counter6
6 files changed, 195 insertions, 14 deletions
diff --git a/doc/counter-api.txt b/doc/counter-api.txt
index 14e5a010..98d7a172 100644
--- a/doc/counter-api.txt
+++ b/doc/counter-api.txt
@@ -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.
diff --git a/src/connman.h b/src/connman.h
index 23596204..3b8f7c26 100644
--- a/src/connman.h
+++ b/src/connman.h
@@ -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>
diff --git a/src/counter.c b/src/counter.c
index a4613ca1..a457a226 100644
--- a/src/counter.c
+++ b/src/counter.c
@@ -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;
diff --git a/src/ipconfig.c b/src/ipconfig.c
index a7d5d325..2ef600b1 100644
--- a/src/ipconfig.c
+++ b/src/ipconfig.c
@@ -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,
diff --git a/src/service.c b/src/service.c
index 3027cc8b..c76a9ee7 100644
--- a/src/service.c
+++ b/src/service.c
@@ -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;
diff --git a/test/test-counter b/test/test-counter
index 7c2fa4ab..111d4fc5 100755
--- a/test/test-counter
+++ b/test/test-counter
@@ -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)