|
| 1 | +local g = import './g.libsonnet'; |
| 2 | +local commonlib = import 'common-lib/common/main.libsonnet'; |
| 3 | +local logslib = import 'logs-lib/logs/main.libsonnet'; |
| 4 | + |
| 5 | +{ |
| 6 | + local root = self, |
| 7 | + new(this):: |
| 8 | + local prefix = this.config.dashboardNamePrefix; |
| 9 | + local links = this.grafana.links; |
| 10 | + local tags = this.config.dashboardTags; |
| 11 | + local uid = g.util.string.slugify(this.config.uid); |
| 12 | + local vars = this.grafana.variables; |
| 13 | + local annotations = this.grafana.annotations; |
| 14 | + local refresh = this.config.dashboardRefresh; |
| 15 | + local period = this.config.dashboardPeriod; |
| 16 | + local timezone = this.config.dashboardTimezone; |
| 17 | + { |
| 18 | + 'apache-tomcat-overview.json': |
| 19 | + g.dashboard.new(prefix + ' overview') |
| 20 | + + g.dashboard.withPanels( |
| 21 | + g.util.panel.resolveCollapsedFlagOnRows( |
| 22 | + g.util.grid.wrapPanels( |
| 23 | + [ |
| 24 | + this.grafana.rows.overview, |
| 25 | + ], |
| 26 | + ), |
| 27 | + ), |
| 28 | + ) + root.applyCommon( |
| 29 | + vars.multiInstance + [ |
| 30 | + g.dashboard.variable.query.new( |
| 31 | + 'protocol', |
| 32 | + query='label_values(tomcat_bytesreceived_total{%(queriesSelector)s}, protocol)' % vars |
| 33 | + ) |
| 34 | + + g.dashboard.variable.custom.selectionOptions.withMulti(true) |
| 35 | + + g.dashboard.variable.query.queryTypes.withLabelValues(label='protocol', metric='tomcat_bytesreceived_total{%(queriesSelector)s}' % vars) |
| 36 | + + g.dashboard.variable.query.withDatasourceFromVariable(variable=vars.datasources.prometheus), |
| 37 | + |
| 38 | + g.dashboard.variable.query.new( |
| 39 | + 'port', |
| 40 | + query='label_values(tomcat_bytesreceived_total{%(queriesSelector)s}, port)' % vars |
| 41 | + ) |
| 42 | + + g.dashboard.variable.custom.selectionOptions.withMulti(true) |
| 43 | + + g.dashboard.variable.query.queryTypes.withLabelValues(label='port', metric='tomcat_bytesreceived_total{%(queriesSelector)s}' % vars) |
| 44 | + + g.dashboard.variable.query.withDatasourceFromVariable(variable=vars.datasources.prometheus), |
| 45 | + ], |
| 46 | + uid + '_overview', |
| 47 | + tags, |
| 48 | + links { apacheTomcatOverview:: {} }, |
| 49 | + annotations, |
| 50 | + timezone, |
| 51 | + refresh, |
| 52 | + period |
| 53 | + ), |
| 54 | + |
| 55 | + 'apache-tomcat-hosts.json': |
| 56 | + g.dashboard.new(prefix + ' hosts') |
| 57 | + + g.dashboard.withPanels( |
| 58 | + g.util.panel.resolveCollapsedFlagOnRows( |
| 59 | + g.util.grid.wrapPanels( |
| 60 | + [ |
| 61 | + this.grafana.rows.hosts, |
| 62 | + this.grafana.rows.hostServlets, |
| 63 | + ], |
| 64 | + ), |
| 65 | + ), |
| 66 | + ) + root.applyCommon( |
| 67 | + vars.multiInstance + [ |
| 68 | + g.dashboard.variable.query.new('host') |
| 69 | + + g.dashboard.variable.custom.selectionOptions.withMulti(true) |
| 70 | + + g.dashboard.variable.query.queryTypes.withLabelValues(label='host', metric='tomcat_session_sessioncounter_total{%(queriesSelector)s}' % vars) |
| 71 | + + g.dashboard.variable.query.withDatasourceFromVariable(variable=vars.datasources.prometheus), |
| 72 | + |
| 73 | + g.dashboard.variable.query.new('context') |
| 74 | + + g.dashboard.variable.custom.selectionOptions.withMulti(true) |
| 75 | + + g.dashboard.variable.query.queryTypes.withLabelValues(label='context', metric='tomcat_session_sessioncounter_total{%(queriesSelector)s}' % vars) |
| 76 | + + g.dashboard.variable.query.withDatasourceFromVariable(variable=vars.datasources.prometheus), |
| 77 | + |
| 78 | + g.dashboard.variable.query.new('servlet') |
| 79 | + + g.dashboard.variable.custom.selectionOptions.withMulti(true) |
| 80 | + + g.dashboard.variable.query.queryTypes.withLabelValues(label='servlet', metric='tomcat_servlet_requestcount_total{%(queriesSelector)s}' % vars) |
| 81 | + + g.dashboard.variable.query.withDatasourceFromVariable(variable=vars.datasources.prometheus), |
| 82 | + ], |
| 83 | + uid + '_hosts', |
| 84 | + tags, |
| 85 | + links { apacheTomcatHosts:: {} }, |
| 86 | + annotations, |
| 87 | + timezone, |
| 88 | + refresh, |
| 89 | + period |
| 90 | + ), |
| 91 | + } + if this.config.enableLokiLogs then { |
| 92 | + 'apache-tomcat-logs.json': |
| 93 | + logslib.new( |
| 94 | + prefix + ' logs', |
| 95 | + datasourceName=this.grafana.variables.datasources.loki.name, |
| 96 | + datasourceRegex=this.grafana.variables.datasources.loki.regex, |
| 97 | + filterSelector=this.config.filteringSelector, |
| 98 | + labels=this.config.groupLabels + this.config.extraLogLabels, |
| 99 | + formatParser=null, |
| 100 | + showLogsVolume=this.config.showLogsVolume, |
| 101 | + ) |
| 102 | + { |
| 103 | + dashboards+: |
| 104 | + { |
| 105 | + logs+: |
| 106 | + root.applyCommon(super.logs.templating.list, uid=uid + '-logs', tags=tags, links=links { apacheTomcatLogs:: {} }, annotations=annotations, timezone=timezone, refresh=refresh, period=period), |
| 107 | + }, |
| 108 | + panels+: |
| 109 | + { |
| 110 | + logs+: |
| 111 | + g.panel.logs.options.withEnableLogDetails(true) |
| 112 | + + g.panel.logs.options.withShowTime(false) |
| 113 | + + g.panel.logs.options.withWrapLogMessage(false), |
| 114 | + }, |
| 115 | + variables+: { |
| 116 | + toArray+: [ |
| 117 | + this.grafana.variables.datasources.prometheus { hide: 2 }, |
| 118 | + ], |
| 119 | + }, |
| 120 | + }.dashboards.logs, |
| 121 | + }, |
| 122 | + |
| 123 | + applyCommon(vars, uid, tags, links, annotations, timezone, refresh, period): |
| 124 | + g.dashboard.withTags(tags) |
| 125 | + + g.dashboard.withUid(uid) |
| 126 | + + g.dashboard.withLinks(std.objectValues(links)) |
| 127 | + + g.dashboard.withTimezone(timezone) |
| 128 | + + g.dashboard.withRefresh(refresh) |
| 129 | + + g.dashboard.time.withFrom(period) |
| 130 | + + g.dashboard.withVariables(vars) |
| 131 | + + g.dashboard.withAnnotations(std.objectValues(annotations)), |
| 132 | +} |
0 commit comments