Changeset: c9e05f679b7a for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=c9e05f679b7a
Modified Files:
common/utils/msabaoth.c
common/utils/msabaoth.h
monetdb5/modules/mal/pcre.c
tools/merovingian/ChangeLog.Feb2013
tools/merovingian/client/monetdb.1
tools/merovingian/client/monetdb.c
Branch: default
Log Message:
Merged from Feb2013
diffs (truncated from 409 to 300 lines):
diff --git a/common/utils/msabaoth.c b/common/utils/msabaoth.c
--- a/common/utils/msabaoth.c
+++ b/common/utils/msabaoth.c
@@ -774,6 +774,7 @@ msab_getUplogInfo(sabuplog *ret, const s
memset(ret, 0, sizeof(sabuplog));
ret->minuptime = -1;
ret->lastcrash = -1;
+ ret->laststop = -1;
snprintf(log, sizeof(log), "%s/%s", db->path, UPLOGFILE);
if ((f = fopen(log, "r")) != NULL) {
@@ -800,7 +801,7 @@ msab_getUplogInfo(sabuplog *ret, const s
/* successful stop */
ret->stopcntr++;
*p = '\0';
- stop = (time_t)atol(data);
+ ret->laststop = stop =
(time_t)atol(data);
p = data;
i = (int) (stop - start);
if (i > ret->maxuptime)
@@ -895,13 +896,13 @@ msab_serialise(char **ret, const sabdb *
"%s,%s,%d,%d,%s,"
"%d,%d,%d,"
"" LLFMT "," LLFMT "," LLFMT ","
- "" LLFMT "," LLFMT ","
+ "" LLFMT "," LLFMT "," LLFMT ","
"%d,%f,%f",
db->dbname, db->uri ? db->uri : "", db->locked,
(int)(db->state), scens,
dbu.startcntr, dbu.stopcntr, dbu.crashcntr,
(lng)dbu.avguptime, (lng)dbu.maxuptime,
(lng)dbu.minuptime,
- (lng)dbu.lastcrash, (lng)dbu.laststart,
+ (lng)dbu.lastcrash, (lng)dbu.laststart,
(lng)dbu.laststop,
dbu.crashavg1, dbu.crashavg10, dbu.crashavg30);
*ret = strdup(buf);
@@ -949,11 +950,12 @@ msab_deserialise(sabdb **ret, char *sdb)
if (strcmp(lasts, "1") == 0) {
/* Protocol 1 was used uptil Oct2012. Since Jul2012 a new state
* SABdbStarting was introduced, but not exposed to the client
- * in serialise. After Oct2012, the path component was removed
+ * in serialise. In Feb2013, the path component was removed
* and replaced by an URI field. This meant dbname could no
* longer be deduced from path, and hence sent separately.
* Since the conns property became useless in the light of the
- * added uri, it was dropped.
+ * added uri, it was dropped. On top of this, a laststop
+ * property was added to the uplog struct.
* These four changes were effectuated in protocol 2. When
* reading protocol 1, we use the path field to set dbname, but
* ignore the path information (and set uri to "<unknown>". The
@@ -1095,6 +1097,19 @@ msab_deserialise(sabdb **ret, char *sdb)
*p++ = '\0';
u->laststart = (time_t)strtoll(lasts, (char **)NULL, 10);
lasts = p;
+ if (protover != '1') {
+ if ((p = strchr(p, ',')) == NULL) {
+ free(u);
+ snprintf(buf, sizeof(buf),
+ "string does not contain laststop: %s",
lasts);
+ return(strdup(buf));
+ }
+ *p++ = '\0';
+ u->laststop = (time_t)strtoll(lasts, (char **)NULL, 10);
+ lasts = p;
+ } else {
+ u->laststop = -1;
+ }
if ((p = strchr(p, ',')) == NULL) {
free(u);
snprintf(buf, sizeof(buf),
diff --git a/common/utils/msabaoth.h b/common/utils/msabaoth.h
--- a/common/utils/msabaoth.h
+++ b/common/utils/msabaoth.h
@@ -55,6 +55,7 @@ typedef struct Ssabuplog {
time_t minuptime; /* shortest uptime when not crashing */
time_t lastcrash; /* time of last crash, -1 if none */
time_t laststart; /* time of last start */
+ time_t laststop; /* time of last stop, -1 if running */
int crashavg1; /* if there was a crash in the last start attempt */
double crashavg10; /* average of crashes in the last 10 start attempts
*/
double crashavg30; /* average of crashes in the last 30 start attempts
*/
diff --git a/monetdb5/modules/mal/pcre.c b/monetdb5/modules/mal/pcre.c
--- a/monetdb5/modules/mal/pcre.c
+++ b/monetdb5/modules/mal/pcre.c
@@ -110,10 +110,10 @@ typedef struct RE {
} RE;
#ifndef HAVE_STRCASESTR
-static char *
+static const char *
strcasestr (const char *haystack, const char *needle)
{
- char *p, *startn = 0, *np = 0;
+ const char *p, *np = 0, *startn = 0;
for (p = haystack; *p; p++) {
if (np) {
diff --git a/tools/merovingian/ChangeLog.Feb2013
b/tools/merovingian/ChangeLog.Feb2013
--- a/tools/merovingian/ChangeLog.Feb2013
+++ b/tools/merovingian/ChangeLog.Feb2013
@@ -1,6 +1,10 @@
# ChangeLog file for sql/src/backends/monet5/merovingian
# This file is updated with mchangelog
+* Fri Nov 30 2012 Fabian Groffen <[email protected]>
+- monetdb status now uses a more condensed output, to cater for the uris
+ being shown, and prints how long a database is stopped
+
* Wed Nov 21 2012 Fabian Groffen <[email protected]>
- monetdb status now prints the connection uri for each database,
when available. The connections and database path properties have
diff --git a/tools/merovingian/client/monetdb.1
b/tools/merovingian/client/monetdb.1
--- a/tools/merovingian/client/monetdb.1
+++ b/tools/merovingian/client/monetdb.1
@@ -114,7 +114,15 @@ output. By default a condensed one-line
used. This output resembles pretty much the output of various
.B xxxstat
programs, and is ideal for quickly gaining an overview of the system
-state.
+state. The output is divided in four columns,
+.IR name ", " state ", " health " and " remarks .
+The state column contains two characters that identify the state of the
+database, based on Booting (starting up), Running, Stopped, Crashed and
+Locked (under maintenance). This is followed by the uptime when
+running. The health column contains the percentage of successful starts
+and stops, followed by the average uptime. The remarks column can
+contain arbitrary information about the database state, but usually
+contains the URI the database can be connected to.
.IP " \-c"
The
.I \-c
diff --git a/tools/merovingian/client/monetdb.c
b/tools/merovingian/client/monetdb.c
--- a/tools/merovingian/client/monetdb.c
+++ b/tools/merovingian/client/monetdb.c
@@ -224,6 +224,7 @@ MEROgetStatus(sabdb **ret, char *databas
printf("WARNING: failed to parse response from "
"monetdbd: %s\n", e);
free(e);
+ swpos--;
continue;
}
if (swpos == swlen)
@@ -251,7 +252,7 @@ MEROgetStatus(sabdb **ret, char *databas
}
static void
-printStatus(sabdb *stats, int mode, int twidth)
+printStatus(sabdb *stats, int mode, int dbwidth, int uriwidth)
{
sabuplog uplog;
char *e;
@@ -264,30 +265,34 @@ printStatus(sabdb *stats, int mode, int
if (mode == 1) {
/* short one-line (default) mode */
- char *state;
+ char state = '\0';
+ char locked = '\0';
char uptime[12];
char avg[8];
char info[32];
char *dbname;
+ char *uri;
switch (stats->state) {
+ case SABdbStarting:
+ state = 'B';
+ break;
case SABdbRunning:
- state = "running";
+ state = 'R';
break;
case SABdbCrashed:
- state = "crashed";
+ state = 'C';
break;
- case SABdbStarting:
case SABdbInactive:
- state = "stopped";
+ state = 'S';
break;
default:
- state = "unknown";
+ state = ' ';
break;
}
/* override if locked for brevity */
if (stats->locked == 1)
- state = "locked ";
+ locked = 'L';
info[0] = '\0';
if (stats->state == SABdbStarting) {
@@ -303,25 +308,40 @@ printStatus(sabdb *stats, int mode, int
strftime(info, sizeof(info), "crashed on %Y-%m-%d
%H:%M:%S", t);
}
- if (stats->state != SABdbRunning) {
- uptime[0] = '\0';
- } else {
- secondsToString(uptime, time(NULL) - uplog.laststart,
3);
+ switch (stats->state) {
+ case SABdbRunning:
+ case SABdbStarting:
+ secondsToString(uptime, time(NULL) -
uplog.laststart, 1);
+ break;
+ case SABdbInactive:
+ if (uplog.laststop != -1) {
+ secondsToString(uptime, time(NULL) -
uplog.laststop, 1);
+ break;
+ } /* else fall through */
+ default:
+ uptime[0] = '\0';
+ break;
}
- /* cut too long database names */
- dbname = malloc(sizeof(char) * (twidth + 1));
- abbreviateString(dbname, stats->dbname, twidth);
- /* dbname | state | uptime | health */
- secondsToString(avg, uplog.avguptime, 1);
- printf("%-*s %s %12s", twidth,
- dbname, state, uptime);
+ /* cut too long names */
+ dbname = malloc(sizeof(char) * (dbwidth + 1));
+ abbreviateString(dbname, stats->dbname, dbwidth);
+ uri = malloc(sizeof(char) * (uriwidth + 1));
+ abbreviateString(uri,
+ info[0] != '\0' ? info : stats->uri ?
stats->uri : "",
+ uriwidth);
+ /* dbname | state | health | uri/crash */
+ printf("%-*s %c%c%3s", dbwidth, dbname,
+ locked ? locked : state, locked ? state : ' ',
uptime);
free(dbname);
- if (uplog.startcntr)
- printf(" %3d%%, %3s %s",
- 100 - (uplog.crashcntr * 100 /
uplog.startcntr),
- avg, info[0] != '\0' ? info :
stats->uri ? stats->uri : "");
- printf("\n");
+ if (uplog.startcntr) {
+ secondsToString(avg, uplog.avguptime, 1);
+ printf(" %3d%% %3s",
+ 100 - (uplog.crashcntr * 100 /
uplog.startcntr), avg);
+ } else {
+ printf(" ");
+ }
+ printf(" %-*s\n", uriwidth, uri);
} else if (mode == 2) {
/* long mode */
char *state;
@@ -387,6 +407,13 @@ printStatus(sabdb *stats, int mode, int
sprintf(up, "(unknown)");
}
printf(" last start: %s\n", up);
+ if (uplog.laststop != -1) {
+ t = localtime(&uplog.laststop);
+ strftime(up, 32, "%Y-%m-%d %H:%M:%S", t);
+ } else {
+ sprintf(up, "(unknown)");
+ }
+ printf(" last stop: %s\n", up);
printf(" average of crashes in the last start attempt: %d\n",
uplog.crashavg1);
printf(" average of crashes in the last 10 start attempts:
%.2f\n",
@@ -629,9 +656,12 @@ command_status(int argc, char *argv[])
char *e;
sabdb *stats;
sabdb *orig;
+ sabdb *prev;
+ sabdb *neworig = NULL;
int t;
+ int twidth = TERMWIDTH;
int dbwidth = 0;
- int twidth = TERMWIDTH;
+ int uriwidth = 0;
if (argc == 0) {
exit(2);
@@ -708,29 +738,9 @@ command_status(int argc, char *argv[])
msab_freeStatus(&orig);
orig = stats;
}
- /* calculate width, BUG: SABdbState selection is only done at
- * printing */
- for (stats = orig; stats != NULL; stats = stats->next) {
- if ((t = strlen(stats->dbname)) > dbwidth)
- dbwidth = t;
- }
- if (mode == 1 && orig != NULL) {
- /* print header for short mode, state -- last crash = 54 chars
*/
- twidth -= 54;
- if (twidth < 6)
- twidth = 6;
- if (dbwidth < 14)
- dbwidth = 14;
- if (dbwidth < twidth)
- twidth = dbwidth;
- printf("%*sname%*s ",
_______________________________________________
checkin-list mailing list
[email protected]
http://mail.monetdb.org/mailman/listinfo/checkin-list