summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2005-03-17 16:40:36 +0000
committerDimitri Sokolyuk <demon@dim13.org>2005-03-17 16:40:36 +0000
commit1ef35c5e38f2b78d6bddf922b0ee3d4e1c05b5db (patch)
tree6b2c1daa0022d6974dd3190f1457ebbdead275d7
CGI: load average
-rw-r--r--lavg/Makefile7
-rw-r--r--lavg/lavg.c70
2 files changed, 77 insertions, 0 deletions
diff --git a/lavg/Makefile b/lavg/Makefile
new file mode 100644
index 0000000..9bdb443
--- /dev/null
+++ b/lavg/Makefile
@@ -0,0 +1,7 @@
+# $Id$
+
+PROG= lavg
+CFLAGS+= -Wall
+NOMAN=
+
+.include <bsd.prog.mk>
diff --git a/lavg/lavg.c b/lavg/lavg.c
new file mode 100644
index 0000000..b587d57
--- /dev/null
+++ b/lavg/lavg.c
@@ -0,0 +1,70 @@
+/* $Id$ */
+/*
+ * Copyright (c) 2005 demon <demon@vhost.dyndns.org>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#ifndef lint
+static const char rcsid[] = "$Id$";
+#endif /* not lint */
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#define THRESHOLD 1
+
+static const struct {
+ char *name;
+ char *color;
+} status[] = {
+ {"green", "#008B00"},
+ {"yellow", "#CDCD00"},
+ {"orange", "#FFA500"},
+ {"red", "#FF0000"}
+};
+
+#define NELEM 3
+
+int
+main(void)
+{
+ double avg[NELEM];
+ int i, n;
+
+ printf("Content-Type: text/html\n\n<html>\n");
+
+ if (getloadavg(avg, NELEM) == -1)
+ printf("no load average information available\n");
+ else {
+ n = 0;
+ for (i = 0; i < NELEM; i++) {
+ if (avg[i] > THRESHOLD)
+ n++;
+ }
+
+ printf("<head>\n<title>load %.2f %s</title>\n</head>\n<body>\n"
+ "load averages:", avg[0], status[n].name);
+ for (i = 0; i < NELEM; i++) {
+ if (i > 0)
+ printf(",");
+ printf(" %.2f", avg[i]);
+ }
+
+ printf("<br>\nload status: <font color=\"%s\">%s</font>\n"
+ "</body>\n", status[n].color, status[n].name);
+ }
+ printf("</html>\n");
+
+ exit(0);
+}