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

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Forkers

isabella232

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

Prometheus unable to scrape endpoints on cf app with routes associated

I was inspired by the go-app-with-metrics example and setup running the prometheus-operator colocated with cf-for-k8s and using an application deployed using the same prometheus.io annotations -- which, tangentially, personally I think this is very cool, powerful, and could open the door to other interesting possibilities for plumbing together CF and other systems. anyhow--

When there are no routes associated to the application and the app is just a regular process, prometheus is able to scrape the eirini-built pod against the port /metrics is exposed on:

with-no-route

When there are routes associated to it, prometheus appears unable to scrape the pod, svc, or generally any endpoint associated to it:

with-route-associated

I also haven't had success using different ports e.g. prometheus.io/port: 80:

with-route-on-80

... or using a ServiceMonitor or PodMonitor against the pod's associated svc, etc.

I haven't dug too deep into this, mostly trial and error; I'm assuming it has to do with how routing gets wired up via istio ("something-something proxy?"). Forgive me for not having more definitive explanation, I just wanted to get this issue out there before digging around too much more.

Is this to be expected for the time being? any success with having prometheus scrape pods which have cf routes associated to them? thanks all ๐Ÿ‘

EDIT this may have something to do with the pods prometheus leverages to perform scrapes requires istio sidecar injection. maybe. I'll just go poke around and find out.

Configuring GitBot is recommended

Pivotal provides the GitBot service to synchronize pull requests and/or issues made against public GitHub repos with Pivotal Tracker projects. This service does not track individual commits.

If you are a Pivotal employee, you can configure Gitbot to sync your GitHub repo to your Pivotal Tracker project with a pull request. An ask+rd@ ticket is the fastest way to get write access if you get a 404 to the config repo.

If you do not want have pull requests and/or issues copied from GitHub to Pivotal Tracker, you do not need to take any action.

If there are any questions, please reach out to [email protected].

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.