Skip to content

Latest commit

 

History

History
98 lines (85 loc) · 2.12 KB

monitoring-configuring-monitoring-for-an-application.adoc

File metadata and controls

98 lines (85 loc) · 2.12 KB

Configuring monitoring for an application

This procedure shows, on an example, how an application developer can deploy an application and configure monitoring for it.

Prerequisites
  • Make sure you configured the cluster for application monitoring. In this example, it is presumed that Prometheus and Alertmanager instances were installed in the default namespace.

Procedure
  1. Create a YAML file for your configuration. In this example, it is called deploy.yaml.

  2. Add configuration for deploying a sample application:

    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: example-app
      namespace: default
    spec:
      selector:
        matchLabels:
          app: example-app
      replicas: 1
      template:
        metadata:
          labels:
            app: example-app
        spec:
          containers:
          - name: example-app
            image: quay.io/brancz/prometheus-example-app:v0.2.0
            ports:
            - name: web
              containerPort: 8080
    ---
  3. Add configuration for exposing the sample application as a service:

    kind: Service
    apiVersion: v1
    metadata:
      name: example-app
      namespace: default
      labels:
        tier: frontend
    spec:
      selector:
        app: example-app
      ports:
      - name: web
        port: 8080
    ---
  4. Add configuration for creating a service monitor for the sample application. This will add your application as a target for monitoring:

    apiVersion: monitoring.coreos.com/v1
    kind: ServiceMonitor
    metadata:
      name: example-app
      namespace: default
      labels:
        k8s-app: example-app
    spec:
      selector:
        matchLabels:
          tier: frontend
      endpoints:
      - port: web
  5. Apply the configuration file to the cluster:

    $ oc apply -f deploy.yaml
  6. Forward a port to the Prometheus UI. In this example, port 9090 is used:

    $ oc port-forward -n openshift-user-workload-monitoring svc/prometheus-operated 9090
  7. Navigate to the Prometheus UI at http://localhost:9090/targets to see the sample application being monitored.