Skip to content

Instantly share code, notes, and snippets.

@christophlehmann
Last active April 29, 2024 11:44
Show Gist options
  • Save christophlehmann/b1bbf2821a876c7f91d8eec3b6788f24 to your computer and use it in GitHub Desktop.
Save christophlehmann/b1bbf2821a876c7f91d8eec3b6788f24 to your computer and use it in GitHub Desktop.
Example: Monitoring external server with Prometheus Operator
# First install prometheus-operator:
#
# helm install coreos/prometheus-operator --name prometheus-operator
#
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
name: node-exporter
# Namespace of prometheus operator
namespace: monitoring
labels:
prometheus: mon
spec:
namespaceSelector:
matchNames:
- server-monitoring
selector:
matchLabels:
k8s-app: node-exporter
endpoints:
- port: metrics
interval: 10s
---
apiVersion: v1
kind: Service
metadata:
name: name-your-server-com
namespace: server
labels:
k8s-app: node-exporter
spec:
type: ExternalName
externalName: name.your-server.com
clusterIP: ""
# Maybe not relevant
ports:
- name: metrics
port: 9100
protocol: TCP
targetPort: 9100
---
apiVersion: v1
kind: Endpoints
metadata:
# Name must match service name
name: name-your-server-com
namespace: server
labels:
k8s-app: node-exporter
subsets:
- addresses:
- ip: 192.168.99.12
ports:
- name: metrics
port: 9100
protocol: TCP
@zffocussss
Copy link

zffocussss commented Jun 29, 2022

@vladComan0
Copy link

@zffocussss did you find a solution for that?

@arslanbekov
Copy link

@zffocussss @vladComan0 if you use prometheus-operator, you can use additionalScrapes:

additionalScrapeConfigs:
  - job_name: 'external_service'
    basic_auth: # if needed
      username: 'login'
      password: 'password'
    scheme: https
    static_configs:
    - targets: ['my-public-domain.com']

  - job_name: 'external_service_second'
    basic_auth: # if needed
      username: 'login'
      password: 'password'
    scheme: https
    metrics_path: "/metrics/second" # with custom metric path
    static_configs:
    - targets: ['my-public-domain.com']

@kural82
Copy link

kural82 commented Aug 9, 2023

Hi,
Do we still need a service monitoring to monitor external service after adding this additional scraperConfigs?

@spanagiot
Copy link

No, you can either use the serviceMonitor with the Service and the Endpoint or add the configuration in the additionalScrapeConfigs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment