Skip to content

Commit

Permalink
Add id and hostname to server stats.
Browse files Browse the repository at this point in the history
  • Loading branch information
nathanielc authored and root committed Dec 11, 2012
1 parent 84b12d2 commit d5ffd66
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 1 deletion.
2 changes: 2 additions & 0 deletions doc/protocol.md
Expand Up @@ -504,6 +504,8 @@ The stats data for the system is a YAML file representing a single dictionary of
* `binlog-max-size` is the maximum size in bytes a binlog file is allowed to get before a new binlog file is opened
* `binlog-records-written` is the cumulative number of records written to the binlog
* `binlog-records-migrated` is the cumulative number of records written as part of compaction
* `id` a unique id for this server process. The id is generated on each startup and is always a random series of 8 bytes base16 encoded
* `hostname` the hostname of the machine as determined by uname

#### `list-tubes` command

Expand Down
5 changes: 5 additions & 0 deletions doc/protocol.txt
Expand Up @@ -637,6 +637,11 @@ beanstalkd process starts; they are not stored on disk with the -b flag.
- "binlog-records-migrated" is the cumulative number of records written
as part of compaction

- "id" a unique id for this server process. The id is generated on each startup and
is always a random series of 8 bytes base16 encoded

- "hostname" the hostname of the machine as determined by uname

The list-tubes command returns a list of all existing tubes. Its form is:

list-tubes\r\n
Expand Down
35 changes: 34 additions & 1 deletion prot.c
Expand Up @@ -8,6 +8,7 @@
#include <sys/resource.h>
#include <sys/uio.h>
#include <sys/types.h>
#include <sys/utsname.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <inttypes.h>
Expand Down Expand Up @@ -183,6 +184,8 @@ size_t job_data_size_limit = JOB_DATA_SIZE_LIMIT_DEFAULT;
"binlog-records-migrated: %" PRId64 "\n" \
"binlog-records-written: %" PRId64 "\n" \
"binlog-max-size: %d\n" \
"id: %s\n" \
"hostname: %s\n" \
"\r\n"

#define STATS_TUBE_FMT "---\n" \
Expand Down Expand Up @@ -231,6 +234,14 @@ static tube default_tube;

static int drain_mode = 0;
static int64 started_at;

enum {
NumIdBytes = 8
};

static char id[NumIdBytes * 2 + 1]; // hex-encoded len of NumIdBytes

static struct utsname node_info;
static uint64 op_ct[TOTAL_OPS], timeout_ct = 0;

static Conn *dirty;
Expand Down Expand Up @@ -917,7 +928,9 @@ fmt_stats(char *buf, size_t size, void *x)
wcur,
srv->wal.nmig,
srv->wal.nrec,
srv->wal.filesize);
srv->wal.filesize,
id,
node_info.nodename);

}

Expand Down Expand Up @@ -1933,6 +1946,26 @@ prot_init()
started_at = nanoseconds();
memset(op_ct, 0, sizeof(op_ct));

int dev_random = open("/dev/urandom", O_RDONLY);
if (dev_random < 0) {
twarn("Error could not open '/dev/urandom' to generate server id.");
exit(50);
}

int i, r;
byte rand_data[NumIdBytes];
r = read(dev_random, &rand_data, NumIdBytes);
if (r != NumIdBytes) {
twarn("Error could not read '/dev/urandom' to generate server id.");
exit(50);
}
for (i = 0; i < NumIdBytes; i++) {
sprintf(id + (i * 2), "%02x", rand_data[i]);
}
close(dev_random);

uname(&node_info);

ms_init(&tubes, NULL, NULL);

TUBE_ASSIGN(default_tube, tube_find_or_make("default"));
Expand Down

0 comments on commit d5ffd66

Please sign in to comment.