[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r1331 - gnunet-gtk/src/plugins/stats
From: |
grothoff |
Subject: |
[GNUnet-SVN] r1331 - gnunet-gtk/src/plugins/stats |
Date: |
Fri, 8 Jul 2005 16:30:07 -0700 (PDT) |
Author: grothoff
Date: 2005-07-08 16:30:03 -0700 (Fri, 08 Jul 2005)
New Revision: 1331
Added:
gnunet-gtk/src/plugins/stats/functions.c
gnunet-gtk/src/plugins/stats/functions.h
Log:
oops
Added: gnunet-gtk/src/plugins/stats/functions.c
===================================================================
--- gnunet-gtk/src/plugins/stats/functions.c 2005-07-08 23:29:37 UTC (rev
1330)
+++ gnunet-gtk/src/plugins/stats/functions.c 2005-07-08 23:30:03 UTC (rev
1331)
@@ -0,0 +1,376 @@
+/*
+ This file is part of GNUnet
+ (C) 2004, 2005 Christian Grothoff (and other contributing authors)
+
+ GNUnet 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, or (at your
+ option) any later version.
+
+ GNUnet 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 GNUnet; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+
+*/
+
+#include "platform.h"
+#include "gnunetgtk_common.h"
+#include <GNUnet/gnunet_stats_lib.h>
+#include <GNUnet/gnunet_getoption_lib.h>
+#include <GNUnet/gnunet_protocols.h>
+#include "functions.h"
+
+static StatPair * lastStatValues;
+
+static unsigned int lsv_size;
+
+static GNUNET_TCP_SOCKET * sock;
+
+static int getStatValue(long long * value,
+ long long * lvalue,
+ cron_t * dtime,
+ const char * optName) {
+ unsigned int i;
+
+ *value = 0;
+ if (lvalue != NULL)
+ *lvalue = 0;
+ for (i=0;i<lsv_size;i++) {
+ if (0 == strcmp(optName,
+ lastStatValues[i].statName)) {
+ *value = lastStatValues[i].value;
+ if (lvalue != NULL)
+ *lvalue = lastStatValues[i].lvalue;
+ if (dtime != NULL)
+ *dtime = lastStatValues[i].delta;
+ return OK;
+ }
+ }
+ return SYSERR;
+}
+
+static int getConnectedNodesStat(const void * closure,
+ gfloat ** data) {
+ long long val;
+ char * cmh;
+ long cval;
+
+ cmh = getConfigurationOptionValue(sock,
+ "gnunetd",
+ "connection-max-hosts");
+ if (cmh == NULL)
+ return SYSERR;
+ cval = atol(cmh);
+ FREE(cmh);
+ if (OK != getStatValue(&val,
+ NULL,
+ NULL,
+ _("# currently connected nodes")))
+ return SYSERR;
+ data[0][0] = 0.8 * val / cval;
+ return OK;
+}
+
+static int getCPULoadStat(const void * closure,
+ gfloat ** data) {
+ long long val;
+
+ if (OK != getStatValue(&val,
+ NULL,
+ NULL,
+ _("% of allowed cpu load")))
+ return SYSERR;
+ data[0][0] = val / 125.0;
+ return OK;
+}
+
+static int getTrafficRecvStats(const void * closure,
+ gfloat ** data) {
+ long long total;
+ long long noise;
+ long long content;
+ long long queries;
+ long long ltotal;
+ long long lnoise;
+ long long lcontent;
+ long long lqueries;
+ long long band;
+ long long tmp;
+ long long ltmp;
+ cron_t dtime;
+ char * available;
+ char * buffer;
+ int i;
+
+ if (OK != getStatValue(&total,
+ <otal,
+ &dtime,
+ _("# bytes decrypted")))
+ return SYSERR;
+ if (OK != getStatValue(&noise,
+ &lnoise,
+ NULL,
+ _("# bytes of noise received")))
+ return SYSERR;
+ i = 0;
+ content = lcontent = 0;
+ buffer = MALLOC(512);
+ SNPRINTF(buffer,
+ 512,
+ _("# bytes received of type %d"),
+ GAP_p2p_PROTO_RESULT);
+ if (OK == getStatValue(&tmp,
+ <mp,
+ NULL,
+ buffer)) {
+ content += tmp;
+ lcontent += ltmp;
+ }
+ i = 0;
+ SNPRINTF(buffer,
+ 512,
+ _("# bytes received of type %d"),
+ GAP_p2p_PROTO_QUERY);
+ if (OK == getStatValue(&tmp,
+ <mp,
+ NULL,
+ buffer)) {
+ queries += tmp;
+ lqueries += ltmp;
+ }
+ FREE(buffer);
+ available = getConfigurationOptionValue(sock,
+ "LOAD",
+ "MAXNETDOWNBPSTOTAL");
+ if (available == NULL)
+ return SYSERR;
+ band = atol(available) * dtime / cronSECONDS;
+ FREE(available);
+ total -= ltotal;
+ noise -= lnoise;
+ queries -= lqueries;
+ content -= lcontent;
+ if (band <= 0) {
+ data[0][0] = 0.0;
+ data[0][1] = 0.0;
+ data[0][2] = 0.0;
+ data[0][3] = 0.0;
+ return OK;
+ }
+ data[0][0] = 0.8 * noise / band; /* red */
+ data[0][1] = 0.8 * (content+noise) / band; /* green */
+ data[0][2] = 0.8 * (queries+content+noise) / band; /* yellow */
+ data[0][3] = 0.8 * total / band; /* blue */
+ /*printf("I: %f %f %f\n",
+ data[0][0],
+ data[0][1],
+ data[0][2]);*/
+
+ return OK;
+}
+
+static int getTrafficSendStats(const void * closure,
+ gfloat ** data) {
+ long long total;
+ long long noise;
+ long long content;
+ long long queries;
+ long long ltotal;
+ long long lnoise;
+ long long lcontent;
+ long long lqueries;
+ long long band;
+ long long tmp;
+ long long ltmp;
+ cron_t dtime;
+ char * available;
+ char * buffer;
+ int i;
+
+ if (OK != getStatValue(&total,
+ <otal,
+ &dtime,
+ _("# encrypted bytes sent")))
+ return SYSERR;
+ if (OK != getStatValue(&noise,
+ &lnoise,
+ NULL,
+ _("# bytes noise sent")))
+ return SYSERR;
+ i = 0;
+ content = lcontent = 0;
+ buffer = MALLOC(512);
+ SNPRINTF(buffer,
+ 512,
+ _("# bytes transmitted of type %d"),
+ GAP_p2p_PROTO_RESULT);
+ if (OK == getStatValue(&tmp,
+ <mp,
+ NULL,
+ buffer)) {
+ content += tmp;
+ lcontent += ltmp;
+ }
+ i = 0;
+ SNPRINTF(buffer,
+ 512,
+ _("# bytes received of type %d"),
+ GAP_p2p_PROTO_QUERY);
+ if (OK == getStatValue(&tmp,
+ <mp,
+ NULL,
+ buffer)) {
+ queries += tmp;
+ lqueries += ltmp;
+ }
+ FREE(buffer);
+ available = getConfigurationOptionValue(sock,
+ "LOAD",
+ "MAXNETUPBPSTOTAL");
+ if (available == NULL)
+ return SYSERR;
+ band = atol(available) * dtime / cronSECONDS;
+ FREE(available);
+ total -= ltotal;
+ noise -= lnoise;
+ queries -= lqueries;
+ content -= lcontent;
+ if (band <= 0) {
+ data[0][0] = 0.0;
+ data[0][1] = 0.0;
+ data[0][2] = 0.0;
+ data[0][3] = 0.0;
+ return OK;
+ }
+ data[0][0] = 0.8 * noise / band; /* red */
+ data[0][1] = 0.8 * (noise + content) / band; /* green */
+ data[0][2] = 0.8 * (noise + content + queries) / band; /* yellow */
+ data[0][3] = 0.8 * total / band; /* yellow */
+ /* printf("O: %f %f %f\n",
+ data[0][0],
+ data[0][1],
+ data[0][2]);*/
+ return OK;
+}
+
+
+static int statsProcessor(const char * optName,
+ unsigned long long value,
+ void * data) {
+ cron_t * delta = data;
+ int j;
+ int found;
+
+ found = -1;
+ for (j=0;j<lsv_size;j++)
+ if (0 == strcmp(optName,
+ lastStatValues[j].statName))
+ found = j;
+ if (found == -1) {
+ found = lsv_size;
+ GROW(lastStatValues,
+ lsv_size,
+ lsv_size+1);
+ lastStatValues[found].statName
+ = STRDUP(optName);
+ }
+ lastStatValues[found].lvalue
+ = lastStatValues[found].value;
+ lastStatValues[found].value
+ = value;
+ lastStatValues[found].delta
+ = *delta;
+ return OK;
+}
+
+/**
+ * Cron-job that updates all stat values.
+ */
+static void updateStatValues(void * unused) {
+ static cron_t lastUpdate;
+ cron_t now;
+ cron_t delta;
+
+ cronTime(&now);
+ delta = now - lastUpdate;
+ if (OK == requestStatistics(sock,
+ &statsProcessor,
+ &delta))
+ lastUpdate = now;
+}
+
+
+StatEntry stats[] = {
+ {
+ gettext_noop("Connectivity"),
+ gettext_noop("# connected nodes (100% = connection table size)"),
+ &getConnectedNodesStat,
+ NULL,
+ 1,
+ NO,
+ },
+ {
+ gettext_noop("CPU load"),
+ gettext_noop("CPU load (in percent of allowed load)"),
+ &getCPULoadStat,
+ NULL,
+ 1,
+ NO,
+ },
+ {
+ gettext_noop("Inbound Traffic"),
+ gettext_noop("Noise (red), Content (green), Queries (yellow), other
(blue)"),
+ &getTrafficRecvStats,
+ NULL,
+ 4,
+ YES,
+ },
+ {
+ gettext_noop("Outbound Traffic"),
+ gettext_noop("Noise (red), Content (green), Queries (yellow), other
(blue)"),
+ &getTrafficSendStats,
+ NULL,
+ 4,
+ YES,
+ },
+ {
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ 1,
+ NO,
+ },
+};
+
+int UPDATE_INTERVAL;
+
+void init_functions() {
+ UPDATE_INTERVAL
+ = getConfigurationInt("GNUNET-GTK",
+ "STATS-INTERVAL") * cronSECONDS;
+ if (UPDATE_INTERVAL == 0)
+ UPDATE_INTERVAL = 30 * cronSECONDS;
+ sock = getClientSocket();
+ addCronJob(&updateStatValues,
+ UPDATE_INTERVAL,
+ UPDATE_INTERVAL,
+ NULL);
+}
+
+void done_functions() {
+ delCronJob(&updateStatValues,
+ UPDATE_INTERVAL,
+ NULL);
+ releaseClientSocket(sock);
+ sock = NULL;
+}
+
+
+/* end of functions.c */
Added: gnunet-gtk/src/plugins/stats/functions.h
===================================================================
--- gnunet-gtk/src/plugins/stats/functions.h 2005-07-08 23:29:37 UTC (rev
1330)
+++ gnunet-gtk/src/plugins/stats/functions.h 2005-07-08 23:30:03 UTC (rev
1331)
@@ -0,0 +1,59 @@
+/*
+ This file is part of GNUnet
+ (C) 2004, 2005 Christian Grothoff (and other contributing authors)
+
+ GNUnet 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, or (at your
+ option) any later version.
+
+ GNUnet 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 GNUnet; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+
+*/
+
+#ifndef STATS_FUNCTIONS_H
+#define STATS_FUNCTIONS_H
+
+#include <GNUnet/gnunet_util.h>
+
+typedef struct {
+ char * statName;
+ long long value;
+ long long lvalue;
+ cron_t delta;
+} StatPair;
+
+/**
+ * Callback function to obtain the latest stats
+ * data for this stat display.
+ */
+typedef int (*UpdateData)(const void * closure,
+ gfloat ** data);
+
+
+typedef struct SE_ {
+ char * paneName;
+ char * frameName;
+ UpdateData getData;
+ void * get_closure;
+ unsigned int count;
+ int fill; /* YES / NO */
+} StatEntry;
+
+extern StatEntry stats[];
+
+extern int UPDATE_INTERVAL;
+
+void init_functions(void);
+
+void done_functions(void);
+
+#endif
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r1331 - gnunet-gtk/src/plugins/stats,
grothoff <=