or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

async-operations.mdcomponent-lifecycle.mdcore-utilities.mddata-structures.mdindex.mdresource-management.mdsecurity.mdstatistics.mdthreading.md

statistics.mddocs/

0

# Statistics

1

2

Built-in statistics collection and monitoring capabilities for performance tracking and system diagnostics in server applications.

3

4

## Capabilities

5

6

### CounterStatistic

7

8

Counter-based statistics for tracking numeric values over time.

9

10

```java { .api }

11

/**

12

* Counter-based statistic tracking

13

*/

14

public class CounterStatistic {

15

/** Create counter statistic */

16

public CounterStatistic();

17

18

/** Increment counter by 1 */

19

public void increment();

20

21

/** Decrement counter by 1 */

22

public void decrement();

23

24

/** Add value to counter */

25

public void add(long value);

26

27

/** Get current value */

28

public long getCurrent();

29

30

/** Get maximum value reached */

31

public long getMax();

32

33

/** Reset counter to zero */

34

public void reset();

35

36

/** Reset and get previous max */

37

public long resetMax();

38

}

39

```

40

41

### RateStatistic

42

43

Rate-based statistics with time windows for monitoring throughput.

44

45

```java { .api }

46

/**

47

* Rate-based statistics with time windows

48

*/

49

public class RateStatistic {

50

/** Create rate statistic with time window */

51

public RateStatistic(long timeWindow, TimeUnit unit);

52

53

/** Record an event */

54

public void record();

55

56

/** Get current rate per second */

57

public double getRate();

58

59

/** Get rate for oldest time window */

60

public double getOldestRate();

61

62

/** Get total event count */

63

public long getTotal();

64

}

65

```

66

67

### SampleStatistic

68

69

Sampling-based statistics for analyzing value distributions.

70

71

```java { .api }

72

/**

73

* Sampling-based statistics

74

*/

75

public class SampleStatistic {

76

/** Create sample statistic */

77

public SampleStatistic();

78

79

/** Set current value */

80

public void set(long value);

81

82

/** Get maximum value */

83

public long getMax();

84

85

/** Get minimum value */

86

public long getMin();

87

88

/** Get mean value */

89

public double getMean();

90

91

/** Get standard deviation */

92

public double getStdDev();

93

94

/** Get sample count */

95

public long getCount();

96

97

/** Reset all statistics */

98

public void reset();

99

}

100

```

101

102

**Usage Examples:**

103

104

```java

105

import org.eclipse.jetty.util.statistic.*;

106

import java.util.concurrent.TimeUnit;

107

108

// Request counter

109

CounterStatistic requestCounter = new CounterStatistic();

110

requestCounter.increment(); // Track each request

111

System.out.println("Requests: " + requestCounter.getCurrent());

112

System.out.println("Peak: " + requestCounter.getMax());

113

114

// Request rate monitoring

115

RateStatistic requestRate = new RateStatistic(60, TimeUnit.SECONDS);

116

requestRate.record(); // Record each request

117

double rps = requestRate.getRate(); // Requests per second

118

119

// Response time statistics

120

SampleStatistic responseTime = new SampleStatistic();

121

responseTime.set(150); // Record response time in ms

122

System.out.println("Avg response: " + responseTime.getMean() + "ms");

123

System.out.println("Max response: " + responseTime.getMax() + "ms");

124

```

125

126

## Monitoring Patterns

127

128

Statistics are commonly used for:

129

130

- **Request counting**: Track total requests and concurrent requests

131

- **Rate monitoring**: Monitor requests per second, errors per minute

132

- **Performance metrics**: Response times, queue lengths, resource usage

133

- **Capacity planning**: Peak usage, growth trends, bottleneck identification

134

- **Health monitoring**: Error rates, timeout rates, success ratios