Skip to content

Commit

Permalink
Merge pull request #37 from JoeyBarnes/main
Browse files Browse the repository at this point in the history
added grafana dashboard section
  • Loading branch information
JoeyBarnes authored Oct 17, 2023
2 parents 6cd49de + a67cb9f commit 5a28db4
Show file tree
Hide file tree
Showing 3 changed files with 214 additions and 0 deletions.
25 changes: 25 additions & 0 deletions docs/layouts/partials/templates/dashboard-tabs.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<div class="gdoc-tabs">
<input
type="radio"
class="gdoc-tabs__control hidden"
name="dashboards"
id="dashboards-0"
checked="checked"
/>
<label for="dashboards-0" class="gdoc-tabs__label"></label>
<div class="gdoc-markdown--nested gdoc-tabs__content">
<p><b>Click a tab to view the dashboard template</b></p>
</div>
<input
type="radio"
class="gdoc-tabs__control hidden"
name="dashboards"
id="dashboards-1"
/>
<label for="dashboards-1" class="gdoc-tabs__label">
Grafana
</label>
<div class="gdoc-markdown--nested gdoc-tabs__content">
{{ highlight (partial "templates/grafana/dashboard.html" (dict "type" .type "alerts" .alerts "devMode" .devMode)) "json" }}
</div>
</div>
186 changes: 186 additions & 0 deletions docs/layouts/partials/templates/grafana/dashboard.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
{
"__inputs": [],
"__elements": {},
"__requires": [
{
"type": "panel",
"id": "bargauge",
"name": "Bar gauge",
"version": ""
},
{
"type": "grafana",
"id": "grafana",
"name": "Grafana",
"version": "9.5.12"
},
{
"type": "datasource",
"id": "grafana-azure-monitor-datasource",
"name": "Azure Monitor",
"version": "1.0.0"
}
],
"title": "{{ humanize .type }}",
"editable": true,
"links": [],
"liveNow": false,
"panels": [
{{ $types := slice "Log" "Metric" }}
{{ $alerts := where .alerts "visible" true }}
{{ $alerts := where $alerts "type" "in" $types }}
{{ range $idx, $value := sort $alerts "name" "asc" }}{{ if ne $idx 0}},
{{ end }} {
"title": "{{ $value.name }}",
"datasource": {
"type": "grafana-azure-monitor-datasource",
"uid": "${ds}"
},
"fieldConfig": {
"defaults": {
"color": {
"mode": "thresholds"
},
"mappings": [],
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "#808080",
"value": null
},
{
{{ if or (eq $value.properties.operator "GreaterThan") (eq $value.properties.operator "GreaterThanOrEqual") }}
"color": "dark-green",{{ else }}
"color": "dark-red",{{ end }}
"value": 0
},
{
{{ if or (eq $value.properties.operator "GreaterThan") (eq $value.properties.operator "GreaterThanOrEqual") }}
"color": "dark-red",{{ else }}
"color": "dark-green",{{ end }}
"value": {{ if $value.properites.threshold }}{{ string $value.properties.threshold }}{{ else }}0{{ end }}
}
]
}
},
"overrides": []
},
"gridPos": {
"h": 8,
"w": 12,
"x": {{ mul 12 (mod $idx 2) }},
"y": {{ mul 8 (div $idx 2) }}
},
"id": {{ add $idx 1 }},
"options": {
"displayMode": "basic",
"minVizHeight": 10,
"minVizWidth": 0,
"orientation": "horizontal",
"reduceOptions": {
"calcs": [
"lastNotNull"
],
"fields": "",
"values": true
},
"showUnfilled": true,
"valueMode": "color"
},
"pluginVersion": "9.5.12",
"targets": [
{
"azureLogAnalytics": {
{{ if eq $value.type "Log" }}
"query": {{ jsonify (replace $value.properties.query "\n" " ") }},{{ else }}
"query": "AzureMetrics\r\n| where _ResourceId has '{{ $value.properties.metricNamespace }}'\r\n| where MetricName has '{{ $value.properties.metricName }}'\r\n| summarize metric = avg({{ $value.properties.timeAggregation }}) by _ResourceId, Resource",{{ end }}
"resources": [
"/subscriptions/$sub"
]
},
"azureMonitor": {
"allowedTimeGrainsMs": [],
"timeGrain": "auto"
},
"datasource": {
"type": "grafana-azure-monitor-datasource",
"uid": "${ds}"
},
"queryType": "Azure Log Analytics",
"refId": "A"
}
],
"transformations": [
{
"id": "organize",
"options": {
"excludeByName": {
"_ResourceId": true
},
"indexByName": {},
"renameByName": {}
}
}
],
"type": "bargauge"
}{{ end }}
],
"refresh": "",
"schemaVersion": 38,
"style": "dark",
"tags": [],
"templating": {
"list": [
{
"current": {},
"hide": 0,
"includeAll": false,
"label": "Datasource",
"multi": false,
"name": "ds",
"options": [],
"query": "grafana-azure-monitor-datasource",
"queryValue": "",
"refresh": 1,
"regex": "",
"skipUrlSync": false,
"type": "datasource"
},
{
"current": {},
"datasource": {
"type": "grafana-azure-monitor-datasource",
"uid": "${ds}"
},
"definition": "",
"hide": 0,
"includeAll": false,
"label": "Subscription",
"multi": false,
"name": "sub",
"options": [],
"query": {
"azureLogAnalytics": {
"query": "",
"resources": []
},
"queryType": "Azure Subscriptions",
"refId": "A"
},
"refresh": 1,
"regex": "",
"skipUrlSync": false,
"sort": 0,
"type": "query"
}
]
},
"time": {
"from": "now-6h",
"to": "now"
},
"timepicker": {},
"timezone": "",
"version": null
}
3 changes: 3 additions & 0 deletions docs/layouts/shortcodes/alertList.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@

<br>

<h4>Dashboards:</h4>
{{ partial "templates/dashboard-tabs.html" (dict "type" $type "alerts" .alerts "devMode" $.Site.Params.ambaDevMode) }}

<!-- Create a detail entry for each alert under category/type -->
{{ range sort .alerts "name" "asc" }}
{{ if or (eq .visible true) (eq $.Site.Params.ambaDevMode true) }}
Expand Down

0 comments on commit 5a28db4

Please sign in to comment.