FadingCounter.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 1996-2023 The Squid Software Foundation and contributors
3 *
4 * Squid software is distributed under GPLv2+ license and includes
5 * contributions from numerous individuals and organizations.
6 * Please see the COPYING and CONTRIBUTORS files for details.
7 */
8
9#ifndef SQUID_FADING_COUNTER_H
10#define SQUID_FADING_COUNTER_H
11
12#include <vector>
13
16{
17public:
19
21 void configure(double horizonSeconds);
22
23 void clear();
24
25 int count(int howMany);
26 int remembered() const { return total; }
27
29 double horizon;
30
31private:
32 const int precision;
33 double delta;
34
35 double lastTime;
36 std::vector<int> counters;
37 int total;
38};
39
40#endif /* SQUID_FADING_COUNTER_H */
41
Counts events, forgetting old ones. Useful for "3 errors/minute" limits.
Definition: FadingCounter.h:16
std::vector< int > counters
events per delta (possibly stale)
Definition: FadingCounter.h:36
int total
number of remembered events (possibly stale)
Definition: FadingCounter.h:37
int count(int howMany)
count fresh, return #events remembered
double horizon
read-only memory horizon in seconds; older events are forgotten
Definition: FadingCounter.h:29
void clear()
forgets all events
double delta
sub-interval duration = horizon/precision
Definition: FadingCounter.h:33
void configure(double horizonSeconds)
0=remember nothing; -1=forget nothing; new value triggers clear()
double lastTime
time of the last update
Definition: FadingCounter.h:35
int remembered() const
possibly stale #events
Definition: FadingCounter.h:26
const int precision
#counting slots, controls measur. accuracy
Definition: FadingCounter.h:32

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors