blob: d8439bce794ab9e3d4242c978163aae0b09e3eb4 (
plain) (
blame)
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
|
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.config.proxy;
import com.yahoo.log.LogLevel;
import com.yahoo.log.event.Event;
/**
* Statistics/metrics for config proxy.
* //TODO Use metrics framework
*
* @author hmusum
* @since 5.1.7
*/
class ConfigProxyStatistics implements Runnable {
static final long defaultEventInterval = 5 * 60; // in seconds
private final long eventInterval; // in seconds
private boolean stopped;
private long lastRun = System.currentTimeMillis();
/* Number of RPC getConfig requests */
private long rpcRequests = 0;
private long processedRequests = 0;
private long errors = 0;
private long delayedResponses = 0;
ConfigProxyStatistics() {
this(defaultEventInterval);
}
ConfigProxyStatistics(long eventInterval) {
this.eventInterval = eventInterval;
}
// Send events every eventInterval seconds
public void run() {
while (true) {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
ProxyServer.log.log(LogLevel.WARNING, e.getMessage());
}
if (stopped) {
return;
}
ProxyServer.log.log(LogLevel.SPAM, "Running ConfigProxyStatistics");
// Only send events every eventInterval seconds
if ((System.currentTimeMillis() - lastRun) > eventInterval * 1000) {
lastRun = System.currentTimeMillis();
sendEvents();
}
}
}
private void sendEvents() {
Event.count("rpc_requests", rpcRequests());
Event.count("processed_messages", processedRequests());
Event.count("errors", errors());
Event.value("delayed_responses", delayedResponses());
}
void stop() {
stopped = true;
}
Long getEventInterval() {
return eventInterval;
}
void incRpcRequests() {
rpcRequests++;
}
void incProcessedRequests() {
processedRequests++;
}
void incErrorCount() {
errors++;
}
long processedRequests() {
return processedRequests;
}
long rpcRequests() {
return rpcRequests;
}
long errors() {
return errors;
}
long delayedResponses() {
return delayedResponses;
}
void delayedResponses(long count) {
delayedResponses = count;
}
void decDelayedResponses() {
delayedResponses--;
}
}
|