Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Logs dashboard #866

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,11 @@ Running `jsonnet -S lib/kubernetes_customised_alerts.jsonnet` will build the ale

Same result can be achieved by modyfying the existing `config.libsonnet` with the content of `kubernetes_mixin_override.libsonnet`.

### Loki logs dashboard

Pod logs dashboard with loki datasource can be enabled/disabled with
`enableLokiLogs` option.

## Background

### Alert Severities
Expand Down
9 changes: 9 additions & 0 deletions config.libsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
'nodes.json': 'kcb9C2QDe4IYcjiTOmYyfhsImuzxRcvwWC3YLJPS',
'persistentvolumesusage.json': 'AhCeikee0xoa6faec0Weep2nee6shaiquigahw8b',
'pods.json': 'AMK9hS0rSbSz7cKjPHcOtk6CGHFjhSHwhbQ3sedK',
'pods-logs.json': 'add79da23c2c11eebe560242ac120002',
'statefulset.json': 'dPiBt0FRG5BNYo0XJ4L0Meoc7DWs9eL40c1CRc1g',
'k8s-resources-windows-cluster.json': '4d08557fd9391b100730f2494bccac68',
'k8s-resources-windows-namespace.json': '490b402361724ab1d4c45666c1fa9b6f',
Expand Down Expand Up @@ -109,5 +110,13 @@

// Default timeout value for k8s Jobs. The jobs which are active beyond this duration would trigger KubeJobNotCompleted alert.
kubeJobTimeoutDuration: 12 * 60 * 60,

// Enable pod logs dashboard (loki datasource)
enableLokiLogs: false,

// Application label (used in logs selector)
applicationLabel: 'app',
logsVolumeGroupBy: self.applicationLabel,
showLogsVolume: true,
},
}
3 changes: 2 additions & 1 deletion dashboards/dashboards.libsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@
(import 'scheduler.libsonnet') +
(import 'proxy.libsonnet') +
(import 'kubelet.libsonnet') +
(import 'defaults.libsonnet')
(import 'defaults.libsonnet') +
(import 'pod-logs.libsonnet')
46 changes: 46 additions & 0 deletions dashboards/pod-logs.libsonnet
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// add logs
local g = import 'github.com/grafana/grafonnet/gen/grafonnet-v10.0.0/main.libsonnet';
local logsDashboard = import 'github.com/grafana/jsonnet-libs/logs-lib/logs/main.libsonnet';

{
local filterSelector = 'namespace!=""',
local labels = [$._config.clusterLabel, $._config.namespaceLabel, $._config.applicationLabel, $._config.podLabel, 'container'],

local formatParser = null,
local logsDash =
logsDashboard.new(
'%s Pod Logs' % $._config.grafanaK8s.dashboardNamePrefix,
datasourceRegex='',
filterSelector=filterSelector,
labels=labels,
formatParser=formatParser,
showLogsVolume=$._config.showLogsVolume,
logsVolumeGroupBy=$._config.logsVolumeGroupBy,
extraFilters=|||
| label_format timestamp="{{__timestamp__}}"
| line_format `{{ if eq "[[pod]]" ".*" }}{{.pod | trunc 20}}:{{else}}{{.container}}:{{end}} {{__line__}}`
|||
)

{
// overwrite dashboard 'log'
dashboards+:
{
logs+: g.dashboard.withLinksMixin($.grafanaDashboards['k8s-resources-cluster.json'].links)
+ g.dashboard.withUid($._config.grafanaDashboardIDs['pods-logs.json'])
+ g.dashboard.withTags($._config.grafanaK8s.dashboardTags)
+ g.dashboard.withRefresh($._config.grafanaK8s.refresh),
},
// overwrite panel 'log'
panels+:
{
logs+: g.panel.logs.options.withEnableLogDetails(true)
+ g.panel.logs.options.withShowTime(false),
},
},

grafanaDashboards+:: if $._config.enableLokiLogs then {
'pods-logs':
logsDash.dashboards.logs,
} else {},
}
11 changes: 10 additions & 1 deletion jsonnetfile.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,16 @@
}
},
"version": "master"
},
{
"source": {
"git": {
"remote": "https://github.com/grafana/jsonnet-libs.git",
"subdir": "logs-lib"
}
},
"version": "master"
}
],
"legacyImports": false
"legacyImports": true
}
Loading