summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--multiload/ChangeLog12
-rw-r--r--multiload/linux-proc.c83
-rw-r--r--multiload/linux-proc.h2
-rw-r--r--multiload/main.c13
-rw-r--r--multiload/multiload.schemas.in29
-rw-r--r--multiload/properties.c11
6 files changed, 92 insertions, 58 deletions
diff --git a/multiload/ChangeLog b/multiload/ChangeLog
index 3ff18e5f4..1d4a5f1ba 100644
--- a/multiload/ChangeLog
+++ b/multiload/ChangeLog
@@ -1,3 +1,15 @@
+2008-11-04 Callum McKenzie <callum@spooky-possum.org>
+
+ * multiload.schemas.in:
+ * properties.c:
+ * linux-proc.c:
+ * linux-proc.h:
+ * main.c: Change the netload applet to report packets in and out
+ rather than the transport protocol (slip and plip are ancient,
+ leaving the almost useless distinction of ethernet and
+ other). Patch supplied by Eric Piel. See bug 327509.
+
+
==================== 2.24.0.1 ====================
2008-08-10 Callum McKenzie <callum@spooky-possum.org>
diff --git a/multiload/linux-proc.c b/multiload/linux-proc.c
index 95031ba8a..1b08b517b 100644
--- a/multiload/linux-proc.c
+++ b/multiload/linux-proc.c
@@ -271,17 +271,48 @@ GetLoadAvg (int Maximum, int data [2], LoadGraph *g)
data [1] = Maximum - data[0];
}
-
+/*
+ * Return true if a network device (identified by its name) is virtual
+ * (ie: not corresponding to a physical device). In case it is a physical
+ * device or unknown, returns false.
+ */
+static gboolean
+is_net_device_virtual(char *device)
+{
+ /*
+ * There is not definitive way to find out. On some systems (Linux
+ * kernels ≳ 2.19 without option SYSFS_DEPRECATED), there exist a
+ * directory /sys/devices/virtual/net which only contains virtual
+ * devices. It's also possible to detect by the fact that virtual
+ * devices do not have a symlink "device" in
+ * /sys/class/net/name-of-dev/ . This second method is more complex
+ * but more reliable.
+ */
+ char path[PATH_MAX];
+
+ /* Check if /sys/class/net/name-of-dev/ exists (may be old linux kernel
+ * or not linux at all). */
+ if (sprintf(path, "/sys/class/net/%s", device) < 0)
+ return FALSE;
+ if (access(path, F_OK) != 0)
+ return FALSE; /* unknown */
+
+ if (sprintf(path, "/sys/class/net/%s/device", device) < 0)
+ return FALSE;
+ if (access(path, F_OK) != 0)
+ return TRUE;
+
+ return FALSE;
+}
void
-GetNet (int Maximum, int data [5], LoadGraph *g)
+GetNet (int Maximum, int data [4], LoadGraph *g)
{
enum Types {
- SLIP_COUNT = 0,
- PPP_COUNT = 1,
- ETH_COUNT = 2,
- OTHER_COUNT = 3,
- COUNT_TYPES = 4
+ IN_COUNT = 0,
+ OUT_COUNT = 1,
+ LOCAL_COUNT = 2,
+ COUNT_TYPES = 3
};
static int ticks = 0;
@@ -315,22 +346,21 @@ GetNet (int Maximum, int data [5], LoadGraph *g)
if (!(netload.if_flags & (1L << GLIBTOP_IF_FLAGS_UP)))
continue;
- if (netload.if_flags & (1L << GLIBTOP_IF_FLAGS_LOOPBACK))
+ if (netload.if_flags & (1L << GLIBTOP_IF_FLAGS_LOOPBACK)) {
+ /* for loopback in and out are identical, so only count in */
+ present[LOCAL_COUNT] += netload.bytes_in;
continue;
-
- if (netload.if_flags & (1L << GLIBTOP_IF_FLAGS_POINTOPOINT))
- {
- if (g_str_has_prefix(devices[i], "sl"))
- index = SLIP_COUNT;
- else
- index = PPP_COUNT;
}
- else if (g_str_has_prefix(devices[i], "eth"))
- index = ETH_COUNT;
- else
- index = OTHER_COUNT;
- present[index] += netload.bytes_total;
+ /*
+ * Do not include virtual devices (VPN, PPPOE...) to avoid
+ * counting the same throughput several times.
+ */
+ if (is_net_device_virtual(devices[i]))
+ continue;
+
+ present[IN_COUNT] += netload.bytes_in;
+ present[OUT_COUNT] += netload.bytes_out;
}
g_strfreev(devices);
@@ -361,17 +391,12 @@ GetNet (int Maximum, int data [5], LoadGraph *g)
for (i = 0; i < COUNT_TYPES; i++)
data[i] = rint (Maximum * (float)delta[i] / max);
-
-#if 0
- printf("dSLIP: %9d dPPP: %9d dOther: %9d, max: %9d\n",
- delta[SLIP_COUNT], delta[PPP_COUNT], delta[OTHER_COUNT], max);
-
- printf("vSLIP: %9d vPPP: %9d vOther: %9d, Maximum: %9d\n",
- data[0], data[1], data[2], Maximum);
-#endif
}
- data[4] = Maximum - data[3] - data[2] - data[1] - data[0];
+ //data[4] = Maximum - data[3] - data[2] - data[1] - data[0];
+ data[COUNT_TYPES] = Maximum;
+ for (i = 0; i < COUNT_TYPES; i++)
+ data[COUNT_TYPES] -= data[i];
memcpy(past, present, sizeof past);
}
diff --git a/multiload/linux-proc.h b/multiload/linux-proc.h
index c54bcb7f6..fdcb13598 100644
--- a/multiload/linux-proc.h
+++ b/multiload/linux-proc.h
@@ -11,6 +11,6 @@ G_GNUC_INTERNAL void GetPage (int Maximum, int data [3], LoadGraph *g);
G_GNUC_INTERNAL void GetMemory (int Maximum, int data [4], LoadGraph *g);
G_GNUC_INTERNAL void GetSwap (int Maximum, int data [2], LoadGraph *g);
G_GNUC_INTERNAL void GetLoadAvg (int Maximum, int data [2], LoadGraph *g);
-G_GNUC_INTERNAL void GetNet (int Maximum, int data [3], LoadGraph *g);
+G_GNUC_INTERNAL void GetNet (int Maximum, int data [4], LoadGraph *g);
#endif
diff --git a/multiload/main.c b/multiload/main.c
index 17cf911ad..dbf427e4d 100644
--- a/multiload/main.c
+++ b/multiload/main.c
@@ -289,7 +289,7 @@ multiload_applet_tooltip_update(LoadGraph *g)
name = g_strdup(_("Processor"));
else if (!strncmp(g->name, "memload", strlen("memload")))
name = g_strdup(_("Memory"));
- else if (!strncmp(g->name, "netload", strlen("netload")))
+ else if (!strncmp(g->name, "netload2", strlen("netload2")))
name = g_strdup(_("Network"));
else if (!strncmp(g->name, "swapload", strlen("swapload")))
name = g_strdup(_("Swap Space"));
@@ -363,7 +363,7 @@ multiload_create_graphs(MultiloadApplet *ma)
} graph_types[] = {
{ _("CPU Load"), "cpuload", 5, GetLoad },
{ _("Memory Load"), "memload", 5, GetMemory },
- { _("Net Load"), "netload", 5, GetNet },
+ { _("Net Load"), "netload2", 4, GetNet },
{ _("Swap Load"), "swapload", 2, GetSwap },
{ _("Load Average"), "loadavg", 2, GetLoadAvg },
{ _("Disk Load"), "diskload", 3, GetDiskLoad }
@@ -382,7 +382,14 @@ multiload_create_graphs(MultiloadApplet *ma)
gboolean visible;
char *key;
- key = g_strdup_printf ("view_%s", graph_types[i].name);
+ /* This is a special case to handle migration from an
+ * older version of netload to a newer one in the
+ * 2.25.1 release. */
+ if (g_strcmp0 ("netload2", graph_types[i].name) == 0) {
+ key = g_strdup ("view_netload");
+ } else {
+ key = g_strdup_printf ("view_%s", graph_types[i].name);
+ }
visible = panel_applet_gconf_get_bool (ma->applet, key, NULL);
g_free (key);
diff --git a/multiload/multiload.schemas.in b/multiload/multiload.schemas.in
index 588483ef3..6f2d9e30d 100644
--- a/multiload/multiload.schemas.in
+++ b/multiload/multiload.schemas.in
@@ -169,43 +169,34 @@
</schema>
<schema>
- <key>/schemas/apps/multiload/prefs/netload_color0</key>
+ <key>/schemas/apps/multiload/prefs/netload2_color0</key>
<owner>multiload-applet-2</owner>
<type>string</type>
- <default>#00b0b3</default>
+ <default>#fce94f</default>
<locale name="C">
- <short>Graph color for SLIP network activity</short>
+ <short>Graph color for input network activity</short>
</locale>
</schema>
<schema>
- <key>/schemas/apps/multiload/prefs/netload_color1</key>
+ <key>/schemas/apps/multiload/prefs/netload2_color1</key>
<owner>multiload-applet-2</owner>
<type>string</type>
- <default>#00e2e6</default>
+ <default>#edd400</default>
<locale name="C">
- <short>Graph color for PLIP network activity</short>
+ <short>Graph color for output network activity</short>
</locale>
</schema>
<schema>
- <key>/schemas/apps/multiload/prefs/netload_color2</key>
+ <key>/schemas/apps/multiload/prefs/netload2_color2</key>
<owner>multiload-applet-2</owner>
<type>string</type>
- <default>#00fbff</default>
+ <default>#c4a000</default>
<locale name="C">
- <short>Graph color for Ethernet network activity</short>
+ <short>Graph color for loopback network usage</short>
</locale>
</schema>
<schema>
- <key>/schemas/apps/multiload/prefs/netload_color3</key>
- <owner>multiload-applet-2</owner>
- <type>string</type>
- <default>#B7FEFF</default>
- <locale name="C">
- <short>Graph color for other network usage</short>
- </locale>
-</schema>
-<schema>
- <key>/schemas/apps/multiload/prefs/netload_color4</key>
+ <key>/schemas/apps/multiload/prefs/netload2_color3</key>
<owner>multiload-applet-2</owner>
<type>string</type>
<default>#000000</default>
diff --git a/multiload/properties.c b/multiload/properties.c
index 8c72d0062..dd912e50f 100644
--- a/multiload/properties.c
+++ b/multiload/properties.c
@@ -262,7 +262,7 @@ color_picker_set_cb(GtkColorButton *color_picker, gpointer data)
prop_type = PROP_CPU;
else if (strstr(gconf_path, "memload"))
prop_type = PROP_MEM;
- else if (strstr(gconf_path, "netload"))
+ else if (strstr(gconf_path, "netload2"))
prop_type = PROP_NET;
else if (strstr(gconf_path, "swapload"))
prop_type = PROP_SWAP;
@@ -622,11 +622,10 @@ fill_properties(GtkWidget *dialog, MultiloadApplet *ma)
page = add_page(ma->notebook, _("Network"));
gtk_container_set_border_width (GTK_CONTAINER (page), 12);
- add_color_selector (page, _("_SLIP"), "netload_color0", ma);
- add_color_selector(page, _("PL_IP"), "netload_color1", ma);
- add_color_selector (page, _("_Ethernet"), "netload_color2", ma);
- add_color_selector (page, _("Othe_r"), "netload_color3", ma);
- add_color_selector(page, _("_Background"), "netload_color4", ma);
+ add_color_selector (page, _("_In"), "netload2_color0", ma);
+ add_color_selector(page, _("_Out"), "netload2_color1", ma);
+ add_color_selector (page, _("_Local"), "netload2_color2", ma);
+ add_color_selector(page, _("_Background"), "netload2_color3", ma);
page = add_page(ma->notebook, _("Swap Space"));
gtk_container_set_border_width (GTK_CONTAINER (page), 12);