How to monitor external service in prometheus-operator How to monitor external service in prometheus-operator kubernetes kubernetes

How to monitor external service in prometheus-operator


Ok, I found out that service should be in the same namespace as service monitor and endpoint, after that prometheus started to see some metrics from cassandra.


To be strict only "Endpoints" and "Service" should be in the same namespace.Additionally "Endpoints" and "Service" should have the same name as Lucas mentioned it before.

ServiceMonitor can be placed anywhere, it finds and scrapes SVC/Endpoint inside defined namespaces (namespaceSelector->matchNames) and matching all labels (selector->matchLabels):

    spec:  selector:    matchLabels:      app: cassandra-metrics80      release: prometheus-operator  namespaceSelector:    matchNames:    - my-namespace

Furthermore now there is much more easier method to define additional scraping:https://github.com/prometheus-operator/prometheus-operator/blob/master/Documentation/additional-scrape-config.mdThe only drawback for the second one is that it requires pod restart after the change. Configuration based on Endpoint/Service/ServiceMonitor seem to be discovered and applied automatically.