当前仓库属于关闭状态,部分功能使用受限,详情请查阅 仓库状态说明
5 Star 19 Fork 5

fangfuhaomin / promethus-vspherewebapi
关闭

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
run.go 1.73 KB
一键复制 编辑 原始数据 按行查看 历史
pidantouble 提交于 2019-12-16 08:38 . a
package main
import (
"flag"
"fmt"
"github.com/fangfuhaomin/promethus-vspherewebapi-go/esxihost"
"github.com/fangfuhaomin/promethus-vspherewebapi-go/vcconnect"
"github.com/fangfuhaomin/promethus-vspherewebapi-go/vms"
"github.com/prometheus/client_golang/prometheus/promhttp"
"log"
"net/http"
)
func main() {
var (
// 用户
user string
// 密码
password string
// 主机名
ip string
//metrics port
metricsport string
)
// StringVar用指定的名称、控制台参数项目、默认值、使用信息注册一个string类型flag,并将flag的值保存到p指向的变量
flag.StringVar(&user, "user", "", "用户名,默认为空")
flag.StringVar(&password, "password", "", "密码,默认为空")
flag.StringVar(&ip, "vcip", "127.0.0.1", "主机名,默认 127.0.0.1")
flag.StringVar(&metricsport, "metricsport", "8080", "metrics端口,默认 8080")
// 从arguments中解析注册的flag。必须在所有flag都注册好而未访问其值时执行。未注册却使用flag -help时,会返回ErrHelp。
flag.Parse()
// 打印
fmt.Printf("请使用格式 ./XXX -user XX -password XX -vcip XX -metricsport XX \n")
fmt.Printf("当前参数 -user %s -password %s -vcip%s -metricsport %s \n", user, password, ip, metricsport)
c := vcconnect.Vccon(user, password, ip).Client
fmt.Printf("web open url hostip:%s/metrics", metricsport)
go func() {
for {
vms.GetVmsInfo(c)
esxihost.GetEsxiInfo(c)
vms.GetEsxipre(c)
esxihost.GetEsxipre(c)
//time.Sleep(time.Second*30)
}
}()
// The Handler function provides a default handler to expose metrics
// via an HTTP server. "/metrics" is the usual endpoint for that.
http.Handle("/metrics", promhttp.Handler())
log.Fatal(http.ListenAndServe(":"+metricsport, nil))
}
Go
1
https://gitee.com/fangfhm/promethus-vspherewebapi.git
git@gitee.com:fangfhm/promethus-vspherewebapi.git
fangfhm
promethus-vspherewebapi
promethus-vspherewebapi
master

搜索帮助