File: aggregator.h

package info (click to toggle)
carbon-c-relay 3.4-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 1,604 kB
  • sloc: ansic: 8,354; sh: 1,401; yacc: 924; lex: 354; python: 112; makefile: 110
file content (83 lines) | stat: -rw-r--r-- 2,913 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/*
 * Copyright 2013-2018 Fabian Groffen
 *
 * 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 <pthread.h>

#include "server.h"
#include "posixregex.h"

#define AGGR_HT_POW_SIZE  12  /* 4096: too big? issue #60 */
typedef struct _aggregator {
	unsigned short interval;  /* when to perform the aggregation */
	unsigned short expire;    /* when incoming metrics are no longer valid */
	enum _aggr_timestamp { TS_START, TS_MIDDLE, TS_END } tswhen;
	unsigned char bucketcnt;
	int disp_conn;
	int fd;
	size_t received;
	size_t sent;
	size_t dropped;
	struct _aggr_computes {
		enum _aggr_compute_type { SUM, CNT, MAX, MIN, AVG,
		                          MEDN, PCTL, VAR, SDEV } type;
		const char *metric;   /* name template of metric to produce */
		struct _aggr_invocations {
			char *metric;       /* actual name to emit */
			unsigned int hash;  /* to speed up matching */
			unsigned short expire;  /* expire + splay */
			struct _aggr_bucket {
				pthread_mutex_t bcklock;
				enum { A_OPEN, A_EXPIRE } state;
				long long int start;
				size_t cnt;
				double sum;
				double max;
				double min;
				struct _aggr_bucket_entries {
					size_t size;
					double *values;
				} entries;
			} *buckets;
			struct _aggr_invocations *next;
		} *invocations_ht[1 << AGGR_HT_POW_SIZE];
		unsigned char entries_needed:1;
		unsigned char percentile:7;
		pthread_rwlock_t invlock;
		struct _aggr_computes *next;
	} *computes;
	struct _aggregator *next;
} aggregator;

aggregator *aggregator_new(unsigned int interval, unsigned int expire, enum _aggr_timestamp tswhen);
char aggregator_add_compute(aggregator *s, const char *metric, enum _aggr_compute_type type, unsigned char pctl);
void aggregator_set_stub(aggregator *s, const char *stubname);
void aggregator_putmetric(aggregator *s, const char *metric, const char *firstspace, size_t nmatch, regmatch_t *pmatch);
int aggregator_start(aggregator *aggrs);
void aggregator_stop(void);
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);

#endif