示例#1
0
struct brubeck_backend *
brubeck_carbon_new(struct brubeck_server *server, json_t *settings, int shard_n)
{
	struct brubeck_carbon *carbon = xcalloc(1, sizeof(struct brubeck_carbon));
	char *address;
	const char *global_prefix = carbon_global_prefix;
	const char *global_count_prefix = carbon_global_count_prefix;
	const char *prefix_counter = carbon_prefix_counter;
	const char *prefix_timer = carbon_prefix_timer;
	const char *prefix_gauge = carbon_prefix_gauge;
	int port, frequency, pickle, namespacing = 0;
	int legacy_namespace = 1;

	json_unpack_or_die(settings,
		"{s:s, s:i, s?:b, s:i, s?:b, s?:b, s?:s, s?:s, s?:s, s?:s, s?:s}",
		"address", &address,
		"port", &port,
		"pickle", &pickle,
		"frequency", &frequency,

		"namespacing", &namespacing,
		"legacy_namespace", &legacy_namespace,
		"global_prefix", &global_prefix,
		"global_count_prefix", &global_count_prefix,
		"prefix_counter", &prefix_counter,
		"prefix_timer", &prefix_timer,
		"prefix_gauge", &prefix_gauge);

	carbon->backend.type = BRUBECK_BACKEND_CARBON;
	carbon->backend.shard_n = shard_n;
	carbon->backend.connect = &carbon_connect;

	if (pickle) {
		carbon->backend.sample = &pickle1_each;
		carbon->backend.flush = &pickle1_flush;
		carbon->pickler.ptr = malloc(PICKLE_BUFFER_SIZE);
		pickle1_init(&carbon->pickler);
	} else {
		carbon->backend.sample = &plaintext_each;
		carbon->backend.flush = NULL;
	}

	carbon->backend.sample_freq = frequency;
	carbon->namespacing = namespacing;
	carbon->legacy_namespace = legacy_namespace;
	carbon->global_prefix = global_prefix;
	carbon->global_count_prefix = global_count_prefix;
	carbon->prefix_counter = prefix_counter;
	carbon->prefix_timer = prefix_timer;
	carbon->prefix_gauge = prefix_gauge;

	carbon->backend.server = server;
	carbon->out_sock = -1;
	url_to_inaddr2(&carbon->out_sockaddr, address, port);

	brubeck_backend_run_threaded((struct brubeck_backend *)carbon);
	log_splunk("backend=carbon event=started");

	return (struct brubeck_backend *)carbon;
}
示例#2
0
文件: statsd.c 项目: chenbk85/brubeck
struct brubeck_sampler *
brubeck_statsd_new(struct brubeck_server *server, json_t *settings)
{
	struct brubeck_statsd *std = xmalloc(sizeof(struct brubeck_statsd));

	char *address;
	int port;
	int multisock = 0;

	std->sampler.type = BRUBECK_SAMPLER_STATSD;
	std->sampler.shutdown = &shutdown_sampler;
	std->sampler.in_sock = -1;
	std->worker_count = 4;
	std->mmsg_count = 1;

	json_unpack_or_die(settings,
		"{s:s, s:i, s?:i, s?:i, s?:b}",
		"address", &address,
		"port", &port,
		"workers", &std->worker_count,
		"multimsg", &std->mmsg_count,
		"multisock", &multisock);

	brubeck_sampler_init_inet(&std->sampler, server, address, port);

#ifndef SO_REUSEPORT
	multisock = 0;
#endif

	if (!multisock)
		std->sampler.in_sock = brubeck_sampler_socket(&std->sampler, 0);

	run_worker_threads(std);
	return &std->sampler;
}
示例#3
0
static void load_config(struct brubeck_server *server, const char *path)
{
	json_error_t error;

	/* required */
	int capacity;
	json_t *backends, *samplers;

	/* optional */
	int expire = 0;
	char *http = NULL;

	server->name = "brubeck";
	server->config_name = get_config_name(path);
	server->dump_path = NULL;
	server->config = json_load_file(path, 0, &error);
	if (!server->config) {
		die("failed to load config file, %s (%s:%d:%d)",
				error.text, error.source, error.line, error.column);
	}

	json_unpack_or_die(server->config,
		"{s?:s, s:s, s:i, s:o, s:o, s?:s, s?:i}",
		"server_name", &server->name,
		"dumpfile", &server->dump_path,
		"capacity", &capacity,
		"backends", &backends,
		"samplers", &samplers,
		"http", &http,
		"expire", &expire);

	gh_log_set_instance(server->name);

	server->metrics = brubeck_hashtable_new(1 << capacity);
	if (!server->metrics)
	    die("failed to initialize hash table (size: %lu)", 1ul << capacity);

	load_backends(server, backends);
	load_samplers(server, samplers);

	if (http) brubeck_http_endpoint_init(server, http);
	if (expire) server->fd_expire = load_timerfd(expire);
}
示例#4
0
struct brubeck_backend *
brubeck_carbon_new(struct brubeck_server *server, json_t *settings, int shard_n)
{
	struct brubeck_carbon *carbon = xcalloc(1, sizeof(struct brubeck_carbon));
	char *address;
	int port, frequency, pickle = 0;

	json_unpack_or_die(settings,
		"{s:s, s:i, s?:b, s:i}",
		"address", &address,
		"port", &port,
		"pickle", &pickle,
		"frequency", &frequency);

	carbon->backend.type = BRUBECK_BACKEND_CARBON;
	carbon->backend.shard_n = shard_n;
	carbon->backend.connect = &carbon_connect;

	if (pickle) {
		carbon->backend.sample = &pickle1_each;
		carbon->backend.flush = &pickle1_flush;
		carbon->pickler.ptr = malloc(PICKLE_BUFFER_SIZE);
		pickle1_init(&carbon->pickler);
	} else {
		carbon->backend.sample = &plaintext_each;
		carbon->backend.flush = NULL;
	}

	carbon->backend.sample_freq = frequency;
	carbon->backend.server = server;
	carbon->out_sock = -1;
	url_to_inaddr2(&carbon->out_sockaddr, address, port);

	brubeck_backend_run_threaded((struct brubeck_backend *)carbon);
	log_splunk("backend=carbon event=started");

	return (struct brubeck_backend *)carbon;
}