You need to enable JavaScript to run this app.
Cloud Monitor

Cloud Monitor

Copy page
Download PDF
SDK reference
Go usage examples
Copy page
Download PDF
Go usage examples
This topic describes the download link, installation method, and sample code of the Cloud Monitor Go SDK to help you quickly understand how to use the SDK to call APIs.​
Prerequisites​
  • You have installed a Go version from 1.12 to 1.18. You can check the current Go version by running go version.​
SDK download link​
Golang SDK download link: volcengine-go-sdk.​
Install SDK​
  1. Create a Go project and use go mod as the dependency management tool.​
  1. Configure service dependencies in go.mod.​
  • ​
    require github.com/volcengine/volcengine-go-sdk v1.0.148​
    ​
  • To download the latest version, refer to the release tag in the Github download link and replace v1.0.148 in the command with the latest version.​
Sample code​
Create a GetMetricData.go file and add the following code to query the time series data aggregated for the specified metric within the specified time range.​
​
package main​
​
import (​
"fmt"​
"github.com/volcengine/volcengine-go-sdk/service/cloudmonitor"​
"github.com/volcengine/volcengine-go-sdk/volcengine"​
"github.com/volcengine/volcengine-go-sdk/volcengine/session"​
)​
​
func main() {​
// Specify your ak.​
ak := "Your AK"​
// Specify your sk.​
sk := "Your SK"​
//Specify the region that you want to access.​
var region = "cn-beijing"​
​
//if use env Credentials​
//please​
//export VOLCSTACK_ACCESS_KEY=AK​
//export VOLCSTACK_SECRET_KEY=SK​
// and WithCredentials(credentials.NewEnvCredentials())​
config := volcengine.NewConfig().​
WithRegion(region).​
WithAkSk(ak, sk).​
//WithCredentials(credentials.NewEnvCredentials()).​
WithDisableSSL(true)​
//WithLogLevel(volcengine.LogDebugWithHTTPBody).​
sess, _ := session.NewSession(config)​
svc := cloudmonitor.New(sess)​
​
in := &cloudmonitor.GetMetricDataInput{​
EndTime: volcengine.Int32(1673272219),​
StartTime: volcengine.Int32(1673185819),​
Instances: []*cloudmonitor.InstanceForGetMetricDataInput{​
{​
Dimensions: []*cloudmonitor.DimensionForGetMetricDataInput{​
{​
Name: volcengine.String("****"),​
Value: volcengine.String("eip-rrtfrj****"),​
},​
},​
},​
},​
MetricName: volcengine.String("***"),​
Period: volcengine.String("**s"),​
Namespace: volcengine.String("***"),​
SubNamespace: volcengine.String("***"),​
}​
resp, err := svc.GetMetricData(in)​
if err != nil {​
panic(err)​
}​
fmt.Printf("Response is %v", resp)​
}​
​
​
Last updated: 2026.03.27 11:34:30