diff --git a/grafana/grafana-configmap.yaml b/grafana/grafana-configmap.yaml new file mode 100644 index 0000000..c97998e --- /dev/null +++ b/grafana/grafana-configmap.yaml @@ -0,0 +1,21 @@ +apiVersion: v1 +kind: ConfigMap +metadata: + name: grafana-datasources + namespace: #namespace_name# +data: + prometheus.yaml: |- + { + "apiVersion": 1, + "datasources": [ + { + "access":"proxy", + "editable": true, + "name": "prometheus", + "orgId": 1, + "type": "prometheus", + "url": "http://prometheus-service.monitoring.svc:8080", + "version": 1 + } + ] + } diff --git a/grafana/grafana-deployment.yaml b/grafana/grafana-deployment.yaml new file mode 100644 index 0000000..10d86b7 --- /dev/null +++ b/grafana/grafana-deployment.yaml @@ -0,0 +1,49 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: grafana + namespace: #namespace_name# +spec: + replicas: 1 + selector: + matchLabels: + app: grafana + template: + metadata: + name: grafana + labels: + app: grafana + spec: + containers: + - name: grafana + image: grafana/grafana:9.3.6 + ports: + - name: grafana + containerPort: 3000 + resources: + limits: + memory: "1Gi" + cpu: "1000m" + requests: + memory: 500M + cpu: "500m" + volumeMounts: + - mountPath: /var/lib/grafana + name: grafana-storage + - mountPath: /etc/grafana/provisioning/datasources + name: grafana-datasources + readOnly: false + volumes: + - name: grafana-storage + persistentVolumeClaim: + claimName: grafana-storage + - name: grafana-datasources + persistentVolumeClaim: + claimName: grafana-datasources + initContainers: + - name: volume-mount-hack + image: busybox + command: ["sh", "-c", "chown -R 472:472 /var/lib/grafana"] + volumeMounts: + - name: grafana-storage + mountPath: /var/lib/grafana diff --git a/grafana/grafana-ingress.yaml b/grafana/grafana-ingress.yaml new file mode 100644 index 0000000..32a2315 --- /dev/null +++ b/grafana/grafana-ingress.yaml @@ -0,0 +1,19 @@ +apiVersion: networking.k8s.io/v1 +kind: Ingress +metadata: + name: grafana + namespace: #namespace_name# + annotations: + kubernetes.io/ingress.class: "nginx" +spec: + rules: + - host: grafana.mybento.local + http: + paths: + - path: / + pathType: Prefix + backend: + service: + name: grafana + port: + number: 3000 diff --git a/grafana/grafana-pvc.yaml b/grafana/grafana-pvc.yaml new file mode 100644 index 0000000..16b75e6 --- /dev/null +++ b/grafana/grafana-pvc.yaml @@ -0,0 +1,25 @@ +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + name: grafana-storage + namespace: #namespace_name# +spec: + storageClassName: longhorn + accessModes: + - ReadWriteOnce + resources: + requests: + storage: 1Gi +--- +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + name: grafana-datasources + namespace: #namespace_name# +spec: + storageClassName: longhorn + accessModes: + - ReadWriteOnce + resources: + requests: + storage: 1Gi diff --git a/grafana/grafana-service.yaml b/grafana/grafana-service.yaml new file mode 100644 index 0000000..60e323f --- /dev/null +++ b/grafana/grafana-service.yaml @@ -0,0 +1,16 @@ +apiVersion: v1 +kind: Service +metadata: + name: grafana + namespace: #namespace_name# + annotations: + prometheus.io/scrape: "true" + prometheus.io/port: "3000" +spec: + selector: + app: grafana + type: NodePort + ports: + - port: 3000 + targetPort: 3000 + nodePort: 32309 diff --git a/grafana/package.json b/grafana/package.json new file mode 100644 index 0000000..cb2ec6f --- /dev/null +++ b/grafana/package.json @@ -0,0 +1,16 @@ +{ + "name": "grafana", + "display_name": "grafana", + "description": "grafana", + "parameters": [], + "main": "grafana/run.sh", + "dependencies": [ + "grafana/run.sh", + "utils/cachengo.sh", + "grafana/grafana-configmap.yaml", + "grafana/grafana-deployment.yaml", + "grafana/grafana-ingress.yaml", + "grafana/grafana-pvc.yaml", + "grafana/grafana-service.yaml" + ] + } \ No newline at end of file diff --git a/grafana/readme.md b/grafana/readme.md new file mode 100644 index 0000000..f168e61 --- /dev/null +++ b/grafana/readme.md @@ -0,0 +1,79 @@ +![Grafana logo](https://github.com/grafana/grafana/raw/main/docs/logo-horizontal.png "Grafana Logo") + +## What is Grafana? + +--- + +Grafana allows you to query, visualize, alert on and understand your metrics no matter where they are stored + + +## Features + +--- +-Visualizations: Fast and flexible client side graphs with a multitude of options. Panel plugins offer many different ways to visualize metrics and logs. + +-Dynamic Dashboards: Create dynamic & reusable dashboards with template variables that appear as dropdowns at the top of the dashboard. + +-Explore Metrics: Explore your data through ad-hoc queries and dynamic drilldown. Split view and compare different time ranges, queries and data sources side by side. + +-Explore Logs: Experience the magic of switching from metrics to logs with preserved label filters. Quickly search through all your logs or streaming them live. + +-Alerting: Visually define alert rules for your most important metrics. Grafana will continuously evaluate and send notifications to systems like Slack, PagerDuty, VictorOps, OpsGenie. + +-Mixed Data Sources: Mix different data sources in the same graph! You can specify a data source on a per-query basis. This works for even custom datasources. + +## Installation + +--- + +1. Select the devices to which Grafana will be installed from 'Devices' page. + +2. Navigate to the 'App Marketplace' tab and select the 'Grafana' application. + +3. The 'Install Now' button should now appear near the top of the screen. Select this button. + +4. Give your installation a name and fill all the parameters. Click 'Install Grafana' in the bottom right corner. + +## Required Parameters + +--- + + +## Additional Parameters + +--- + +**Installation Name** + +Here you will put your app name. Although the app name is Grafana on the portal, you can personalize the name that is shown on the device's Applications. + +**NAMESPACE NAME** +Namespace where you want your app to be installed. + +## Using Grafana + +After you have installed Grafana and set up your first dashboard, you will have many options to choose from depending on your requirements. For example, if you want to view weather data and statistics about your smart home, then you can create a playlist. If you are the administrator for an enterprise and are managing Grafana for multiple teams, then you can set up provisioning and authentication. + +If you’re using Grafana Alerting, then you can have alerts sent through a number of different alert notifiers, including PagerDuty, SMS, email, VictorOps, OpsGenie, or Slack. + +## OS Architectures + +--- + +- Arm64 + +## Limitations / Known issues + +--- + +## Grafana Platform Video + +--- + +[![Demo Image](http://img.youtube.com/vi/0n2UNzk2OaI/0.jpg)](https://www.youtube.com/watch?v=0n2UNzk2OaI) + +## Docs + +--- + +For more information: diff --git a/grafana/run.sh b/grafana/run.sh new file mode 100755 index 0000000..d220f1c --- /dev/null +++ b/grafana/run.sh @@ -0,0 +1,39 @@ +#!/bin/bash + +function do_install { + set -e + cachengo-cli updateInstallStatus "$APPID" "Installing" + + kubectl create namespace $APPID + + sed -i "s|#namespace_name#|$APPID|g" grafana/grafana-configmap.yaml + sed -i "s|#namespace_name#|$APPID|g" grafana/grafana-deployment.yaml + sed -i "s|#namespace_name#|$APPID|g" grafana/grafana-ingress.yaml + sed -i "s|#namespace_name#|$APPID|g" grafana/grafana-service.yaml + sed -i "s|#namespace_name#|$APPID|g" grafana/grafana-pvc.yaml + + kubectl apply -f grafana/grafana-configmap.yaml + kubectl apply -f grafana/grafana-deployment.yaml + kubectl apply -f grafana/grafana-ingress.yaml + kubectl apply -f grafana/grafana-service.yaml + kubectl apply -f grafana/grafana-pvc.yaml + +} + +function do_uninstall { + cachengo-cli updateInstallStatus "$APPID" "Uninstalling" + + kubectl delete -f grafana/grafana-ingress.yaml -n $APPID + kubectl delete -f grafana/grafana-service.yaml -n $APPID + kubectl delete -f grafana/grafana-deployment.yaml -n $APPID + kubectl delete -f grafana/grafana-pvc.yaml -n $APPID + kubectl delete -f grafana/grafana-configmap.yaml -n $APPID + + kubectl delete namespace $APPID + + cachengo-cli updateInstallStatus "$APPID" "Uninstalled" +} +case "$1" in + install) do_install ;; + uninstall) do_uninstall ;; +esac \ No newline at end of file diff --git a/utils/docker.sh b/utils/docker.sh index 5820817..7872a31 100644 --- a/utils/docker.sh +++ b/utils/docker.sh @@ -16,4 +16,10 @@ function delete_network { function container_state { echo "$( docker container inspect -f '{{.State.Status}}' $1 )" +} + +function get_host { + HOST_NAME=$(hostname) + + echo "$HOST_NAME" } \ No newline at end of file