Prometheus Pushgateway Installation: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
 
(11 intermediate revisions by the same user not shown)
Line 8: Line 8:
==Pod and Services==
==Pod and Services==


<syntaxhighlight lang='yaml'>
<syntaxhighlight lang='bash'>
namespace=prom
cat <<EOF | kubectl -n ${namespace} apply -f -
apiVersion: v1
apiVersion: v1
kind: Pod
kind: Pod
Line 50: Line 52:
       port: 9091
       port: 9091
       targetPort: 9091
       targetPort: 9091
EOF
</syntaxhighlight>
</syntaxhighlight>
Test the deployment by accessing the console: {{External|http://localhost:9091}}
==ServiceMonitor==
==ServiceMonitor==
Expose it then as a Prometheus scraping [[Prometheus_Concepts#Target|target]] with a [[Prometheus_Operator_Concepts#ServiceMonitor_Resource|ServiceMonitor]]:
Expose it then as a Prometheus scraping [[Prometheus_Concepts#Target|target]] with a [[Prometheus_Operator_Concepts#ServiceMonitor_Resource|ServiceMonitor]]:
<syntaxhighlight lang='yaml'>
<syntaxhighlight lang='bash'>
namespace=prom
cat <<EOF | kubectl apply -n ${namespace} -f -
apiVersion: monitoring.coreos.com/v1
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
kind: ServiceMonitor
metadata:
metadata:
   name: pushgateway
   name: pushgateway
   namespace: prometheus
   namespace: ${namespace}
   labels:
   labels:
     release: prometheus
     release: prometheus
Line 65: Line 73:
   - port: 'pushgateway' # must match the label from Service declaration
   - port: 'pushgateway' # must match the label from Service declaration
     path: /metrics
     path: /metrics
     interval: 15s
     interval: 5s
   namespaceSelector:
   namespaceSelector:
     matchNames:
     matchNames:
     - prometheus
     - ${namespace}
   selector:
   selector:
     matchLabels:
     matchLabels:
       function: 'pushgateway-target'
       function: 'pushgateway-target'
EOF
</syntaxhighlight>
</syntaxhighlight>
Ensure that the pushgateway is correctly installed as target by inspecting Prometheus configuration at [[Prometheus_Concepts#Prometheus_Console|console]] (Status → Configuration). Also the console has a "Targets" section where the target should show up:
[[File: SuccessfulPrometheusTarget.png]]
Also see: {{Internal|Configuring_Prometheus_with_Prometheus_Operator#Add_a_Monitoring_Target|Configuring Prometheus with Prometheus Operator &#124; Add a Monitoring Target}}
Also see: {{Internal|Configuring_Prometheus_with_Prometheus_Operator#Add_a_Monitoring_Target|Configuring Prometheus with Prometheus Operator &#124; Add a Monitoring Target}}
=Test=
Publish a synthetic metric to pushgateway with a script similar to [https://github.com/ovidiuf/playground/blob/master/prometheus/pushgateway/publish-metric publish-metric] and ensure the metric can be found in the pushgateway console (http://localhost:9091) and with a Prometheus query.

Latest revision as of 06:31, 16 October 2020

Internal

Kubernetes Installation

Deploy the pod and associated services, and then configure it as a scraping target by deploying a ServiceMonitor. All descriptors are available in:

playground/prometheus/pushgateway

Pod and Services

namespace=prom
cat <<EOF | kubectl -n ${namespace} apply -f -
apiVersion: v1
kind: Pod
metadata:
  name: 'pushgateway'
  labels:
    function: 'pushgateway'
spec:
  containers:
  - name: 'pushgateway'
    image: prom/pushgateway
---
apiVersion: v1
kind: Service
metadata:
  name: 'pushgateway'
  labels:
    function: 'pushgateway-target'
spec:
  type: 'ClusterIP'
  selector:
    function: 'pushgateway'
  ports:
    # 'name' is important, it will be referred by ServiceMonitor configuration
    - name: 'pushgateway'
      protocol: 'TCP'
      port: 9091
      targetPort: 9091
---
apiVersion: v1
kind: Service
metadata:
  name: 'pushgateway-lb'
spec:
  type: 'LoadBalancer'
  selector:
    function: 'pushgateway'
  ports:
    - name: 'pushgateway'
      protocol: 'TCP'
      port: 9091
      targetPort: 9091
EOF

Test the deployment by accessing the console:

http://localhost:9091

ServiceMonitor

Expose it then as a Prometheus scraping target with a ServiceMonitor:

namespace=prom
cat <<EOF | kubectl apply -n ${namespace} -f -
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
  name: pushgateway
  namespace: ${namespace}
  labels:
    release: prometheus
spec:
  endpoints:
  - port: 'pushgateway' # must match the label from Service declaration
    path: /metrics
    interval: 5s
  namespaceSelector:
    matchNames:
    - ${namespace}
  selector:
    matchLabels:
      function: 'pushgateway-target'
EOF

Ensure that the pushgateway is correctly installed as target by inspecting Prometheus configuration at console (Status → Configuration). Also the console has a "Targets" section where the target should show up: SuccessfulPrometheusTarget.png

Also see:

Configuring Prometheus with Prometheus Operator | Add a Monitoring Target

Test

Publish a synthetic metric to pushgateway with a script similar to publish-metric and ensure the metric can be found in the pushgateway console (http://localhost:9091) and with a Prometheus query.