From 56697fde19055e8593ecc72e038f3fd5468af7b7 Mon Sep 17 00:00:00 2001 From: m0duspwnens Date: Thu, 8 Jul 2021 14:10:22 -0400 Subject: [PATCH] create common dashboard and define templates/dashbaord vars --- .../dashboards/common_template.json.jinja | 59 +++++ .../standalone/common_standalone.json.jinja | 203 +++++++++--------- salt/grafana/dashboards/template.json | 130 ----------- salt/grafana/defaults.yaml | 5 + salt/grafana/init.sls | 12 +- salt/grafana/templates/cpucount.json | 24 +++ salt/grafana/templates/mainint.json | 24 +++ salt/grafana/templates/monint.json | 24 +++ salt/grafana/templates/role.json | 24 +++ salt/grafana/templates/servername.json | 24 +++ 10 files changed, 291 insertions(+), 238 deletions(-) create mode 100644 salt/grafana/dashboards/common_template.json.jinja delete mode 100644 salt/grafana/dashboards/template.json create mode 100644 salt/grafana/templates/cpucount.json create mode 100644 salt/grafana/templates/mainint.json create mode 100644 salt/grafana/templates/monint.json create mode 100644 salt/grafana/templates/role.json create mode 100644 salt/grafana/templates/servername.json diff --git a/salt/grafana/dashboards/common_template.json.jinja b/salt/grafana/dashboards/common_template.json.jinja new file mode 100644 index 000000000..ffe2a4740 --- /dev/null +++ b/salt/grafana/dashboards/common_template.json.jinja @@ -0,0 +1,59 @@ +{ + "annotations": { + "list": [ + { + "builtIn": 1, + "datasource": "-- Grafana --", + "enable": true, + "hide": true, + "iconColor": "rgba(0, 211, 255, 1)", + "name": "Annotations & Alerts", + "type": "dashboard" + } + ] + }, + "description": "MY DASHBOARD DESCRIPTION", + "editable": true, + "gnetId": null, + "graphTooltip": 0, + "id": 7, + "iteration": 1625757047565, + "links": [], + "panels": [ +{% for panel in PANELS -%} +{%- import_json "grafana/panels/" ~ panel ~ ".json.jinja" as panel %} +{{ panel | json }} {% if not loop.last %},{% endif %} +{% endfor -%} + ], + "schemaVersion": 27, + "style": "dark", + "tags": [], + "templating": { + "list": [ +{% for template in TEMPLATES -%} +{%- import_json "grafana/templates/" ~ template ~ ".json" as panel %} +{{ template | json }} {% if not loop.last %},{% endif %} +{% endfor -%} + ] + }, + "time": { + "from": "now-3h", + "to": "now" + }, + "timepicker": { + "refresh_intervals": [ + "30s", + "1m", + "5m", + "15m", + "30m", + "1h", + "2h", + "1d" + ] + }, + "timezone": "browser", + "title": "MY DASHBOARD NAME - Standalone", + "uid": "{{ UID }}", + "version": 1 +} diff --git a/salt/grafana/dashboards/standalone/common_standalone.json.jinja b/salt/grafana/dashboards/standalone/common_standalone.json.jinja index 1d331e801..a4167d6d0 100644 --- a/salt/grafana/dashboards/standalone/common_standalone.json.jinja +++ b/salt/grafana/dashboards/standalone/common_standalone.json.jinja @@ -12,117 +12,131 @@ } ] }, - "description": "This Dashboard provides a general overview of Standalone Mode", + "description": "MY DASHBOARD DESCRIPTION", "editable": true, - "gnetId": 2381, + "gnetId": null, "graphTooltip": 0, - "id": 6, - "iteration": 1625018989654, + "id": 7, + "iteration": 1625757047565, "links": [], - "panels": [ -{% for panel in PANELS -%} - {%- import_json "grafana/panels/" ~ panel ~ ".json.jinja" as panel %} -{{ panel | json }} {% if not loop.last %},{% endif %} -{% endfor -%} - - ], - "refresh": "30s", + "panels": [], "schemaVersion": 27, "style": "dark", "tags": [], "templating": { "list": [ { - "auto": true, - "auto_count": 30, - "auto_min": "10s", + "allValue": null, "current": { "selected": false, - "text": "10s", - "value": "10s" + "text": "eth0", + "value": "eth0" }, + "datasource": "InfluxDB", + "definition": "SELECT \"manint\" FROM \"node_config\" WHERE (\"host\" = 'jppce2360sa-influx-scripts')", "description": null, "error": null, "hide": 0, - "label": null, - "name": "Interval", - "options": [ - { - "selected": false, - "text": "auto", - "value": "$__auto_interval_Interval" - }, - { - "selected": true, - "text": "10s", - "value": "10s" - }, - { - "selected": false, - "text": "1m", - "value": "1m" - }, - { - "selected": false, - "text": "10m", - "value": "10m" - }, - { - "selected": false, - "text": "30m", - "value": "30m" - }, - { - "selected": false, - "text": "1h", - "value": "1h" - }, - { - "selected": false, - "text": "6h", - "value": "6h" - }, - { - "selected": false, - "text": "12h", - "value": "12h" - }, - { - "selected": false, - "text": "1d", - "value": "1d" - }, - { - "selected": false, - "text": "7d", - "value": "7d" - }, - { - "selected": false, - "text": "14d", - "value": "14d" - }, - { - "selected": false, - "text": "30d", - "value": "30d" - } - ], - "query": "10s, 1m,10m,30m,1h,6h,12h,1d,7d,14d,30d", - "refresh": 3, + "includeAll": false, + "label": "Management Interface", + "multi": false, + "name": "manint", + "options": [], + "query": "SELECT \"manint\" FROM \"node_config\" WHERE (\"host\" = 'jppce2360sa-influx-scripts')", + "refresh": 1, + "regex": "", "skipUrlSync": false, - "type": "interval" + "sort": 0, + "tagValuesQuery": "", + "tags": [], + "tagsQuery": "", + "type": "query", + "useTags": false + }, + { + "allValue": null, + "current": {}, + "datasource": "InfluxDB", + "definition": "SELECT \"monint\" FROM \"node_config\" WHERE (\"host\" = 'jppce2360sa-influx-scripts')", + "description": null, + "error": null, + "hide": 0, + "includeAll": false, + "label": "Monitor Interface", + "multi": false, + "name": "monint", + "options": [], + "query": "SELECT \"monint\" FROM \"node_config\" WHERE (\"host\" = 'jppce2360sa-influx-scripts')", + "refresh": 1, + "regex": "", + "skipUrlSync": false, + "sort": 0, + "tagValuesQuery": "", + "tags": [], + "tagsQuery": "", + "type": "query", + "useTags": false + }, + { + "allValue": null, + "current": {}, + "datasource": "InfluxDB", + "definition": "show tag values with key=\"host\" where \"role\" = 'standalone'", + "description": "", + "error": null, + "hide": 0, + "includeAll": false, + "label": "Node", + "multi": false, + "name": "servername", + "options": [], + "query": "show tag values with key=\"host\" where \"role\" = 'standalone'", + "refresh": 1, + "regex": "", + "skipUrlSync": false, + "sort": 0, + "tagValuesQuery": "", + "tags": [], + "tagsQuery": "", + "type": "query", + "useTags": false + }, + { + "allValue": null, + "current": { + "selected": false, + "text": "", + "value": "" + }, + "datasource": "InfluxDB", + "definition": "SELECT \"n_cpus\" FROM \"system\" WHERE \"host\" = '$servername'", + "description": null, + "error": null, + "hide": 2, + "includeAll": false, + "label": "CPU Count", + "multi": false, + "name": "cpucount", + "options": [], + "query": "SELECT \"n_cpus\" FROM \"system\" WHERE \"host\" = '$servername'", + "refresh": 1, + "regex": "", + "skipUrlSync": false, + "sort": 0, + "tagValuesQuery": "", + "tags": [], + "tagsQuery": "", + "type": "query", + "useTags": false } ] }, "time": { - "from": "now-1h", + "from": "now-3h", "to": "now" }, "timepicker": { "refresh_intervals": [ - "5s", - "10s", "30s", "1m", "5m", @@ -131,21 +145,10 @@ "1h", "2h", "1d" - ], - "time_options": [ - "5m", - "15m", - "1h", - "6h", - "12h", - "24h", - "2d", - "7d", - "30d" ] }, "timezone": "browser", - "title": "Standalone - {{ SERVERNAME }} Overview", + "title": "Standalone Dashboard", "uid": "{{ UID }}", - "version": 17 + "version": 1 } diff --git a/salt/grafana/dashboards/template.json b/salt/grafana/dashboards/template.json deleted file mode 100644 index f1ec5d8ff..000000000 --- a/salt/grafana/dashboards/template.json +++ /dev/null @@ -1,130 +0,0 @@ -{ - "annotations": { - "list": [ - { - "builtIn": 1, - "datasource": "-- Grafana --", - "enable": true, - "hide": true, - "iconColor": "rgba(0, 211, 255, 1)", - "name": "Annotations & Alerts", - "type": "dashboard" - } - ] - }, - "description": "MY DASHBOARD DESCRIPTION", - "editable": true, - "gnetId": null, - "graphTooltip": 0, - "id": 7, - "iteration": 1625251118337, - "links": [], - "panels": [], - "schemaVersion": 27, - "style": "dark", - "tags": [], - "templating": { - "list": [ - { - "allValue": null, - "current": { - "selected": false, - "text": "mynode1", - "value": "mynode1" - }, - "description": "", - "error": null, - "hide": 0, - "includeAll": false, - "label": "Node", - "multi": false, - "name": "query0", - "options": [ - { - "selected": true, - "text": "mynode1", - "value": "mynode1" - }, - { - "selected": false, - "text": "mynode2", - "value": "mynode2" - }, - { - "selected": false, - "text": "mynode3", - "value": "mynode3" - } - ], - "query": "mynode1,mynode2,mynode3", - "queryValue": "", - "skipUrlSync": false, - "type": "custom" - }, - { - "current": { - "selected": true, - "text": "{{ MANINT }}", - "value": "{{ MANINT }}" - }, - "description": null, - "error": null, - "hide": 0, - "label": "Management Interface", - "name": "manint", - "options": [ - { - "selected": true, - "text": "{{ MANINT }}", - "value": "{{ MANINT }}" - } - ], - "query": "{{ MANINT }}", - "skipUrlSync": false, - "type": "textbox" - }, - { - "current": { - "selected": true, - "text": "{{ MONINT }}", - "value": "{{ MONINT }}" - }, - "description": null, - "error": null, - "hide": 2, - "label": "Monitor Interface", - "name": "monint", - "options": [ - { - "selected": true, - "text": "{{ MONINT }}", - "value": "{{ MONINT }}" - } - ], - "query": "{{ MONINT }}", - "skipUrlSync": false, - "type": "textbox" - } - ] - }, - "time": { - "from": "now-6h", - "to": "now" - }, - "timepicker": { - "refresh_intervals": [ - "30s", - "1m", - "5m", - "15m", - "30m", - "1h", - "2h", - "1d" - ] - }, - "timezone": "browser", - "title": "MY DASHBOARD NAME", - "uid": "IQqwsPznk", - "version": 3 - } diff --git a/salt/grafana/defaults.yaml b/salt/grafana/defaults.yaml index a384e490a..471d43c77 100644 --- a/salt/grafana/defaults.yaml +++ b/salt/grafana/defaults.yaml @@ -26,6 +26,11 @@ grafana: # license_path: /opt/so/conf/grafana/etc/files/license.jwt dashboards: standalone: + templating: + list: + - servername + - manint + - monint panels: cpu_usage_idle: enabled: true diff --git a/salt/grafana/init.sls b/salt/grafana/init.sls index 655df4bc6..724fa2f91 100644 --- a/salt/grafana/init.sls +++ b/salt/grafana/init.sls @@ -125,15 +125,11 @@ common-standalone-dashboard: - user: 939 - group: 939 - template: jinja - - source: salt://grafana/dashboards/standalone/common_standalone.json.jinja + - source: salt://grafana/dashboards/common_template.json.jinja - defaults: - SERVERNAME: {{ SN }} - MANINT: {{ SNDATA.manint }} - CPUS: {{ SNDATA.totalcpus }} - UID: so_overview - ROOTFS: {{ SNDATA.rootfs }} - NSMFS: {{ SNDATA.nsmfs }} - PANELS: {{GRAFANA_SETTINGS.dashboards.standalone.panels}} + UID: so_overview + PANELS: {{GRAFANA_SETTINGS.dashboards.standalone.panels}} + TEMPLATES: {{GRAFANA_SETTINGS.dashboards.standalone.templates}} {% endfor %} {% endif %} diff --git a/salt/grafana/templates/cpucount.json b/salt/grafana/templates/cpucount.json new file mode 100644 index 000000000..202ae7a49 --- /dev/null +++ b/salt/grafana/templates/cpucount.json @@ -0,0 +1,24 @@ +{ + "allValue": null, + "current": {}, + "datasource": "InfluxDB", + "definition": "SELECT \"n_cpus\" FROM \"system\" WHERE \"host\" = '$servername'", + "description": null, + "error": null, + "hide": 2, + "includeAll": false, + "label": "CPU Count", + "multi": false, + "name": "cpucount", + "options": [], + "query": "SELECT \"n_cpus\" FROM \"system\" WHERE \"host\" = '$servername'", + "refresh": 1, + "regex": "", + "skipUrlSync": false, + "sort": 0, + "tagValuesQuery": "", + "tags": [], + "tagsQuery": "", + "type": "query", + "useTags": false + } diff --git a/salt/grafana/templates/mainint.json b/salt/grafana/templates/mainint.json new file mode 100644 index 000000000..8c0e65530 --- /dev/null +++ b/salt/grafana/templates/mainint.json @@ -0,0 +1,24 @@ +{ + "allValue": null, + "current": {}, + "datasource": "InfluxDB", + "definition": "SELECT \"manint\" FROM \"node_config\" WHERE (\"host\" = '$servername')", + "description": null, + "error": null, + "hide": 0, + "includeAll": false, + "label": "Management Interface", + "multi": false, + "name": "manint", + "options": [], + "query": "SELECT \"manint\" FROM \"node_config\" WHERE (\"host\" = '$servername')", + "refresh": 1, + "regex": "", + "skipUrlSync": false, + "sort": 0, + "tagValuesQuery": "", + "tags": [], + "tagsQuery": "", + "type": "query", + "useTags": false + } diff --git a/salt/grafana/templates/monint.json b/salt/grafana/templates/monint.json new file mode 100644 index 000000000..98098467f --- /dev/null +++ b/salt/grafana/templates/monint.json @@ -0,0 +1,24 @@ +{ + "allValue": null, + "current": {}, + "datasource": "InfluxDB", + "definition": "SELECT \"monint\" FROM \"node_config\" WHERE (\"host\" = '$servername')", + "description": null, + "error": null, + "hide": 0, + "includeAll": false, + "label": "Monitor Interface", + "multi": false, + "name": "monint", + "options": [], + "query": "SELECT \"monint\" FROM \"node_config\" WHERE (\"host\" = '$servername')", + "refresh": 1, + "regex": "", + "skipUrlSync": false, + "sort": 0, + "tagValuesQuery": "", + "tags": [], + "tagsQuery": "", + "type": "query", + "useTags": false + } diff --git a/salt/grafana/templates/role.json b/salt/grafana/templates/role.json new file mode 100644 index 000000000..f76de3cad --- /dev/null +++ b/salt/grafana/templates/role.json @@ -0,0 +1,24 @@ +{ + "allValue": null, + "current": {}, + "datasource": "InfluxDB", + "definition": "show tag values with key=\"role\"", + "description": null, + "error": null, + "hide": 0, + "includeAll": true, + "label": "Role", + "multi": true, + "name": "role", + "options": [], + "query": "show tag values with key=\"role\"", + "refresh": 1, + "regex": "", + "skipUrlSync": false, + "sort": 1, + "tagValuesQuery": "", + "tags": [], + "tagsQuery": "", + "type": "query", + "useTags": false +} diff --git a/salt/grafana/templates/servername.json b/salt/grafana/templates/servername.json new file mode 100644 index 000000000..58fc08818 --- /dev/null +++ b/salt/grafana/templates/servername.json @@ -0,0 +1,24 @@ +{ + "allValue": null, + "current": {}, + "datasource": "InfluxDB", + "definition": "show tag values with key=\"host\" where \"role\" = 'standalone'", + "description": "", + "error": null, + "hide": 0, + "includeAll": false, + "label": "Node", + "multi": false, + "name": "servername", + "options": [], + "query": "show tag values with key=\"host\" where \"role\" = 'standalone'", + "refresh": 1, + "regex": "", + "skipUrlSync": false, + "sort": 0, + "tagValuesQuery": "", + "tags": [], + "tagsQuery": "", + "type": "query", + "useTags": false + }