Git Product home page Git Product logo

cf-for-k8s-metric-examples's Introduction

cf-for-k8s-metric-examples

Examples for Metrics in cf-for-k8s

Setting up metrics in cf-for-k8s involves the following steps:

  1. From your app, expose metrics in the Prometheus exposition format
  2. In your app's manifest.yml, define the appropriate Prometheus annotations

This repo provides examples of applications and the appropriate annotations.

Deploying an app with metrics

Requirements
Deploying the app

Change into your app's root directory and cf push

Example for golang using cf CLI:

  1. cd go-app-with-metrics
  2. cf push
Verifying it emits metrics

By defining the Prometheus annotations in the manifest.yml, Prometheus will automatically pick up your app's metrics endpoint.

If you have kubectl access on your cluster, you can verify that your app is emitting metrics by port-forwarding:

export POD_NAME="$(k get pods -n cf-workloads | grep go-app-with-metrics | awk 'NR==1{print $1}')"
export PROM_PORT="YOUR_PORT_HERE"

kubectl port-forward -n cf-workloads $POD_NAME $PROM_PORT

curl localhost:$PROM_PORT/metrics

Deploying Prometheus Server

In order for prometheus to sucessfully scrape pods in a cf-for-k8s cluster, it currently needs the following:

  1. Be deployed in namespace that has the label "istio-injection=enabled". This injects istio sidecars onto prometheus's pods. The recommended namespace is cf-system.
  2. Have a network policy in place that allows prometheus to scrape your app's pod.
  3. Have the necessary certs available in prometheus's istio sidecar.

Because of the complexity of these requirements, we recommend using cf-k8s-prometheus.

To set up port forwarding, run the following commands:

  export POD_NAME=$(kubectl get pods --namespace cf-system -l "metrics=prometheus,component=server" -o jsonpath="{.items[0].metadata.name}")
  kubectl --namespace cf-system port-forward $POD_NAME 9090

After setting up the port forwarding, access the Prometheus web UI by going to localhost:9090

Default Metrics Availability

Metrics should be included for all Prometheus nodes, the API node, and any pods annotated with Prometheus scrape configurations:

  • In a Cloud Foundry manifest:
    ---
    applications:
    - name: go-app-with-metrics
      metadata:
        annotations:
          prometheus.io/scrape: "true"
          prometheus.io/port: "2112"
          prometheus.io/path: "/metrics"
    
  • In a Kubernetes pod manifest:
    spec:
      template:
        metadata:
          annotations:
            prometheus.io/scrape: "true"
            prometheus.io/port: "2112"
            prometheus.io/path: "/metrics"
    

Have a question or feedback, reach out to us

Reach out to us in the Cloud Foundry Slack channel #logging-and-metrics. To request a response during Mountain Time business hours, tag your message with @interrupt.

cf-for-k8s-metric-examples's People

Contributors

christopherclark avatar dtimm avatar heycait avatar kkburr avatar louis-brann avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.