aggregator.h 2.74 KB
Newer Older
1
/*
Bernd Zeimetz's avatar
Bernd Zeimetz committed
2
 * Copyright 2013-2017 Fabian Groffen
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */


#ifndef AGGREGATOR_H
#define AGGREGATOR_H 1

#include <regex.h>
#include <pthread.h>

#include "server.h"

26
#define AGGR_HT_POW_SIZE  12  /* 4096: too big? issue #60 */
27 28 29
typedef struct _aggregator {
	unsigned short interval;  /* when to perform the aggregation */
	unsigned short expire;    /* when incoming metrics are no longer valid */
30
	enum _aggr_timestamp { TS_START, TS_MIDDLE, TS_END } tswhen;
31
	unsigned char bucketcnt;
32 33
	int disp_conn;
	int fd;
34 35 36 37
	size_t received;
	size_t sent;
	size_t dropped;
	struct _aggr_computes {
38 39
		enum _aggr_compute_type { SUM, CNT, MAX, MIN, AVG,
		                          MEDN, PCTL, VAR, SDEV } type;
40 41
		const char *metric;   /* name template of metric to produce */
		struct _aggr_invocations {
42 43
			char *metric;       /* actual name to emit */
			unsigned int hash;  /* to speed up matching */
44
			unsigned short expire;  /* expire + splay */
45
			struct _aggr_bucket {
46 47 48 49 50
				long long int start;
				size_t cnt;
				double sum;
				double max;
				double min;
51 52 53 54
				struct _aggr_bucket_entries {
					size_t size;
					double *values;
				} entries;
55 56
			} *buckets;
			struct _aggr_invocations *next;
57
		} *invocations_ht[1 << AGGR_HT_POW_SIZE];
58 59
		unsigned char entries_needed:1;
		unsigned char percentile:7;
60
		pthread_rwlock_t invlock;
61 62 63 64 65
		struct _aggr_computes *next;
	} *computes;
	struct _aggregator *next;
} aggregator;

66
aggregator *aggregator_new(unsigned int interval, unsigned int expire, enum _aggr_timestamp tswhen);
67
char aggregator_add_compute(aggregator *s, const char *metric, const char *type);
68
void aggregator_set_stub(aggregator *s, const char *stubname);
69
void aggregator_putmetric(aggregator *s, const char *metric, const char *firstspace, size_t nmatch, regmatch_t *pmatch);
70
int aggregator_start(aggregator *aggrs);
71
void aggregator_stop(void);
72 73 74 75 76 77 78 79
size_t aggregator_numaggregators(aggregator *agrs);
size_t aggregator_numcomputes(aggregator *aggrs);
size_t aggregator_get_received(aggregator *aggrs);
size_t aggregator_get_sent(aggregator *aggrs);
size_t aggregator_get_dropped(aggregator *aggrs);
size_t aggregator_get_received_sub(aggregator *aggrs);
size_t aggregator_get_sent_sub(aggregator *aggrs);
size_t aggregator_get_dropped_sub(aggregator *aggrs);
80 81

#endif