Debian Codegraph @

runtime/dynstats.h

raw
1 /*
2 * This file is part of the rsyslog runtime library.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 * -or-
10 * see COPYING.ASL20 in the source distribution
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18 #ifndef INCLUDED_DYNSTATS_H
19 #define INCLUDED_DYNSTATS_H
20
21 #include <sys/queue.h>
22 #include "hashtable.h"
23
24 typedef struct hashtable htable;
25 typedef struct rsconf_s rsconf_t;
26
27 struct dynstats_buckets_s;
28
29 struct dynstats_ctr_s {
30 STATSCOUNTER_DEF(ctr, mutCtr);
31 ctr_t *pCtr;
32 uchar *metric;
33 /* linked list ptr */
34 struct dynstats_ctr_s *next;
35 struct dynstats_ctr_s *prev;
36 };
37
38 struct dynstats_bucket_s {
39 struct dynstats_buckets_s *bkts;
40 htable *table;
41 uchar *name;
42 pthread_rwlock_t lock;
43 statsobj_t *stats;
44 STATSCOUNTER_DEF(ctrOpsOverflow, mutCtrOpsOverflow);
45 ctr_t *pOpsOverflowCtr;
46 STATSCOUNTER_DEF(ctrNewMetricAdd, mutCtrNewMetricAdd);
47 ctr_t *pNewMetricAddCtr;
48 STATSCOUNTER_DEF(ctrNoMetric, mutCtrNoMetric);
49 ctr_t *pNoMetricCtr;
50 STATSCOUNTER_DEF(ctrMetricsPurged, mutCtrMetricsPurged);
51 ctr_t *pMetricsPurgedCtr;
52 STATSCOUNTER_DEF(ctrOpsIgnored, mutCtrOpsIgnored);
53 ctr_t *pOpsIgnoredCtr;
54 STATSCOUNTER_DEF(ctrPurgeTriggered, mutCtrPurgeTriggered);
55 ctr_t *pPurgeTriggeredCtr;
56
57 /* file writer thread updates these counters - currently takes the bucket lock */
58
59 STATSCOUNTER_DEF(ctrFlushedBytes, mutCtrFlushedBytes);
60 ctr_t *pCtrFlushedBytes;
61 STATSCOUNTER_DEF(ctrFlushed, mutCtrFlushed);
62 ctr_t *pCtrFlushed;
63 STATSCOUNTER_DEF(ctrFlushedErrors, mutCtrFlushedErrors);
64 ctr_t *pCtrFlushedErrors;
65
66 struct dynstats_bucket_s *next; /* linked list ptr */
67 struct dynstats_ctr_s *ctrs;
68 /*survivor objects are used to keep counter values around for upto unused-ttl duration,
69 so in case it is accessed within (ttl - 2 * ttl) time-period we can re-store the
70 accumulator value from this */
71 struct dynstats_ctr_s *survivor_ctrs;
72 htable *survivor_table;
73
74 uint32_t maxCardinality;
75 uint32_t metricCount;
76 pthread_mutex_t mutMetricCount;
77 uint32_t unusedMetricLife;
78 uint32_t lastResetTs;
79 struct timespec metricCleanupTimeout;
80 uint8_t resettable;
81 uchar *state_file_directory;
82 uint32_t persist_state_write_count_interval; /* count of bucket updates before persisting */
83 uint32_t persist_state_interval_secs; /* interval in secs bucket before persisting bucket state */
84 time_t persist_expiration_time;
85 uint32_t n_updates; /* number of bucket updates before persisting the stream */
86 };
87
88 struct dynstats_file_write_queue_s {
89 STAILQ_HEAD(head, file_write_entry_s) q;
90 STATSCOUNTER_DEF(ctrEnq, mutCtrEnq);
91 int size;
92 int ctrMaxSz;
93 statsobj_t *stats;
94 pthread_mutex_t mut;
95 pthread_cond_t wakeup_worker;
96 };
97
98 struct dynstats_wrkrInfo_s {
99 pthread_t tid; /* the worker's thread ID */
100 };
101
102 struct dynstats_buckets_s {
103 struct dynstats_bucket_s *list;
104 statsobj_t *global_stats;
105 pthread_rwlock_t lock;
106 uint8_t initialized;
107 /* background file write worker data */
108 struct dynstats_file_write_queue_s work_q;
109 uint8_t wrkrRunning;
110 uint8_t wrkrTermState;
111 uint8_t wrkrStarted;
112 struct dynstats_wrkrInfo_s wrkrInfo;
113 };
114
115 rsRetVal dynstats_initCnf(dynstats_buckets_t *b);
116 rsRetVal dynstats_processCnf(struct cnfobj *o);
117 dynstats_bucket_t *dynstats_findBucket(const uchar *name);
118 rsRetVal dynstats_inc(dynstats_bucket_t *bucket, uchar *metric);
119 void dynstats_destroyAllBuckets(rsconf_t *cnf);
120 void dynstats_resetExpired(void);
121 rsRetVal dynstatsClassInit(void);
122
123 #endif /* #ifndef INCLUDED_DYNSTATS_H */