You need to enable JavaScript to run this app.
文档中心
云监控

云监控

复制全文
下载 pdf
SDK 参考
Go 使用示例
复制全文
下载 pdf
Go 使用示例
本文为您介绍云监控 Go SDK 的下载地址、安装方式以及代码示例,帮助您快速了解如何使用 SDK 调用 OpenAPI。​
前提条件​
  • 已安装 Go 1.12~1.18 版本,执行go version可以检查当前 Go 版本信息。​
SDK 下载地址​
Golang SDK 下载地址:volcengine-go-sdk 。​
安装 SDK​
  1. 新建一个 Go 项目,使用 go mod 作为软件依赖工具。​
  1. 在go.mod中设置服务依赖。​
  • ​
    require github.com/volcengine/volcengine-go-sdk v1.0.148​
    ​
  • 如需下载最新版本,请参考 Github 下载地址中的 release tag,替换命令中 v1.0.148 为最新版本。​
代码示例​
新建GetMetricData.go文件,添加如下代码,查询指定指标在指定时间选段内聚合的时序数据。​
​
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() {​
// 设置您的ak​
ak := "Your AK"​
// 设置您的sk​
sk := "Your SK"​
// 设置您要访问的地域​
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)​
}​
​
​
最近更新时间:2025.12.04 10:10:09
这个页面对您有帮助吗?
有用
有用
无用
无用