Code Monkey home page Code Monkey logo

dark's Introduction

DARK

codecov

Dashboards As Resources in Kubernetes.

DARK provides a way to define and deploy Grafana dashboards via Kubernetes, next to the services they monitor.

If you are looking for a way to version your dashboards and deploy them across all environments, like you would do with your services, then this project is meant for you.

Design goals

  • full description of dashboards via YAML
  • compatibility with kubectl
  • seamless integration with Grafana
  • delegate YAML decoding and dashboard generation to Grabana

Setup

Note: review these manifests to ensure that they fit your cluster's configuration.

Setup the CRD:

kubectl apply -f k8s/crd.yaml

Add the ClusterRole and ClusterRoleBinding to grant ServiceAccount API access to the new GrafanaDashboard resource:

kubectl apply -f k8s/cluster-role.yaml

Create a secret to store Grafana's API token (with editor access level):

kubectl create secret generic dark-tokens --from-literal=grafana=TOKEN_HERE

Deploy DARK's controller:

kubectl apply -f k8s/deployment.yaml

Dashboard definition

Define a dashboard:

# k8s/example-dashboard.yml
apiVersion: k8s.kevingomez.fr/v1
kind: GrafanaDashboard

metadata:
  # must be unique across dashboards
  name: example-dashboard

folder: "Awesome folder"
spec:
  title: Awesome dashboard

  shared_crosshair: true
  tags: [generated, yaml]
  auto_refresh: 10s

  variables:
    - interval:
        name: interval
        label: interval
        default: 1m
        values: [30s, 1m, 5m, 10m, 30m, 1h, 6h, 12h]

  rows:
    - name: Prometheus
      panels:
        - graph:
            title: HTTP Rate
            height: 400px
            datasource: prometheus-default
            targets:
              - prometheus:
                  query: "rate(promhttp_metric_handler_requests_total[$interval])"
                  legend: "{{handler}} - {{ code }}"
        - graph:
            title: Heap allocations
            height: 400px
            datasource: prometheus-default
            targets:
              - prometheus:
                  query: "go_memstats_heap_alloc_bytes"
                  legend: "{{job}}"

For more information on the YAML schema used to describe dashboards, see Grabana.

Apply the configuration:

kubectl apply -f k8s/example-dashboard.yml

And verify that the dashboard was created:

kubectl get dashboards
kubectl get events | grep dark

Converting Grafana JSON dashboard to YAML

To ease the transition from existing, raw Grafana dashboards to DARK, a converter is provided. It takes the path to a JSON dashboard and a path for the destination YAML file.

docker run --rm -it -v $(pwd):/workspace kphoen/dark-converter:latest convert-yaml -i dashboard.json -o converted-dashboard.yaml

Converting Grafana JSON dashboard to a Kubernetes manifest

docker run --rm -it -u $(id -u):$(id -g) -v $(pwd):/workspace kphoen/dark-converter:latest convert-k8s-manifest -i dashboard.json -o converted-dashboard.yaml --folder Dark --namespace monitoring test-dashboard

Integrating with ArgoCD

ArgoCD supports health checks for custom resources. To enable it for GrafanaDashboards, add the following code to your argo-cm ConfigMap:

data:
  resource.customizations.health.k8s.kevingomez.fr_GrafanaDashboard: |                                                                                                                                               
    hs = {}                                                                                                                                                                                                          
    if obj.status ~= nil then                                                                                                                                                                                        
      if obj.status.status ~= "OK" then                                                                                                                                                                              
        hs.status = "Degraded"                                                                                                                                                                                       
        hs.message = obj.status.message                                                                                                                                                                              
        return hs                                                                                                                                                                                                    
      else                                                                                                                                                                                                           
        hs.status = "Healthy"                                                                                                                                                                                        
        hs.message = obj.status.message                                                                                                                                                                              
        return hs                                                                                                                                                                                                    
      end                                                                                                                                                                                                            
    end                                                                                                                                                                                                              
                                                                                                                                                                                                                     
    hs.status = "Progressing"                                                                                                                                                                                            
    hs.message = "Status unknown"                                                                                                                                                                                    
    return hs 

Adopters

Companies using DARK.

License

This library is under the MIT license.

dark's People

Contributors

k-phoen avatar diskmanti avatar

Stargazers

Roman 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.