Giter Club home page Giter Club logo

matrics's Introduction

Metrics Scrapper

This is Prometheus Integration with rest service exposed using golang application. Golang application is deployed on kubernetes cluster and exposed as rest endpoint url.

There are two matrics exposed:

  1. Gauge (To count number of pods in cluster)
  2. Counter (Couting the total request hit count)

Pre-requisite:

Create RBAC rules to allow go application to get pod list on cluster level.

kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  name: pod-reader
rules:
  - verbs:
      - get
      - watch
      - list
    apiGroups:
      - ''
    resources:
      - pods

kind: ServiceAccount
apiVersion: v1
metadata:
  name: pod-service-account
  namespace: <namespace-name>

kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  name: pod-reader-global
subjects:
  - kind: ServiceAccount
    name: pod-service-account
    namespace: mukul-test
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: pod-reader

Build Metrics Go application, create a docker image and deploy on kubernetes

Clone code first:

git clone https://github.com/mukul4u2005/matrics.git
 

Build code:

GOOS=linux go build -o ./matrix-app .

Build docker image:

docker build -t matrix-app .

Tag image

docker tag matrix-app mpdocker2017/matrix-app:latest

Push image to Dockerhub

docker push mpdocker2017/matrix-app:latest   

Configure configmap and secret for Prometheus and metrics service

Create Secret for cluster api call, this secret is referenced in metrics deployment to configure as env. variables:

 kubectl create secret generic cluster-secret --from-literal=TOKEN=<token> --from-literal=API_URL=<api-url>

Create Prometheus config map for scrapper configuration (For prometheus deployment):

kubectl create configmap prome-config --from-file=<path>/prometheus.yml

Deploy Application on Kubernetes cluster and expose

Create deployment using yaml available in config folder:

For metrics service (Please change the image url):

kubectl apply -f metrics-deployment.yml

Create Prometheus deployment:

kubectl apply -f prom-deployment.yml

Access Prometheus using port-forward

kubectl port-forward pod-name 9090:9090

matrics's People

Contributors

mukul4u2005 avatar mukulpanwar 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.