diff --git a/jsonnet/custom-prometheus.jsonnet b/jsonnet/custom-prometheus.jsonnet new file mode 100644 index 0000000000..99b6caca00 --- /dev/null +++ b/jsonnet/custom-prometheus.jsonnet @@ -0,0 +1,40 @@ +{ + // Add Lens metric relabelings for custom prometheus instances installed with kube-prometheus + // https://github.com/lensapp/lens/blob/master/troubleshooting/custom-prometheus.md + nodeExporter+:: { + serviceMonitor+: { + spec+: { + endpoints: std.map(function(endpoint) + if endpoint.port == "https" then + endpoint { + relabelings+: [ + { + action: 'replace', + regex: '(.*)', + replacement: '$1', + sourceLabels: ['__meta_kubernetes_pod_node_name'], + targetLabel: 'kubernetes_node', + } + ], + } + else + endpoint, + super.endpoints + ), + }, + }, + }, + prometheus+:: { + serviceMonitorKubelet+: { + spec+: { + metricRelabelings+: [ + { + action: 'replace', + sourceLabels: ['node'], + targetLabel: 'instance', + }, + ], + }, + }, + }, +} diff --git a/troubleshooting/custom-prometheus.md b/troubleshooting/custom-prometheus.md index 098eb00b55..7f7ad4c169 100644 --- a/troubleshooting/custom-prometheus.md +++ b/troubleshooting/custom-prometheus.md @@ -4,6 +4,8 @@ When using custom prometheus with Lens app, Lens expects certain things for prom ## kube-prometheus +### Manual + 1. To see node metrics properly, please add ``` @@ -27,6 +29,39 @@ metricRelabelings: targetLabel: instance ``` +### Jsonnet + +The required label replacements are bundled in [jsonnet/custom-prometheus](../jsonnet/custom-prometheus.jsonnet). To install it copy the file or use +[Jsonnet Bundler](https://github.com/jsonnet-bundler/jsonnet-bundler). For jsonnet bundler add the following dependency to your `jsonnetfile.json`: + +``` +{ + "name": "lens", + "source": { + "git": { + "remote": "https://github.com/lensapp/lens", + "subdir": "jsonnet" + } + }, + "version": "master" +} +``` + +and run `jb install`. When the installation was successful include it into your definitions. Using the [example](https://github.com/coreos/kube-prometheus#compiling) +of kube-prometheus, e.g.: + +``` +local kp = + (import 'kube-prometheus/kube-prometheus.libsonnet') + + (import 'lens/custom-prometheus.jsonnet') + + { + _config+:: { + namespace: 'monitoring', + }, + }; +... +``` + ## Helm chart 1. To see cpu metrics properly, please set value of `server.global.scrape_timeout` less than 1 minute, for example