2 Star 3 Fork 0

telemetry_devops/ucloud_kafka_exporter

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
main.go 2.00 KB
一键复制 编辑 原始数据 按行查看 历史
蓝宝石的傻话 提交于 2021-09-06 18:33 . go 1.17
package main
import (
"net/http"
"github.com/prometheus/client_golang/prometheus/promhttp"
plog "github.com/prometheus/common/log"
"github.com/prometheus/common/version"
"gopkg.in/alecthomas/kingpin.v2"
"gitee.com/monitor_dev/ucloud_kafka_exporter/ucloud"
)
var (
versions string
buildUser string = "MickeyZZC"
buildData string
branch string
)
func main() {
var (
listenAddress = kingpin.Flag("web.listen-address", "Address to listen on for web interface and telemetry.").Default(":59308").String()
metricsPath = kingpin.Flag("web.telemetry-path", "Path under which to expose metrics.").Default("/metrics").String()
ucloudPrivateKey = kingpin.Flag("ucloud.privatekey", "Ucloud api PrivateKey.").Default("").String()
ucloudPublicKey = kingpin.Flag("ucloud.publickey", "Ucloud api PublicKey.").Default("").String()
//reload time
ucloudKafkaReload = kingpin.Flag("ucloud.kafkaReload", "Ucloud kafka resource reload interval time,units of minutes,default 100 min").Default("100").Int()
ucloudKafkaProjectID = kingpin.Flag("ucloud.projectID", "Ucloud projectID").Default("all").String()
)
version.Version = versions
version.BuildUser = buildUser
version.BuildDate = buildData
version.Branch = branch
kingpin.Version(version.Print("ucloud_kafka_exporter"))
kingpin.HelpFlag.Short('h')
kingpin.Parse()
var resource = ucloud.NewResource()
resource.Registry(*ucloudPrivateKey, *ucloudPublicKey)
err := resource.Update()
if err != nil {
plog.Fatal(err.Error())
}
go ucloud.Collector(resource, ucloudKafkaReload, *ucloudKafkaProjectID)
http.Handle(*metricsPath, promhttp.Handler())
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte(`<html>
<head><title>Ucloud Kafka Exporter</title></head>
<body>
<h1>Ucloud Kafka Exporter</h1>
<p><a href='` + *metricsPath + `'>Metrics</a></p>
</body>
</html>`))
})
plog.Infoln("Listening on", *listenAddress)
plog.Fatal(http.ListenAndServe(*listenAddress, nil))
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/monitor_dev/ucloud_kafka_exporter.git
[email protected]:monitor_dev/ucloud_kafka_exporter.git
monitor_dev
ucloud_kafka_exporter
ucloud_kafka_exporter
master

搜索帮助