Skip to content

Commit 88231c4

Browse files
authored
feat: CouchDB K8s Labels (#1162)
* add kubernetes compatible labels for couchdb * fix variable casing * fix linter whitespace
1 parent d34855f commit 88231c4

File tree

3 files changed

+159
-131
lines changed

3 files changed

+159
-131
lines changed

apache-couchdb-mixin/config.libsonnet

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
{
22
_config+:: {
3+
enableMultiCluster: false,
4+
couchDBSelector: if self.enableMultiCluster then 'job=~"$job", cluster=~"$cluster"' else 'job=~"$job"',
5+
multiClusterSelector: 'job=~"$job"',
6+
37
dashboardTags: ['apache-couchdb-mixin'],
48
dashboardPeriod: 'now-1h',
59
dashboardTimezone: 'default',

apache-couchdb-mixin/dashboards/couchdb-nodes.libsonnet

Lines changed: 67 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ local dashboardUid = 'couchdb-nodes';
88

99
local promDatasourceName = 'prometheus_datasource';
1010
local lokiDatasourceName = 'loki_datasource';
11-
local matcher = 'job=~"$job", couchdb_cluster=~"$couchdb_cluster", instance=~"$instance"';
11+
local getMatcher(cfg) = '%(couchDBSelector)s, couchdb_cluster=~"$couchdb_cluster", instance=~"$instance"' % cfg;
1212

1313
local promDatasource = {
1414
uid: '${%s}' % promDatasourceName,
@@ -18,11 +18,11 @@ local lokiDatasource = {
1818
uid: '${%s}' % lokiDatasourceName,
1919
};
2020

21-
local erlangMemoryUsagePanel = {
21+
local erlangMemoryUsagePanel(cfg) = {
2222
datasource: promDatasource,
2323
targets: [
2424
prometheus.target(
25-
'couchdb_erlang_memory_bytes{' + matcher + ', memory_type="total"}',
25+
'couchdb_erlang_memory_bytes{' + getMatcher(cfg) + ', memory_type="total"}',
2626
datasource=promDatasource,
2727
legendFormat='{{instance}}',
2828
),
@@ -97,11 +97,11 @@ local erlangMemoryUsagePanel = {
9797
},
9898
};
9999

100-
local openOSFilesPanel = {
100+
local openOSFilesPanel(cfg) = {
101101
datasource: promDatasource,
102102
targets: [
103103
prometheus.target(
104-
'couchdb_open_os_files_total{' + matcher + '}',
104+
'couchdb_open_os_files_total{' + getMatcher(cfg) + '}',
105105
datasource=promDatasource,
106106
legendFormat='{{instance}}',
107107
),
@@ -172,11 +172,11 @@ local openOSFilesPanel = {
172172
},
173173
};
174174

175-
local openDatabasesPanel = {
175+
local openDatabasesPanel(cfg) = {
176176
datasource: promDatasource,
177177
targets: [
178178
prometheus.target(
179-
'couchdb_open_databases_total{' + matcher + '}',
179+
'couchdb_open_databases_total{' + getMatcher(cfg) + '}',
180180
datasource=promDatasource,
181181
legendFormat='{{instance}}',
182182
),
@@ -250,11 +250,11 @@ local openDatabasesPanel = {
250250
},
251251
};
252252

253-
local databaseWritesPanel = {
253+
local databaseWritesPanel(cfg) = {
254254
datasource: promDatasource,
255255
targets: [
256256
prometheus.target(
257-
'rate(couchdb_database_writes_total{' + matcher + '}[$__rate_interval])',
257+
'rate(couchdb_database_writes_total{' + getMatcher(cfg) + '}[$__rate_interval])',
258258
datasource=promDatasource,
259259
legendFormat='{{instance}}',
260260
),
@@ -329,11 +329,11 @@ local databaseWritesPanel = {
329329
},
330330
};
331331

332-
local databaseReadsPanel = {
332+
local databaseReadsPanel(cfg) = {
333333
datasource: promDatasource,
334334
targets: [
335335
prometheus.target(
336-
'rate(couchdb_database_reads_total{' + matcher + '}[$__rate_interval])',
336+
'rate(couchdb_database_reads_total{' + getMatcher(cfg) + '}[$__rate_interval])',
337337
datasource=promDatasource,
338338
legendFormat='{{instance}}',
339339
),
@@ -408,11 +408,11 @@ local databaseReadsPanel = {
408408
},
409409
};
410410

411-
local viewReadsPanel = {
411+
local viewReadsPanel(cfg) = {
412412
datasource: promDatasource,
413413
targets: [
414414
prometheus.target(
415-
'rate(couchdb_httpd_view_reads_total{' + matcher + '}[$__rate_interval])',
415+
'rate(couchdb_httpd_view_reads_total{' + getMatcher(cfg) + '}[$__rate_interval])',
416416
datasource=promDatasource,
417417
legendFormat='{{instance}}',
418418
),
@@ -487,11 +487,11 @@ local viewReadsPanel = {
487487
},
488488
};
489489

490-
local viewTimeoutsPanel = {
490+
local viewTimeoutsPanel(cfg) = {
491491
datasource: promDatasource,
492492
targets: [
493493
prometheus.target(
494-
'rate(couchdb_httpd_view_timeouts_total{' + matcher + '}[$__rate_interval])',
494+
'rate(couchdb_httpd_view_timeouts_total{' + getMatcher(cfg) + '}[$__rate_interval])',
495495
datasource=promDatasource,
496496
legendFormat='{{instance}}',
497497
),
@@ -566,11 +566,11 @@ local viewTimeoutsPanel = {
566566
},
567567
};
568568

569-
local temporaryViewReadsPanel = {
569+
local temporaryViewReadsPanel(cfg) = {
570570
datasource: promDatasource,
571571
targets: [
572572
prometheus.target(
573-
'rate(couchdb_httpd_temporary_view_reads_total{' + matcher + '}[$__rate_interval])',
573+
'rate(couchdb_httpd_temporary_view_reads_total{' + getMatcher(cfg) + '}[$__rate_interval])',
574574
datasource=promDatasource,
575575
legendFormat='{{instance}}',
576576
),
@@ -653,11 +653,11 @@ local requestsRow = {
653653
collapsed: false,
654654
};
655655

656-
local requestMethodsPanel = {
656+
local requestMethodsPanel(cfg) = {
657657
datasource: promDatasource,
658658
targets: [
659659
prometheus.target(
660-
'rate(couchdb_httpd_request_methods{' + matcher + '}[$__rate_interval]) != 0',
660+
'rate(couchdb_httpd_request_methods{' + getMatcher(cfg) + '}[$__rate_interval]) != 0',
661661
datasource=promDatasource,
662662
legendFormat='{{instance}} - {{method}}',
663663
),
@@ -732,26 +732,26 @@ local requestMethodsPanel = {
732732
},
733733
};
734734

735-
local requestLatencyPanel = {
735+
local requestLatencyPanel(cfg) = {
736736
datasource: promDatasource,
737737
targets: [
738738
prometheus.target(
739-
'couchdb_request_time_seconds{' + matcher + ', quantile="0.5"}',
739+
'couchdb_request_time_seconds{' + getMatcher(cfg) + ', quantile="0.5"}',
740740
datasource=promDatasource,
741741
legendFormat='{{instance}} - p50',
742742
),
743743
prometheus.target(
744-
'couchdb_request_time_seconds{' + matcher + ', quantile="0.75"}',
744+
'couchdb_request_time_seconds{' + getMatcher(cfg) + ', quantile="0.75"}',
745745
datasource=promDatasource,
746746
legendFormat='{{instance}} - p75',
747747
),
748748
prometheus.target(
749-
'couchdb_request_time_seconds{' + matcher + ', quantile="0.95"}',
749+
'couchdb_request_time_seconds{' + getMatcher(cfg) + ', quantile="0.95"}',
750750
datasource=promDatasource,
751751
legendFormat='{{instance}} - p95',
752752
),
753753
prometheus.target(
754-
'couchdb_request_time_seconds{' + matcher + ', quantile="0.99"}',
754+
'couchdb_request_time_seconds{' + getMatcher(cfg) + ', quantile="0.99"}',
755755
datasource=promDatasource,
756756
legendFormat='{{instance}} - p99',
757757
),
@@ -826,11 +826,11 @@ local requestLatencyPanel = {
826826
},
827827
};
828828

829-
local bulkRequestsPanel = {
829+
local bulkRequestsPanel(cfg) = {
830830
datasource: promDatasource,
831831
targets: [
832832
prometheus.target(
833-
'rate(couchdb_httpd_bulk_requests_total{' + matcher + '}[$__rate_interval])',
833+
'rate(couchdb_httpd_bulk_requests_total{' + getMatcher(cfg) + '}[$__rate_interval])',
834834
datasource=promDatasource,
835835
legendFormat='{{instance}}',
836836
),
@@ -905,29 +905,29 @@ local bulkRequestsPanel = {
905905
},
906906
};
907907

908-
local responseStatusOverviewPanel = {
908+
local responseStatusOverviewPanel(cfg) = {
909909
datasource: promDatasource,
910910
targets: [
911911
prometheus.target(
912-
'sum by(instance, couchdb_cluster) (increase(couchdb_httpd_status_codes{' + matcher + ', code=~"2.*"}[$__interval:])) != 0',
912+
'sum by(instance, couchdb_cluster) (increase(couchdb_httpd_status_codes{' + getMatcher(cfg) + ', code=~"2.*"}[$__interval:])) != 0',
913913
datasource=promDatasource,
914914
legendFormat='{{instance}} - 2xx',
915915
interval='1m',
916916
),
917917
prometheus.target(
918-
'sum by(instance, couchdb_cluster) (increase(couchdb_httpd_status_codes{' + matcher + ', code=~"3.*"}[$__interval:])) != 0',
918+
'sum by(instance, couchdb_cluster) (increase(couchdb_httpd_status_codes{' + getMatcher(cfg) + ', code=~"3.*"}[$__interval:])) != 0',
919919
datasource=promDatasource,
920920
legendFormat='{{instance}} - 3xx',
921921
interval='1m',
922922
),
923923
prometheus.target(
924-
'sum by(instance, couchdb_cluster) (increase(couchdb_httpd_status_codes{' + matcher + ', code=~"4.*"}[$__interval:])) != 0',
924+
'sum by(instance, couchdb_cluster) (increase(couchdb_httpd_status_codes{' + getMatcher(cfg) + ', code=~"4.*"}[$__interval:])) != 0',
925925
datasource=promDatasource,
926926
legendFormat='{{instance}} - 4xx',
927927
interval='1m',
928928
),
929929
prometheus.target(
930-
'sum by(instance, couchdb_cluster) (increase(couchdb_httpd_status_codes{' + matcher + ', code=~"5.*"}[$__interval:])) != 0',
930+
'sum by(instance, couchdb_cluster) (increase(couchdb_httpd_status_codes{' + getMatcher(cfg) + ', code=~"5.*"}[$__interval:])) != 0',
931931
datasource=promDatasource,
932932
legendFormat='{{instance}} - 5xx',
933933
interval='1m',
@@ -973,11 +973,11 @@ local responseStatusOverviewPanel = {
973973
},
974974
};
975975

976-
local goodResponseStatusesPanel = {
976+
local goodResponseStatusesPanel(cfg) = {
977977
datasource: promDatasource,
978978
targets: [
979979
prometheus.target(
980-
'rate(couchdb_httpd_status_codes{' + matcher + ', code=~"[23].*"}[$__rate_interval]) != 0',
980+
'rate(couchdb_httpd_status_codes{' + getMatcher(cfg) + ', code=~"[23].*"}[$__rate_interval]) != 0',
981981
datasource=promDatasource,
982982
legendFormat='{{instance}} - {{code}}',
983983
),
@@ -1052,11 +1052,11 @@ local goodResponseStatusesPanel = {
10521052
},
10531053
};
10541054

1055-
local errorResponseStatusesPanel = {
1055+
local errorResponseStatusesPanel(cfg) = {
10561056
datasource: promDatasource,
10571057
targets: [
10581058
prometheus.target(
1059-
'rate(couchdb_httpd_status_codes{' + matcher + ', code=~"[45].*"}[$__rate_interval]) != 0',
1059+
'rate(couchdb_httpd_status_codes{' + getMatcher(cfg) + ', code=~"[45].*"}[$__rate_interval]) != 0',
10601060
datasource=promDatasource,
10611061
legendFormat='{{instance}} - {{code}}',
10621062
),
@@ -1139,11 +1139,11 @@ local logsRow = {
11391139
collapsed: false,
11401140
};
11411141

1142-
local logTypesPanel = {
1142+
local logTypesPanel(cfg) = {
11431143
datasource: promDatasource,
11441144
targets: [
11451145
prometheus.target(
1146-
'increase(couchdb_couch_log_requests_total{' + matcher + ', level=~"$log_level"}[$__interval:]) != 0',
1146+
'increase(couchdb_couch_log_requests_total{' + getMatcher(cfg) + ', level=~"$log_level"}[$__interval:]) != 0',
11471147
datasource=promDatasource,
11481148
legendFormat='{{instance}} - {{level}}',
11491149
interval='1m',
@@ -1219,13 +1219,13 @@ local logTypesPanel = {
12191219
},
12201220
};
12211221

1222-
local systemLogsPanel = {
1222+
local systemLogsPanel(cfg) = {
12231223
datasource: lokiDatasource,
12241224
targets: [
12251225
{
12261226
datasource: lokiDatasource,
12271227
editorMode: 'code',
1228-
expr: '{' + matcher + ', filename="/var/log/couchdb/couchdb.log"} |~ "$log_level"',
1228+
expr: '{' + getMatcher(cfg) + ', filename="/var/log/couchdb/couchdb.log"} |~ "$log_level"',
12291229
queryType: 'range',
12301230
refId: 'A',
12311231
},
@@ -1296,6 +1296,18 @@ local systemLogsPanel = {
12961296
allValues='',
12971297
sort=0
12981298
),
1299+
template.new(
1300+
'cluster',
1301+
promDatasource,
1302+
'label_values(couchdb_couch_replicator_cluster_is_stable{%(multiClusterSelector)s}, cluster)' % $._config,
1303+
label='Cluster',
1304+
refresh=1,
1305+
includeAll=true,
1306+
multi=true,
1307+
allValues='',
1308+
hide=if $._config.enableMultiCluster then '' else 'variable' % $._config,
1309+
sort=0
1310+
),
12991311
template.new(
13001312
'couchdb_cluster',
13011313
promDatasource,
@@ -1335,26 +1347,26 @@ local systemLogsPanel = {
13351347
.addPanels(
13361348
std.flattenArrays([
13371349
[
1338-
erlangMemoryUsagePanel { gridPos: { h: 6, w: 8, x: 0, y: 0 } },
1339-
openOSFilesPanel { gridPos: { h: 6, w: 8, x: 8, y: 0 } },
1340-
openDatabasesPanel { gridPos: { h: 6, w: 8, x: 16, y: 0 } },
1341-
databaseWritesPanel { gridPos: { h: 6, w: 12, x: 0, y: 6 } },
1342-
databaseReadsPanel { gridPos: { h: 6, w: 12, x: 12, y: 6 } },
1343-
viewReadsPanel { gridPos: { h: 6, w: 8, x: 0, y: 12 } },
1344-
viewTimeoutsPanel { gridPos: { h: 6, w: 8, x: 8, y: 12 } },
1345-
temporaryViewReadsPanel { gridPos: { h: 6, w: 8, x: 16, y: 12 } },
1350+
erlangMemoryUsagePanel($._config) { gridPos: { h: 6, w: 8, x: 0, y: 0 } },
1351+
openOSFilesPanel($._config) { gridPos: { h: 6, w: 8, x: 8, y: 0 } },
1352+
openDatabasesPanel($._config) { gridPos: { h: 6, w: 8, x: 16, y: 0 } },
1353+
databaseWritesPanel($._config) { gridPos: { h: 6, w: 12, x: 0, y: 6 } },
1354+
databaseReadsPanel($._config) { gridPos: { h: 6, w: 12, x: 12, y: 6 } },
1355+
viewReadsPanel($._config) { gridPos: { h: 6, w: 8, x: 0, y: 12 } },
1356+
viewTimeoutsPanel($._config) { gridPos: { h: 6, w: 8, x: 8, y: 12 } },
1357+
temporaryViewReadsPanel($._config) { gridPos: { h: 6, w: 8, x: 16, y: 12 } },
13461358
requestsRow { gridPos: { h: 1, w: 24, x: 0, y: 18 } },
1347-
bulkRequestsPanel { gridPos: { h: 6, w: 12, x: 0, y: 19 } },
1348-
requestLatencyPanel { gridPos: { h: 6, w: 12, x: 12, y: 19 } },
1349-
requestMethodsPanel { gridPos: { h: 6, w: 12, x: 0, y: 25 } },
1350-
responseStatusOverviewPanel { gridPos: { h: 6, w: 12, x: 12, y: 25 } },
1351-
goodResponseStatusesPanel { gridPos: { h: 6, w: 12, x: 0, y: 31 } },
1352-
errorResponseStatusesPanel { gridPos: { h: 6, w: 12, x: 12, y: 31 } },
1359+
bulkRequestsPanel($._config) { gridPos: { h: 6, w: 12, x: 0, y: 19 } },
1360+
requestLatencyPanel($._config) { gridPos: { h: 6, w: 12, x: 12, y: 19 } },
1361+
requestMethodsPanel($._config) { gridPos: { h: 6, w: 12, x: 0, y: 25 } },
1362+
responseStatusOverviewPanel($._config) { gridPos: { h: 6, w: 12, x: 12, y: 25 } },
1363+
goodResponseStatusesPanel($._config) { gridPos: { h: 6, w: 12, x: 0, y: 31 } },
1364+
errorResponseStatusesPanel($._config) { gridPos: { h: 6, w: 12, x: 12, y: 31 } },
13531365
logsRow { gridPos: { h: 1, w: 24, x: 0, y: 37 } },
1354-
logTypesPanel { gridPos: { h: 6, w: 24, x: 0, y: 38 } },
1366+
logTypesPanel($._config) { gridPos: { h: 6, w: 24, x: 0, y: 38 } },
13551367
],
13561368
if $._config.enableLokiLogs then [
1357-
systemLogsPanel { gridPos: { h: 6, w: 24, x: 0, y: 44 } },
1369+
systemLogsPanel($._config) { gridPos: { h: 6, w: 24, x: 0, y: 44 } },
13581370
] else [],
13591371
[
13601372
],

0 commit comments

Comments
 (0)