-
Notifications
You must be signed in to change notification settings - Fork 54
/
CreateDashboard_765140092.go
78 lines (72 loc) · 2.54 KB
/
CreateDashboard_765140092.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
// Create a new dashboard with a query value widget using timeseries background
package main
import (
"context"
"encoding/json"
"fmt"
"os"
"github.com/DataDog/datadog-api-client-go/v2/api/datadog"
"github.com/DataDog/datadog-api-client-go/v2/api/datadogV1"
)
func main() {
body := datadogV1.Dashboard{
LayoutType: datadogV1.DASHBOARDLAYOUTTYPE_ORDERED,
Title: "Example-Dashboard with QVW Timeseries Background",
Widgets: []datadogV1.Widget{
{
Definition: datadogV1.WidgetDefinition{
QueryValueWidgetDefinition: &datadogV1.QueryValueWidgetDefinition{
TitleSize: datadog.PtrString("16"),
Title: datadog.PtrString(""),
TitleAlign: datadogV1.WIDGETTEXTALIGN_LEFT.Ptr(),
Precision: datadog.PtrInt64(2),
Time: &datadogV1.WidgetTime{},
Autoscale: datadog.PtrBool(true),
Requests: []datadogV1.QueryValueWidgetRequest{
{
Formulas: []datadogV1.WidgetFormula{
{
Formula: "query1",
},
},
ResponseFormat: datadogV1.FORMULAANDFUNCTIONRESPONSEFORMAT_SCALAR.Ptr(),
Queries: []datadogV1.FormulaAndFunctionQueryDefinition{
datadogV1.FormulaAndFunctionQueryDefinition{
FormulaAndFunctionMetricQueryDefinition: &datadogV1.FormulaAndFunctionMetricQueryDefinition{
Query: "sum:my.cool.count.metric{*}",
DataSource: datadogV1.FORMULAANDFUNCTIONMETRICDATASOURCE_METRICS,
Name: "query1",
Aggregator: datadogV1.FORMULAANDFUNCTIONMETRICAGGREGATION_PERCENTILE.Ptr(),
}},
},
},
},
Type: datadogV1.QUERYVALUEWIDGETDEFINITIONTYPE_QUERY_VALUE,
TimeseriesBackground: &datadogV1.TimeseriesBackground{
Type: datadogV1.TIMESERIESBACKGROUNDTYPE_AREA,
Yaxis: &datadogV1.WidgetAxis{
IncludeZero: datadog.PtrBool(true),
},
},
}},
Layout: &datadogV1.WidgetLayout{
Y: 0,
X: 0,
Height: 2,
Width: 2,
},
},
},
}
ctx := datadog.NewDefaultContext(context.Background())
configuration := datadog.NewConfiguration()
apiClient := datadog.NewAPIClient(configuration)
api := datadogV1.NewDashboardsApi(apiClient)
resp, r, err := api.CreateDashboard(ctx, body)
if err != nil {
fmt.Fprintf(os.Stderr, "Error when calling `DashboardsApi.CreateDashboard`: %v\n", err)
fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r)
}
responseContent, _ := json.MarshalIndent(resp, "", " ")
fmt.Fprintf(os.Stdout, "Response from `DashboardsApi.CreateDashboard`:\n%s\n", responseContent)
}