I want to in the jmx_exporter configuration formulate a rule for the JMX datasources metircs such as:
# HELP catalina_datasource_testonborrow Catalina:name="jdbc/AgentDesktopDS",type=DataSource,attribute=TestOnBorrow
# TYPE catalina_datasource_testonborrow untyped
catalina_datasource_testonborrow{host="worker1",context="/AgentDesktop_lcr",class="javax.sql.DataSource",name="\"jdbc/AgentDesktopDS\"",connectionpool="connections",} 1.0
catalina_datasource_testonborrow{host="worker1",context="/AgentDesktop_lcr",class="javax.sql.DataSource",name="\"jdbc/AgentDesktopCommLogDS\"",connectionpool="connections",} 1.0
catalina_datasource_testonborrow{host="worker1",context="/AgentDesktop_lcr",class="javax.sql.DataSource",name="\"jdbc/AgentDesktopReportsDS\"",connectionpool="connections",} 1.0
catalina_datasource_testonborrow{host="worker1",context="/AgentDesktop_lcr",class="javax.sql.DataSource",name="\"jdbc/AgentDesktopCommLogDS\"",} 1.0
catalina_datasource_testonborrow{host="worker1",context="/AgentDesktop_lcr",class="javax.sql.DataSource",name="\"jdbc/AgentDesktopDS\"",} 1.0
catalina_datasource_testonborrow{host="worker1",context="/AgentDesktop_lcr",class="javax.sql.DataSource",name="\"jdbc/AgentDesktopReportsDS\"",} 1.0
catalina_datasource_testonborrow{host="worker1",context="/AgentDesktop_lcr",class="javax.sql.DataSource",name="\"jdbc/AgentDesktop_AdministrationDS\"",} 1.0
catalina_datasource_testonborrow{host="worker1",context="/AgentDesktop_lcr",class="javax.sql.DataSource",name="\"jdbc/AgentDesktop_CarDS\"",} 1.0
catalina_datasource_testonborrow{host="worker1",context="/AgentDesktop_lcr",class="javax.sql.DataSource",name="\"jdbc/AgentDesktop_AirDS\"",} 1.0
catalina_datasource_testonborrow{host="worker1",context="/AgentDesktop_lcr",class="javax.sql.DataSource",name="\"jdbc/AgentDesktop_CoreDS\"",} 1.0
My problem is how to handle the optional connectionpool property, which appears only is some of the metrics data. The best I could come up until now is a pattern like this:
lowercaseOutputLabelNames: true
lowercaseOutputName: true
rules:
- pattern: 'Catalina<type=DataSource, host=([-a-zA-Z0-9+&@#/%?=~_|!:.,;]*[-a-zA-Z0-9+&@#/%=~_|]), context=([-a-zA-Z0-9+/$%~_-|!.]*), class=javax.sql.DataSource, name="(.*)"(.*)><>(.*):'
name: tomcat_datasource_$5
labels:
context: $2
host: $1
blah: $4
# pool: $6
datasource: $3
help: Tomcat session $5
type: GAUGE
which gives me
# HELP tomcat_datasource_testonborrow Tomcat session TestOnBorrow
# TYPE tomcat_datasource_testonborrow gauge
tomcat_datasource_testonborrow{blah=", connectionpool=connections",context="/AgentDesktop_lcr",datasource="jdbc/AgentDesktopDS",host="worker1",} 1.0
tomcat_datasource_testonborrow{blah=", connectionpool=connections",context="/AgentDesktop_lcr",datasource="jdbc/AgentDesktopCommLogDS",host="worker1",} 1.0
tomcat_datasource_testonborrow{blah=", connectionpool=connections",context="/AgentDesktop_lcr",datasource="jdbc/AgentDesktopReportsDS",host="worker1",} 1.0
tomcat_datasource_testonborrow{context="/AgentDesktop_lcr",datasource="jdbc/AgentDesktopCommLogDS",host="worker1",} 1.0
tomcat_datasource_testonborrow{context="/AgentDesktop_lcr",datasource="jdbc/AgentDesktopDS",host="worker1",} 1.0
tomcat_datasource_testonborrow{context="/AgentDesktop_lcr",datasource="jdbc/AgentDesktopReportsDS",host="worker1",} 1.0
tomcat_datasource_testonborrow{context="/AgentDesktop_lcr",datasource="jdbc/AgentDesktop_AdministrationDS",host="worker1",} 1.0
tomcat_datasource_testonborrow{context="/AgentDesktop_lcr",datasource="jdbc/AgentDesktop_CarDS",host="worker1",} 1.0
tomcat_datasource_testonborrow{context="/AgentDesktop_lcr",datasource="jdbc/AgentDesktop_AirDS",host="worker1",} 1.0
tomcat_datasource_testonborrow{context="/AgentDesktop_lcr",datasource="jdbc/AgentDesktop_CoreDS",host="worker1",} 1.0
Group 4 works as a catch all- But when I tried to replace this with something like
- pattern: 'Catalina<type=DataSource, host=([-a-zA-Z0-9+&@#/%?=~_|!:.,;]*[-a-zA-Z0-9+&@#/%=~_|]), context=([-a-zA-Z0-9+/$%~_-|!.]*), class=javax.sql.DataSource, name="(.*)"(, connectionpool=(.*))?><>(.*):'
I got only the lines with or the lines without the connectionpool property.
Is there a way to make the optional pattern work