Skip to content

Commit 3f480b8

Browse files
committed
Fixed a couple of bugs in the userStatusLines, and added support for ignoring [monitorid] when doing the prefix matching.
1 parent b78c92c commit 3f480b8

File tree

7 files changed

+48
-21
lines changed

7 files changed

+48
-21
lines changed

CHANGELOG.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
3.6 (in development)
22
---
3-
...
3+
- Fixed a couple of bugs in the userStatusLines, and added support for ignoring ``[monitorid]`` when doing the prefix matching.
44

55
3.5
66
---

README.rst

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,22 @@ To do this create a .json configuration file containing a "userStatusLines" dici
7777

7878
{
7979
"userStatusLines":{
80+
81+
// This is for a typical application-defined status line. Note that any text inside [...] brackets (
82+
// typically the monitor instance id) is ignored.
83+
"com.mycompany.MyMonitor [1] MyApplication Status:": {
84+
// This prefix is added to the start of each alias to avoid clashes with other status KPIs
85+
"keyPrefix":"myApp.",
86+
87+
// Specifying user-friendly aliases for each key is optional. Always include any units (e.g. MB) in the key or alias
88+
"key:alias":{
89+
"kpi1":"",
90+
"kpi2":"kpi2AliasWithUnits",
91+
"kpi3":""
92+
}},
93+
8094
// This detects INFO level lines beginning with "JMS Status:"
8195
"JMS Status:": {
82-
// This prefix is added to the start of each alias to avoid clashes with other status KPIs
8396
"keyPrefix":"jms.",
8497
"key:alias":{
8598
"s":"s=senders",
@@ -107,15 +120,14 @@ To do this create a .json configuration file containing a "userStatusLines" dici
107120
}
108121
}
109122

110-
111123
Any user-defined status lines should be of the same form as the Correlator status lines, logged at INFO level,
112124
for example::
113125

114126
on all wait(5.0) {
115-
log "MyApplication status:"
127+
log "MyApplication Status:"
116128
+" kpi1="+kpi1.toString()
117129
+" kpi2="+kpi2.toString()
118-
+" string_kpi=\""+kpi3+"\"" at INFO;
130+
+" kpi3=\""+kpi3+"\"" at INFO;
119131
}
120132

121133
Technical detail: the frequency and timing of other status lines may not match when the main "Correlator status:" lines

apamax/log_analyzer.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -611,8 +611,10 @@ def handleLine(self, file, line, previousLine, **extra):
611611
return
612612
level = line.level
613613

614-
for userStatusPrefix, userStatus in self.args.userStatusLines.items():
614+
for (userStatusPrefix, userStatusPrefixAfterBracket), userStatus in self.args.userStatusLines.items():
615615
if m.startswith(userStatusPrefix):
616+
if userStatusPrefixAfterBracket is not None: # special handling of [n] values
617+
if userStatusPrefixAfterBracket not in m: continue
616618
self.handleRawStatusLine(file=file, line=line, userStatus=userStatus)
617619
break
618620

@@ -691,6 +693,7 @@ def handleRawStatusLine(self, file, line, userStatus=None, **extra):
691693
i+=1
692694
if endchar != '"':
693695
try:
696+
if val.endswith('%') and val[:-1].replace('.','').isdigit(): val = val[:-1] # for user-defined % values which would otherwise not be graphable
694697
if '.' in val:
695698
val = float(val)
696699
else:
@@ -2210,7 +2213,8 @@ def main(self, args):
22102213

22112214
globbedpaths = [toLongPathSafe(p) for p in globbedpaths]
22122215
globbedpaths.sort() # best we can do until when start reading them - hopefully puts the latest one at the end
2213-
2216+
2217+
userCharts = {}
22142218
if args.config:
22152219
with open(args.config, 'rb') as f:
22162220
jsonbytes = f.read()
@@ -2223,17 +2227,25 @@ def main(self, args):
22232227
columns = {k or COLUMN_DISPLAY_NAMES[k] for k in COLUMN_DISPLAY_NAMES}
22242228
for userStatusPrefix, userStatus in v.items():
22252229
if not userStatusPrefix.endswith(':'): raise UserError('userStatus prefixes should end with a ":"')
2230+
22262231
for k, alias in userStatus['key:alias'].items():
22272232
alias = userStatus['keyPrefix']+(alias or k)
22282233
if alias in columns: raise UserError(f"User status line '{userStatusPrefix}' contains display name '{alias}' which is already in use; consider using keyPrefix to ensure this status line doesn't conflict with display names from others")
22292234
columns.add(alias)
2235+
2236+
# need a hack to cope with [n] placeholders for monitor instance id
2237+
args.userStatusLines = {
2238+
(k[:k.index('[')+1] if ('[' in k and ']' in k) else k, # simple and hence efficient prefix match
2239+
k[k.index(']'):] if ('[' in k and ']' in k) else None,
2240+
):v for k, v in args.userStatusLines.items()
2241+
}
2242+
22302243
elif k == 'userCharts':
22312244
userCharts = v # allow overriding existing charts if desired
22322245
else:
22332246
raise UserError('Unknown key in config file: '%key)
22342247
else:
22352248
args.userStatusLines = {}
2236-
userCharts = {}
22372249

22382250
if not globbedpaths: raise UserError('No log files specified')
22392251

tests/correctness/Cor_018/Input/analyzer_config.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
11
{"userStatusLines":{
2+
3+
"com.mycompany.MyMonitor [1] MyApplication Status:": {
4+
"keyPrefix":"myApp.",
5+
"key:alias":{
6+
"kpi1":"",
7+
"kpi2":"kpi2AliasWithUnits",
8+
"kpi3":""
9+
}},
10+
211
"JMS Status:": {
312
"keyPrefix":"jms.",
413
"key:alias":{

tests/correctness/Cor_018/Input/correlator.log

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@
174174
2020-06-12 16:06:08.600 CRIT [14100] - test.Test [2] Some sample EPL output
175175
2020-06-12 16:06:09.599 CRIT [33128] - test.Test [2] Some sample EPL output
176176
2020-06-12 16:06:10.600 CRIT [33128] - test.Test [2] Some sample EPL output
177+
2020-06-12 16:06:16.500 INFO [140103309588224] - com.mycompany.MyMonitor [1] MyApplication Status: kpi1=100 kpi2=50% kpi3="a string" jeall=1390 jemap=1708 jeret=360 jeefficiency=81% sys=3136 use=1971 max=3122 tot=0 cur=3024 efficiency=65%
177178
2020-06-12 16:06:11.533 INFO [47556] - Correlator Status: sm=2 nctx=1 ls=5 rq=0 iq=0 oq=0 icq=0 lcn="<none>" lcq=0 lct=0.0 rx=11 tx=6 rt=0 nc=1 vm=615468 pm=267224 runq=0 si=14.4 so=0.0 srn="<none>" srq=0 jvm=76
178179
2020-06-12 16:06:11.533 INFO [47556:Status] - JMS Status: s=1 tx=6 sRate=1 sOutst=0 r=2 rx=4 rRate=0 rWindow=197 rRedel=0 rMaxDeliverySecs=0.0 rDupsDet=1 rDupIds=3 connErr=0 jvmMB=77
179180
2020-06-12 16:06:11.534 INFO [47556:Status] - JMSConnection myConnection: s=1 r=2 connErr=0 sessionsCreated=3
@@ -186,6 +187,7 @@
186187
2020-06-12 16:06:13.600 CRIT [14100] - test.Test [2] Some sample EPL output
187188
2020-06-12 16:06:14.600 CRIT [14100] - test.Test [2] Some sample EPL output
188189
2020-06-12 16:06:15.599 CRIT [14100] - test.Test [2] Some sample EPL output
190+
2020-06-12 16:06:16.500 INFO [140103309588224] - com.mycompany.MyMonitor [5] MyApplication Status: kpi1=1585 kpi2=80.2% kpi3="abc def" jeall=1390 jemap=1708 jeret=360 jeefficiency=81% sys=3136 use=1971 max=3122 tot=0 cur=3024 efficiency=65%
189191
2020-06-12 16:06:16.533 INFO [47556] - Correlator Status: sm=2 nctx=1 ls=5 rq=0 iq=0 oq=0 icq=0 lcn="<none>" lcq=0 lct=0.0 rx=11 tx=6 rt=0 nc=1 vm=615620 pm=267444 runq=0 si=0.0 so=0.0 srn="<none>" srq=0 jvm=107
190192
2020-06-12 16:06:16.534 INFO [47556:Status] - JMS Status: s=1 tx=6 sRate=0 sOutst=0 r=2 rx=4 rRate=0 rWindow=197 rRedel=0 rMaxDeliverySecs=0.0 rDupsDet=1 rDupIds=3 connErr=0 jvmMB=108
191193
2020-06-12 16:06:16.534 INFO [47556:Status] - JMSConnection myConnection: s=1 r=2 connErr=0 sessionsCreated=3

tests/correctness/Cor_018/Reference/user_status_final.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
myApp.kpi1=1585
2+
myApp.kpi2AliasWithUnits=80.2
3+
myApp.kpi3='abc def'
14
jms.s=senders=1
25
jms.r=receivers=2
36
jms.rx /sec=0
@@ -19,7 +22,7 @@ jms.r.q1.msgErrors=1
1922
jms.r.q1.jvmMB=None
2023
jms.r.q1.datetime='2020-06-12 16:06:11.534'
2124
jms.r.q1.epoch secs=1591977971.534
22-
jms.r.q1.line num=181
25+
jms.r.q1.line num=182
2326
p.numSnapshots=42
2427
p.lastSnapshotTime=624772
2528
p.snapshotWaitTimeEwmaMillis=0.03

tests/correctness/Cor_018/run.py

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,6 @@
77
from pysys.constants import *
88
from correlatorloganalyzer.analyzer_basetest import AnalyzerBaseTest
99

10-
"""
11-
12-
custom status line: just add teh values to the most recent real status line
13-
else we have to put them into separate files and it all gets tricky
14-
15-
add --help
16-
17-
18-
deal with error in first status line
19-
"""
20-
2110
class PySysTest(AnalyzerBaseTest):
2211

2312
def execute(self):
@@ -30,7 +19,7 @@ def execute(self):
3019
def validate(self):
3120
self.checkForAnalyzerErrors()
3221
header = self.getExprFromFile('loganalyzer_output/status.correlator.csv', '# (.*)').strip().split(',')
33-
header = header[header.index('jms.s=senders'):header.index('# metadata: ')]
22+
header = header[header.index('myApp.kpi1'):header.index('# metadata: ')]
3423
with open(self.output+'/loganalyzer_output/summary_status.correlator.json', 'rb') as f:
3524
summary = json.load(f)['status']
3625
final = [x for x in summary if x['statistic']=='100% (end)'][0]

0 commit comments

Comments
 (0)