Configuring Prometheus with Prometheus Operator: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
Line 7: Line 7:


=Add a Target=
=Add a Target=
To add a monitoring [[Prometheus_Concepts#Target|target]], deploy a [[Prometheus_Operator_Concepts#ServiceMonitor_Resource|ServiceMonitor]] custom resource.
To add a monitoring [[Prometheus_Concepts#Target|target]], deploy a [[Prometheus_Operator_Concepts#ServiceMonitor_Resource|ServiceMonitor]] custom resource:
<syntaxhighlight lang='bash'>
namespace="prometheus"
cat <<EOF | kubectl -n ${namespace} apply -f -
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
  name: pushgateway-example
  namespace: ${namespace}
  labels:
    release: prometheus
spec:
  endpoints:
  - path: /metrics
    port: "9091"
  namespaceSelector:
    matchNames:
    - ${namespace}
  selector:
    matchLabels:
      function: pushgateway
EOF
</syntaxhighlight>

Revision as of 22:04, 14 October 2020

External

Internal

Overview

Add a Target

To add a monitoring target, deploy a ServiceMonitor custom resource:

namespace="prometheus"
cat <<EOF | kubectl -n ${namespace} apply -f -
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
  name: pushgateway-example
  namespace: ${namespace}
  labels:
    release: prometheus
spec:
  endpoints:
  - path: /metrics
    port: "9091"
  namespaceSelector:
    matchNames:
    - ${namespace}
  selector:
    matchLabels:
      function: pushgateway
EOF