From d03a21ee11fd2f49124d494a721dee2d0a6995e9 Mon Sep 17 00:00:00 2001 From: WrenIX Date: Sat, 29 Jun 2024 12:42:46 +0200 Subject: [PATCH] fix(jellyfin): add monitoring --- jellyfin/Chart.yaml | 2 +- jellyfin/README.adoc | 42 +- jellyfin/files/config-patch.sh.gotmpl | 2 + jellyfin/grafana_dashboards/my.json | 585 ++++++++++++++++++ jellyfin/templates/configmap.yaml | 11 + .../configmap_grafana_dashboards.yaml | 14 + jellyfin/templates/deployment.yaml | 29 +- jellyfin/templates/servicemonitor.yaml | 19 + jellyfin/values.yaml | 22 + 9 files changed, 723 insertions(+), 3 deletions(-) create mode 100644 jellyfin/files/config-patch.sh.gotmpl create mode 100644 jellyfin/grafana_dashboards/my.json create mode 100644 jellyfin/templates/configmap.yaml create mode 100644 jellyfin/templates/configmap_grafana_dashboards.yaml create mode 100644 jellyfin/templates/servicemonitor.yaml diff --git a/jellyfin/Chart.yaml b/jellyfin/Chart.yaml index 8350064..74c0c55 100644 --- a/jellyfin/Chart.yaml +++ b/jellyfin/Chart.yaml @@ -3,7 +3,7 @@ name: jellyfin description: The Free Software Media System icon: https://raw.githubusercontent.com/jellyfin/jellyfin-ux/master/branding/SVG/icon-transparent.svg type: application -version: 0.1.8 +version: 0.2.0 # renovate: image=ghcr.io/jellyfin/jellyfin appVersion: "10.9.7" maintainers: diff --git a/jellyfin/README.adoc b/jellyfin/README.adoc index a3e910a..e6d96cf 100644 --- a/jellyfin/README.adoc +++ b/jellyfin/README.adoc @@ -2,7 +2,7 @@ = jellyfin -image::https://img.shields.io/badge/Version-0.1.8-informational?style=flat-square[Version: 0.1.8] +image::https://img.shields.io/badge/Version-0.2.0-informational?style=flat-square[Version: 0.2.0] image::https://img.shields.io/badge/Version-application-informational?style=flat-square[Type: application] image::https://img.shields.io/badge/AppVersion-10.9.7-informational?style=flat-square[AppVersion: 10.9.7] == Maintainers @@ -72,6 +72,21 @@ helm uninstall jellyfin-release | `80` | +| config.enabled +| bool +| `false` +| + +| config.image +| object +| `{"pullPolicy":"IfNotPresent","registry":"ghcr.io","repository":"tomwright/dasel","tag":"2.8.0"}` +| image to patch config + +| config.metrics +| bool +| `false` +| + | fullnameOverride | string | `""` @@ -87,6 +102,21 @@ helm uninstall jellyfin-release | `nil` | if set it will overwrite all registry entries +| grafana.dashboards.annotations +| object +| `{}` +| + +| grafana.dashboards.enabled +| bool +| `false` +| + +| grafana.dashboards.labels.grafana_dashboard +| string +| `"1"` +| + | image.pullPolicy | string | `"IfNotPresent"` @@ -217,6 +247,16 @@ helm uninstall jellyfin-release | `{}` | +| prometheus.servicemonitor.enabled +| bool +| `false` +| + +| prometheus.servicemonitor.labels +| object +| `{}` +| + | replicaCount | int | `1` diff --git a/jellyfin/files/config-patch.sh.gotmpl b/jellyfin/files/config-patch.sh.gotmpl new file mode 100644 index 0000000..ceff831 --- /dev/null +++ b/jellyfin/files/config-patch.sh.gotmpl @@ -0,0 +1,2 @@ +#!/bin/sh +dasel -f /config/config/system.xml put ServerConfiguration.EnableMetrics -t bool -v {{ .Values.config.metrics | quote}} diff --git a/jellyfin/grafana_dashboards/my.json b/jellyfin/grafana_dashboards/my.json new file mode 100644 index 0000000..307664d --- /dev/null +++ b/jellyfin/grafana_dashboards/my.json @@ -0,0 +1,585 @@ +{ + "annotations": { + "list": [ + { + "builtIn": 1, + "datasource": { + "type": "datasource", + "uid": "grafana" + }, + "enable": true, + "hide": true, + "iconColor": "rgba(0, 211, 255, 1)", + "name": "Annotations & Alerts", + "target": { + "limit": 100, + "matchAny": false, + "tags": [], + "type": "dashboard" + }, + "type": "dashboard" + } + ] + }, + "editable": true, + "fiscalYearStartMonth": 0, + "graphTooltip": 0, + "links": [], + "liveNow": false, + "panels": [ + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "palette-classic" + }, + "custom": { + "axisBorderShow": false, + "axisCenteredZero": false, + "axisColorMode": "text", + "axisLabel": "", + "axisPlacement": "auto", + "barAlignment": 0, + "drawStyle": "line", + "fillOpacity": 0, + "gradientMode": "none", + "hideFrom": { + "legend": false, + "tooltip": false, + "viz": false + }, + "insertNulls": false, + "lineInterpolation": "linear", + "lineWidth": 1, + "pointSize": 5, + "scaleDistribution": { + "type": "linear" + }, + "showPoints": "auto", + "spanNulls": false, + "stacking": { + "group": "A", + "mode": "none" + }, + "thresholdsStyle": { + "mode": "off" + } + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + }, + { + "color": "red", + "value": 80 + } + ] + }, + "unit": "bytes" + }, + "overrides": [] + }, + "gridPos": { + "h": 9, + "w": 12, + "x": 0, + "y": 0 + }, + "id": 4, + "options": { + "legend": { + "calcs": [], + "displayMode": "list", + "placement": "bottom", + "showLegend": true + }, + "tooltip": { + "maxHeight": 600, + "mode": "single", + "sort": "none" + } + }, + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "editorMode": "code", + "exemplar": true, + "expr": "sum(dotnet_total_memory_bytes{container=\"jellyfin\"}) without (endpoint,instance,pod)", + "interval": "", + "legendFormat": "Dotnet total memory", + "range": true, + "refId": "A" + }, + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "editorMode": "code", + "exemplar": true, + "expr": "sum(process_private_memory_bytes{container=\"jellyfin\"}) without (endpoint,instance,pod)", + "hide": false, + "interval": "", + "legendFormat": "Process private memory", + "range": true, + "refId": "B" + }, + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "editorMode": "code", + "exemplar": true, + "expr": "sum(process_working_set_bytes{container=\"jellyfin\"}) without (endpoint,instance,pod)", + "hide": false, + "interval": "", + "legendFormat": "Process working set", + "range": true, + "refId": "C" + } + ], + "title": "Memory usage", + "type": "timeseries" + }, + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "palette-classic" + }, + "custom": { + "axisBorderShow": false, + "axisCenteredZero": false, + "axisColorMode": "text", + "axisLabel": "", + "axisPlacement": "auto", + "barAlignment": 0, + "drawStyle": "line", + "fillOpacity": 0, + "gradientMode": "none", + "hideFrom": { + "legend": false, + "tooltip": false, + "viz": false + }, + "insertNulls": false, + "lineInterpolation": "linear", + "lineWidth": 1, + "pointSize": 5, + "scaleDistribution": { + "type": "linear" + }, + "showPoints": "auto", + "spanNulls": false, + "stacking": { + "group": "A", + "mode": "none" + }, + "thresholdsStyle": { + "mode": "off" + } + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + }, + { + "color": "red", + "value": 80 + } + ] + } + }, + "overrides": [] + }, + "gridPos": { + "h": 9, + "w": 12, + "x": 12, + "y": 0 + }, + "id": 2, + "options": { + "legend": { + "calcs": [], + "displayMode": "list", + "placement": "bottom", + "showLegend": true + }, + "tooltip": { + "maxHeight": 600, + "mode": "single", + "sort": "none" + } + }, + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "editorMode": "code", + "exemplar": true, + "expr": "sum(rate(dotnet_exceptions_total{container=\"jellyfin\"}[$__rate_interval])) without (endpoint,instance,pod)", + "interval": "", + "legendFormat": "{{type}}", + "range": true, + "refId": "A" + } + ], + "title": "Exceptions", + "type": "timeseries" + }, + { + "gridPos": { + "h": 1, + "w": 24, + "x": 0, + "y": 9 + }, + "id": 11, + "title": "HTTP Requests", + "type": "row" + }, + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "palette-classic" + }, + "custom": { + "axisBorderShow": false, + "axisCenteredZero": false, + "axisColorMode": "text", + "axisLabel": "", + "axisPlacement": "auto", + "barAlignment": 0, + "drawStyle": "line", + "fillOpacity": 0, + "gradientMode": "none", + "hideFrom": { + "legend": false, + "tooltip": false, + "viz": false + }, + "insertNulls": false, + "lineInterpolation": "linear", + "lineWidth": 1, + "pointSize": 5, + "scaleDistribution": { + "type": "linear" + }, + "showPoints": "auto", + "spanNulls": false, + "stacking": { + "group": "A", + "mode": "none" + }, + "thresholdsStyle": { + "mode": "off" + } + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + }, + { + "color": "red", + "value": 80 + } + ] + }, + "unit": "reqps" + }, + "overrides": [] + }, + "gridPos": { + "h": 9, + "w": 8, + "x": 0, + "y": 10 + }, + "id": 8, + "options": { + "legend": { + "calcs": [], + "displayMode": "list", + "placement": "bottom", + "showLegend": true + }, + "tooltip": { + "maxHeight": 600, + "mode": "single", + "sort": "none" + } + }, + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "editorMode": "code", + "exemplar": true, + "expr": "sum(irate(http_requests_received_total{container=\"jellyfin\"}[$__rate_interval])) without (endpoint,instance,pod)", + "interval": "", + "legendFormat": "{{method}} {{controller}} {{action}} {{code}}", + "range": true, + "refId": "A" + } + ], + "title": "Requests per Seconds", + "type": "timeseries" + }, + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "fieldConfig": { + "defaults": { + "custom": { + "hideFrom": { + "legend": false, + "tooltip": false, + "viz": false + }, + "scaleDistribution": { + "type": "linear" + } + } + }, + "overrides": [] + }, + "gridPos": { + "h": 9, + "w": 7, + "x": 8, + "y": 10 + }, + "id": 9, + "options": { + "calculate": false, + "cellGap": 1, + "color": { + "exponent": 0.5, + "fill": "dark-orange", + "mode": "scheme", + "reverse": false, + "scale": "exponential", + "scheme": "Oranges", + "steps": 64 + }, + "exemplars": { + "color": "rgba(255,0,255,0.7)" + }, + "filterValues": { + "le": 1e-9 + }, + "legend": { + "show": true + }, + "rowsFrame": { + "layout": "auto" + }, + "tooltip": { + "maxHeight": 600, + "mode": "single", + "showColorScale": false, + "yHistogram": false + }, + "yAxis": { + "axisPlacement": "left", + "reverse": false + } + }, + "pluginVersion": "11.0.0", + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "editorMode": "code", + "exemplar": true, + "expr": "sum(increase(http_request_duration_seconds_bucket{container=\"jellyfin\"}[$__rate_interval])) by(le)", + "format": "heatmap", + "interval": "", + "legendFormat": "__auto", + "range": true, + "refId": "A" + } + ], + "title": "Latency", + "type": "heatmap" + }, + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "palette-classic" + }, + "custom": { + "axisBorderShow": false, + "axisCenteredZero": false, + "axisColorMode": "text", + "axisLabel": "", + "axisPlacement": "auto", + "barAlignment": 0, + "drawStyle": "line", + "fillOpacity": 0, + "gradientMode": "none", + "hideFrom": { + "legend": false, + "tooltip": false, + "viz": false + }, + "insertNulls": false, + "lineInterpolation": "linear", + "lineWidth": 1, + "pointSize": 5, + "scaleDistribution": { + "log": 10, + "type": "log" + }, + "showPoints": "auto", + "spanNulls": false, + "stacking": { + "group": "A", + "mode": "none" + }, + "thresholdsStyle": { + "mode": "off" + } + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + }, + { + "color": "red", + "value": 80 + } + ] + }, + "unit": "s" + }, + "overrides": [] + }, + "gridPos": { + "h": 9, + "w": 9, + "x": 15, + "y": 10 + }, + "id": 10, + "options": { + "legend": { + "calcs": [ + "mean", + "lastNotNull" + ], + "displayMode": "table", + "placement": "right", + "showLegend": true, + "sortBy": "Name", + "sortDesc": false + }, + "tooltip": { + "maxHeight": 600, + "mode": "single", + "sort": "none" + } + }, + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "editorMode": "code", + "exemplar": true, + "expr": "histogram_quantile(0.95, sum(rate(http_request_duration_seconds_bucket{container=\"jellyfin\"}[$__rate_interval])) without(container,endpoint, instance, pod, code, exported_endpoint, method,action))", + "interval": "", + "legendFormat": "{{controller}}.", + "range": true, + "refId": "A" + } + ], + "title": "Latency", + "type": "timeseries" + } + ], + "refresh": "30s", + "schemaVersion": 39, + "tags": [], + "templating": { + "list": [ + { + "current": { + "selected": false, + "text": "Prometheus", + "value": "prometheus" + }, + "hide": 0, + "includeAll": false, + "label": "datasource", + "multi": false, + "name": "DS_PROMETHEUS", + "options": [], + "query": "prometheus", + "refresh": 1, + "regex": "", + "skipUrlSync": false, + "type": "datasource" + } + ] + }, + "time": { + "from": "now-6h", + "to": "now" + }, + "timeRangeUpdatedDuringEditOrView": false, + "timepicker": {}, + "timezone": "", + "title": "Jellyfin", + "uid": "zkWB8mtnk", + "version": 1, + "weekStart": "" +} \ No newline at end of file diff --git a/jellyfin/templates/configmap.yaml b/jellyfin/templates/configmap.yaml new file mode 100644 index 0000000..7252259 --- /dev/null +++ b/jellyfin/templates/configmap.yaml @@ -0,0 +1,11 @@ +{{- if .Values.config.enabled }} +apiVersion: v1 +kind: ConfigMap +metadata: + name: {{ include "jellyfin.fullname" . }}-config + labels: + {{- include "jellyfin.labels" . | nindent 4 }} +data: + patch.sh: |- + {{ tpl (.Files.Get "files/config-patch.sh.gotmpl") . | nindent 4 }} +{{- end }} diff --git a/jellyfin/templates/configmap_grafana_dashboards.yaml b/jellyfin/templates/configmap_grafana_dashboards.yaml new file mode 100644 index 0000000..1f5ae52 --- /dev/null +++ b/jellyfin/templates/configmap_grafana_dashboards.yaml @@ -0,0 +1,14 @@ +{{- if .Values.grafana.dashboards.enabled }} +--- +apiVersion: v1 +kind: ConfigMap +metadata: + name: {{ include "jellyfin.fullname" $ }}-grafana-dashboards + labels: + {{- include "jellyfin.labels" $ | nindent 4 }} + {{- toYaml $.Values.grafana.dashboards.labels | nindent 4 }} + annotations: + {{- toYaml $.Values.grafana.dashboards.annotations | nindent 4 }} +data: + {{- (.Files.Glob "grafana_dashboards/*.json" ).AsConfig | nindent 2 }} +{{- end }} diff --git a/jellyfin/templates/deployment.yaml b/jellyfin/templates/deployment.yaml index 348c8fe..e8f61e3 100644 --- a/jellyfin/templates/deployment.yaml +++ b/jellyfin/templates/deployment.yaml @@ -32,11 +32,29 @@ spec: serviceAccountName: {{ include "jellyfin.serviceAccountName" . }} securityContext: {{- toYaml .Values.podSecurityContext | nindent 8 }} + {{- if .Values.config.enabled }} + initContainers: + - name: patch-config + securityContext: + {{- toYaml .Values.securityContext | nindent 12 }} + {{- with .Values.config.image }} + image: "{{ coalesce $.Values.global.image.registry .registry }}/{{ .repository }}:{{ .tag }}" + imagePullPolicy: {{ coalesce $.Values.global.image.pullPolicy .pullPolicy }} + {{- end }} + command: + - "/bin/sh" + - "/scripts/init.sh" + volumeMounts: + - mountPath: /config + name: config + - mountPath: /scripts + name: configmap + {{- end }} containers: - name: {{ .Chart.Name }} securityContext: {{- toYaml .Values.securityContext | nindent 12 }} - {{- with .Values.image}} + {{- with .Values.image }} image: "{{ coalesce $.Values.global.image.registry .registry }}/{{ .repository }}:{{ .tag | default $.Chart.AppVersion }}" imagePullPolicy: {{ coalesce $.Values.global.image.pullPolicy .pullPolicy }} {{- end }} @@ -92,6 +110,15 @@ spec: {{- end }} - name: cache emptyDir: {} + {{- if .Values.config.enabled }} + - name: configmap + configMap: + name: {{ include "jellyfin.fullname" . }}-config + defaultMode: 0755 + items: + - key: "patch.sh" + path: "init.sh" + {{- end }} - name: media {{- with .Values.persistence.media }} {{- if .nfs.server }} diff --git a/jellyfin/templates/servicemonitor.yaml b/jellyfin/templates/servicemonitor.yaml new file mode 100644 index 0000000..f99ead8 --- /dev/null +++ b/jellyfin/templates/servicemonitor.yaml @@ -0,0 +1,19 @@ +{{- if and .Values.config.metrics .Values.prometheus.servicemonitor.enabled }} +apiVersion: monitoring.coreos.com/v1 +kind: ServiceMonitor +metadata: + name: {{ include "jellyfin.fullname" . }} + labels: + {{- include "jellyfin.labels" . | nindent 4 }} + {{- with .Values.prometheus.servicemonitor.labels }} + {{- toYaml . | nindent 4 }} + {{- end }} +spec: + selector: + matchLabels: + {{- include "jellyfin.selectorLabels" . | nindent 6 }} + endpoints: + - port: http + path: "/metrics" +{{- end }} + diff --git a/jellyfin/values.yaml b/jellyfin/values.yaml index e714d7e..c04afcb 100644 --- a/jellyfin/values.yaml +++ b/jellyfin/values.yaml @@ -18,6 +18,16 @@ imagePullSecrets: [] nameOverride: "" fullnameOverride: "" +config: + enabled: false + # -- image to patch config + image: + registry: ghcr.io + repository: tomwright/dasel + pullPolicy: IfNotPresent + tag: "2.8.0" + metrics: false + persistence: config: nfs: @@ -62,6 +72,18 @@ service: type: ClusterIP port: 8096 +prometheus: + servicemonitor: + enabled: false + labels: {} + +grafana: + dashboards: + enabled: false + labels: + grafana_dashboard: "1" + annotations: {} + ingress: enabled: false className: ""