Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

count the mail queue length

23 views
Skip to first unread message

andy....@gmail.com

unread,
Jul 10, 2015, 12:34:09 AM7/10/15
to
I have a mission to get the mail queue in postfix and draw it in a monitor system. However, i find people say that when doing `mailq` is much slower than `find /var/spool/postfix/{maildrop,incoming,active,incoming,deferred,hold}/ -type f|wc -l`.

However, i want to know is the two are equal. I have read the code about showq(when using `strace mailq`, it shows that `mailq` will connect to `showq` and get the result), i find [this](http://www.opensource.apple.com/source/postfix/postfix-174/postfix/src/showq/showq.c):

static void showq_service(VSTREAM *client, char *unused_service, char **argv)
{

VSTREAM *qfile;
const char *path;
int status;
char *id;
int file_count;
unsigned long queue_size = 0;
struct stat st;
struct queue_info {
char *name; /* queue name */
char *(*scan_next) (SCAN_DIR *); /* flat or recursive */
};
struct queue_info *qp;

static struct queue_info queue_info[] = {
MAIL_QUEUE_MAILDROP, scan_dir_next,
MAIL_QUEUE_ACTIVE, mail_scan_dir_next,
MAIL_QUEUE_INCOMING, mail_scan_dir_next,
MAIL_QUEUE_DEFERRED, mail_scan_dir_next,
MAIL_QUEUE_HOLD, mail_scan_dir_next,
0,
};

/*
* Sanity check. This service takes no command-line arguments.
*/
if (argv[0])
msg_fatal("unexpected command-line argument: %s", argv[0]);

/*
* Skip any files that have the wrong permissions. If we can't open an
* existing file, assume the system is out of resources or that it is
* mis-configured, and force backoff by raising a fatal error.
*/
file_count = 0;
for (qp = queue_info; qp->name != 0; qp++) {
SCAN_DIR *scan = scan_dir_open(qp->name);
char *saved_id = 0;

while ((id = qp->scan_next(scan)) != 0) {

/*
* XXX I have seen showq loop on the same queue id. That would be
* an operating system bug, but who cares whose fault it is. Make
* sure this will never happen again.
*/
if (saved_id) {
if (strcmp(saved_id, id) == 0) {
msg_warn("readdir loop on queue %s id %s", qp->name, id);
break;
}
myfree(saved_id);
}
saved_id = mystrdup(id);
status = mail_open_ok(qp->name, id, &st, &path);
if (status == MAIL_OPEN_YES) {
if (file_count == 0)
vstream_fprintf(client, STRING_FORMAT,
"-Queue ID-", "--Size--",
"----Arrival Time----",
"-Sender/Recipient-------");
else
vstream_fprintf(client, "\n");
if ((qfile = mail_queue_open(qp->name, id, O_RDONLY, 0)) != 0) {
queue_size += st.st_size;
showq_report(client, qp->name, id, qfile, (long) st.st_size,
st.st_mtime);
if (vstream_fclose(qfile))
msg_warn("close file %s %s: %m", qp->name, id);
} else if (strcmp(qp->name, MAIL_QUEUE_MAILDROP) == 0) {
queue_size += st.st_size;
vstream_fprintf(client, DROP_FORMAT, id, ' ',
(long) st.st_size,
asctime(localtime(&st.st_mtime)),
(unsigned) st.st_uid);
} else if (errno != ENOENT)
msg_fatal("open %s %s: %m", qp->name, id);
file_count++;
vstream_fflush(client);
}
vstream_fflush(client);
}
if (saved_id)
myfree(saved_id);
scan_dir_close(scan);
}
if (file_count == 0)
vstream_fprintf(client, "Mail queue is empty\n");
else {
vstream_fprintf(client, "\n-- %lu Kbytes in %d Request%s.\n",
queue_size / 1024, file_count,
file_count == 1 ? "" : "s");
}
}

Can this code make sure that the actually `mailq` do, or showq do, is also traversing the directory maildrop, incoming, active, incoming, dererred, hold and counting the number of files in them. So, in this way the two method to count the mail queue is equal.
0 new messages