-
-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #44 from K-Phoen/yaml-unmarshall
Yaml unmarshall
- Loading branch information
Showing
31 changed files
with
1,681 additions
and
361 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
title: Awesome dashboard | ||
|
||
editable: true | ||
shared_crosshair: true | ||
tags: [generated, yaml] | ||
auto_refresh: 10s | ||
|
||
tags_annotations: | ||
- name: Deployments | ||
datasource: "-- Grafana --" | ||
color: "#5794F2" | ||
tags: ["deploy", "production"] | ||
|
||
variables: | ||
- interval: | ||
name: interval | ||
label: Interval | ||
values: ["30s", "1m", "5m", "10m", "30m", "1h", "6h", "12h"] | ||
- query: | ||
name: status | ||
label: HTTP status | ||
datasource: prometheus-default | ||
request: "label_values(prometheus_http_requests_total, code)" | ||
- const: | ||
name: percentile | ||
label: Percentile | ||
default: 80 | ||
values_map: | ||
50th: "50" | ||
75th: "75" | ||
80th: "80" | ||
85th: "85" | ||
90th: "90" | ||
95th: "95" | ||
99th: "99" | ||
- custom: | ||
name: vX | ||
default: v2 | ||
values_map: | ||
v1: v1 | ||
v2: v2 | ||
|
||
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}}" | ||
ref: A | ||
- table: | ||
title: Threads | ||
datasource: prometheus-default | ||
targets: | ||
- prometheus: | ||
query: "go_threads" | ||
hidden_columns: ["Time"] | ||
time_series_aggregations: | ||
- label: AVG | ||
type: avg | ||
- label: Current | ||
type: current | ||
- single_stat: | ||
title: Heap Allocations | ||
datasource: prometheus-default | ||
targets: | ||
- prometheus: | ||
query: 'go_memstats_heap_alloc_bytes{job="prometheus"}' | ||
unit: bytes | ||
thresholds: ["26000000", "28000000"] | ||
color: ["value"] | ||
|
||
- name: "Some text, because it might be useful" | ||
panels: | ||
- text: | ||
title: Some awesome text? | ||
markdown: "Markdown syntax help: [commonmark.org/help](https://commonmark.org/help/)\n${percentile}" | ||
- text: | ||
title: Some awesome html? | ||
html: "Some <b>awesome</b> html?" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package main | ||
|
||
import ( | ||
"bytes" | ||
"context" | ||
"fmt" | ||
"io/ioutil" | ||
"net/http" | ||
"os" | ||
|
||
"github.com/K-Phoen/grabana" | ||
"github.com/K-Phoen/grabana/decoder" | ||
) | ||
|
||
func main() { | ||
if len(os.Args) != 4 { | ||
fmt.Fprint(os.Stderr, "Usage: go run -mod=vendor main.go file http://grafana-host:3000 api-key\n") | ||
os.Exit(1) | ||
} | ||
|
||
content, err := ioutil.ReadFile(os.Args[1]) | ||
if err != nil { | ||
fmt.Fprintf(os.Stderr, "Could not read file: %s\n", err) | ||
os.Exit(1) | ||
} | ||
|
||
dashboard, err := decoder.UnmarshalYAML(bytes.NewBuffer(content)) | ||
if err != nil { | ||
fmt.Fprintf(os.Stderr, "Could not parse file: %s\n", err) | ||
os.Exit(1) | ||
} | ||
|
||
ctx := context.Background() | ||
client := grabana.NewClient(&http.Client{}, os.Args[2], os.Args[3]) | ||
|
||
// create the folder holding the dashboard for the service | ||
folder, err := client.GetFolderByTitle(ctx, "Test Folder") | ||
if err != nil && err != grabana.ErrFolderNotFound { | ||
fmt.Printf("Could not create folder: %s\n", err) | ||
os.Exit(1) | ||
} | ||
if folder == nil { | ||
folder, err = client.CreateFolder(ctx, "Test Folder") | ||
if err != nil { | ||
fmt.Printf("Could not create folder: %s\n", err) | ||
os.Exit(1) | ||
} | ||
|
||
fmt.Printf("Folder created (id: %d, uid: %s)\n", folder.ID, folder.UID) | ||
} | ||
|
||
if _, err := client.UpsertDashboard(ctx, folder, dashboard); err != nil { | ||
fmt.Printf("Could not create dashboard: %s\n", err) | ||
os.Exit(1) | ||
} | ||
|
||
fmt.Println("The deed is done.") | ||
} |
Oops, something went wrong.