forked from perses/perses
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
113 lines (103 loc) · 4.65 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
// Copyright 2023 The Perses Authors
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package main
import (
"flag"
"time"
"github.com/perses/perses/go-sdk"
"github.com/perses/perses/go-sdk/dashboard"
"github.com/perses/perses/go-sdk/panel"
"github.com/perses/perses/go-sdk/panel-group"
"github.com/perses/perses/go-sdk/prometheus/query"
timeSeriesPanel "github.com/perses/perses/go-sdk/panel/time-series"
promDs "github.com/perses/perses/go-sdk/prometheus/datasource"
labelNamesVar "github.com/perses/perses/go-sdk/prometheus/variable/label-names"
labelValuesVar "github.com/perses/perses/go-sdk/prometheus/variable/label-values"
promqlVar "github.com/perses/perses/go-sdk/prometheus/variable/promql"
listVar "github.com/perses/perses/go-sdk/variable/list-variable"
txtVar "github.com/perses/perses/go-sdk/variable/text-variable"
)
func main() {
flag.Parse()
exec := sdk.NewExec()
builder, buildErr := dashboard.New("ContainersMonitoring",
dashboard.ProjectName("MyProject"),
dashboard.RefreshInterval(1*time.Minute),
// VARIABLES
dashboard.AddVariable("stack",
listVar.List(
labelValuesVar.PrometheusLabelValues("stack",
labelValuesVar.Matchers("thanos_build_info{}"),
labelValuesVar.Datasource("promDemo"),
),
listVar.DisplayName("PaaS"),
),
),
dashboard.AddVariable("prometheus",
txtVar.Text("platform", txtVar.Constant(true)),
),
dashboard.AddVariable("prometheus_namespace",
txtVar.Text("observability",
txtVar.Constant(true),
txtVar.Description("constant to reduce the query scope thus improve performances"),
),
),
dashboard.AddVariable("namespace", listVar.List(
promqlVar.PrometheusPromQL("group by (namespace) (kube_namespace_labels{stack=\"$stack\",prometheus=\"$prometheus\",prometheus_namespace=\"$prometheus_namespace\"})", promqlVar.Datasource("promDemo")),
listVar.AllowMultiple(true),
)),
dashboard.AddVariable("namespaceLabels", listVar.List(
labelNamesVar.PrometheusLabelNames(
labelNamesVar.Matchers("kube_namespace_labels{stack=\"$stack\",prometheus=\"$prometheus\",prometheus_namespace=\"$prometheus_namespace\",namespace=\"$namespace\"}"),
labelNamesVar.Datasource("promDemo"),
),
)),
dashboard.AddVariable("pod", listVar.List(
promqlVar.PrometheusPromQL("group by (pod) (kube_pod_info{stack=\"$stack\",prometheus=\"$prometheus\",prometheus_namespace=\"$prometheus_namespace\",namespace=\"$namespace\"})", promqlVar.Datasource("promDemo")),
listVar.AllowMultiple(true),
listVar.AllowAllValue(true),
)),
dashboard.AddVariable("container", listVar.List(
promqlVar.PrometheusPromQL("group by (container) (kube_pod_container_info{stack=\"$stack\",prometheus=\"$prometheus\",prometheus_namespace=\"$prometheus_namespace\",namespace=\"$namespace\",pod=\"$pod\"})", promqlVar.Datasource("promDemo")),
listVar.AllowMultiple(true),
listVar.AllowAllValue(true),
)),
dashboard.AddVariable("containerLabels", listVar.List(
listVar.Description("simply the list of labels for the considered metric"),
listVar.Hidden(true),
labelNamesVar.PrometheusLabelNames(
labelNamesVar.Matchers("kube_pod_container_info{stack=\"$stack\",prometheus=\"$prometheus\",prometheus_namespace=\"$prometheus_namespace\",namespace=\"$namespace\",pod=\"$pod\",container=\"$container\"}"),
labelNamesVar.Datasource("promDemo"),
),
)),
// ROWS
dashboard.AddPanelGroup("Resource usage",
panelgroup.PanelsPerLine(3),
// PANELS
panelgroup.AddPanel("Container memory",
timeSeriesPanel.Chart(),
panel.AddQuery(
query.PromQL("max by (container) (container_memory_rss{stack=\"$stack\",prometheus=\"$prometheus\",prometheus_namespace=\"$prometheus_namespace\",namespace=\"$namespace\",pod=\"$pod\",container=\"$container\"})"),
),
),
panelgroup.AddPanel("Container CPU",
timeSeriesPanel.Chart(),
panel.AddQuery(
query.PromQL("sum (container_cpu_usage_seconds{stack=\"$stack\",prometheus=\"$prometheus\",prometheus_namespace=\"$prometheus_namespace\",namespace=\"$namespace\",pod=\"$pod\",container=\"$container\"})"),
),
),
),
dashboard.AddDatasource("promDemo", promDs.Prometheus(promDs.HTTPProxy("#####"))),
)
exec.BuildDashboard(builder, buildErr)
}