| 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 |
|
| 19 |
#ifndef INCLUDED_PERCTILE_STATS_H |
| 20 |
#define INCLUDED_PERCTILE_STATS_H |
| 21 |
|
| 22 |
#include "hashtable.h" |
| 23 |
#include "statsobj.h" |
| 24 |
|
| 25 |
struct perctile_ctr_s { |
| 26 |
// percentile [0,100] |
| 27 |
uint8_t percentile; |
| 28 |
size_t index; |
| 29 |
intctr_t ctr_perctile_stat; |
| 30 |
ctr_t *ref_ctr_percentile_stat; |
| 31 |
}; |
| 32 |
|
| 33 |
struct perctile_stat_s { |
| 34 |
uchar name[128]; |
| 35 |
sbool bReported; |
| 36 |
struct ringbuf_s *rb_observed_stats; |
| 37 |
// array of requested perctile to track |
| 38 |
struct perctile_ctr_s *ctrs; |
| 39 |
size_t perctile_ctrs_count; |
| 40 |
|
| 41 |
pthread_rwlock_t stats_lock; |
| 42 |
intctr_t ctrWindowCount; |
| 43 |
ctr_t *refCtrWindowCount; |
| 44 |
intctr_t ctrWindowMin; |
| 45 |
ctr_t *refCtrWindowMin; |
| 46 |
intctr_t ctrWindowMax; |
| 47 |
ctr_t *refCtrWindowMax; |
| 48 |
intctr_t ctrWindowSum; |
| 49 |
ctr_t *refCtrWindowSum; |
| 50 |
}; |
| 51 |
|
| 52 |
struct perctile_bucket_s { |
| 53 |
uchar *name; |
| 54 |
uchar *delim; |
| 55 |
// lock for entire bucket |
| 56 |
pthread_rwlock_t lock; |
| 57 |
struct hashtable *htable; |
| 58 |
struct perctile_bucket_s *next; |
| 59 |
statsobj_t *statsobj; |
| 60 |
STATSCOUNTER_DEF(ctrNewKeyAdd, mutCtrNewKeyAdd); |
| 61 |
ctr_t *pNewKeyAddCtr; |
| 62 |
STATSCOUNTER_DEF(ctrOpsOverflow, mutCtrOpsOverflow); |
| 63 |
ctr_t *pOpsOverflowCtr; |
| 64 |
uint32_t window_size; |
| 65 |
// These percentile values apply to all perctile stats in this bucket. |
| 66 |
uint8_t *perctile_values; |
| 67 |
size_t perctile_values_count; |
| 68 |
}; |
| 69 |
|
| 70 |
struct perctile_buckets_s { |
| 71 |
uint8_t initialized; |
| 72 |
statsobj_t *global_stats; |
| 73 |
pthread_rwlock_t lock; |
| 74 |
struct perctile_bucket_s *listBuckets; |
| 75 |
}; |
| 76 |
|
| 77 |
// keep these local for now. |
| 78 |
typedef struct perctile_ctr_s perctile_ctr_t; |
| 79 |
typedef struct perctile_stat_s perctile_stat_t; |
| 80 |
typedef struct perctile_bucket_s perctile_bucket_t; |
| 81 |
|
| 82 |
rsRetVal perctileClassInit(void); |
| 83 |
void perctileBucketsDestruct(void); |
| 84 |
rsRetVal perctile_initCnf(perctile_buckets_t *b); |
| 85 |
perctile_bucket_t *perctile_findBucket(const uchar *name); |
| 86 |
rsRetVal perctile_processCnf(struct cnfobj *cnf); |
| 87 |
rsRetVal perctile_obs(perctile_bucket_t *perctile_bkt, uchar *key, int64_t value); |
| 88 |
|
| 89 |
#endif /* #ifndef INCLUDED_PERCTILE_STATS_H */ |