Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add id and hostname to server stats.

  • Loading branch information...
commit d5ffd665048ef7e3fbac4fff002073e487820dea 1 parent 84b12d2
nathanielc authored root committed
Showing with 41 additions and 1 deletion.
  1. +2 −0  doc/protocol.md
  2. +5 −0 doc/protocol.txt
  3. +34 −1 prot.c
View
2  doc/protocol.md
@@ -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
View
5 doc/protocol.txt
@@ -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
View
35 prot.c
@@ -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>
@@ -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" \
@@ -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;
@@ -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);
}
@@ -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"));
Please sign in to comment.
Something went wrong with that request. Please try again.