From ad2b941e77082a36606baab95682c05ece079036 Mon Sep 17 00:00:00 2001
From: "Rafael T. C. Soares (A.K.A Tuelho)"
 <rafaeltuelho@users.noreply.github.com>
Date: Wed, 5 Jun 2019 10:56:29 -0300
Subject: [PATCH] adding a note about ServiceMonitor definition

In the **Adding additional namespaces to monitor** section I appended a note showing the need for ServiceMonitor when adding additional namespaces...

see: https://github.com/coreos/prometheus-operator/issues/2557#issuecomment-498996568
---
 README.md | 42 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 42 insertions(+)

diff --git a/README.md b/README.md
index 5b87e00e..6b29e4bf 100644
--- a/README.md
+++ b/README.md
@@ -543,6 +543,48 @@ local kp = (import 'kube-prometheus/kube-prometheus.libsonnet') + {
 { ['grafana-' + name]: kp.grafana[name] for name in std.objectFields(kp.grafana) }
 ```
 
+#### Defining the ServiceMonitor for each addional Namespace
+
+In order to Prometheus be able to discovery and scrap services inside the additional namespaces specified in previous step you need to define a ServiceMonitor resource.
+
+You can define ServiceMonitor resources in your `jsonnet` spec. See the snippet bellow:
+
+```
+local kp = (import 'kube-prometheus/kube-prometheus.libsonnet') + {
+  _config+:: {
+    namespace: 'monitoring',
+
+    prometheus+:: {
+      namespaces+: ['my-namespace', 'my-second-namespace'],
+
+      serviceMonitorKubeScheduler: {
+        apiVersion: 'monitoring.coreos.com/v1',
+        kind: 'ServiceMonitor',
+        metadata: {
+            name: 'my-servicemonitor',
+            namespace: 'my-namespace',
+        },
+        spec: {
+            jobLabel: 'app',
+            endpoints: [
+            {
+                port: 'http-metrics',
+            },
+            ],
+            selector: {
+                matchLabels: {
+                    'app': 'myapp',
+                },
+            },
+        },
+      },      
+    },
+  },
+};
+```
+
+> NOTE: make sure your service resources has the right labels (eg. `'app': 'myapp'`) applied. Prometheus use kubernetes labels to discovery resources inside the namespaces.
+
 ### Static etcd configuration
 
 In order to configure a static etcd cluster to scrape there is a simple [kube-prometheus-static-etcd.libsonnet](jsonnet/kube-prometheus/kube-prometheus-static-etcd.libsonnet) mixin prepared - see [etcd.jsonnet](examples/etcd.jsonnet) for an example of how to use that mixin, and [Monitoring external etcd](docs/monitoring-external-etcd.md) for more information.
-- 
GitLab