代码拉取完成,页面将自动刷新
同步操作将从 inrgihc/greenplum_exporter 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
package main
import (
"greenplum-exporter/collector"
"github.com/prometheus/client_golang/prometheus"
logger "github.com/prometheus/common/log"
"github.com/prometheus/client_golang/prometheus/promhttp"
"gopkg.in/alecthomas/kingpin.v2"
"net/http"
)
/**
* 参考教程:https://www.cnblogs.com/momoyan/p/9943268.html
* 官方文档:https://godoc.org/github.com/prometheus/client_golang/prometheus
* 官方文档:https://gp-docs-cn.github.io/docs/admin_guide/monitoring/monitoring.html
*/
var (
listenAddress = kingpin.Flag("web.listen-address", "web endpoint").Default("0.0.0.0:9297").String()
metricPath = kingpin.Flag("web.telemetry-path", "Path under which to expose metrics.").Default("/metrics").String()
disableDefaultMetrics = kingpin.Flag("disableDefaultMetrics", "do not report default metrics(go metrics and process metrics)").Default("true").Bool()
)
var scrapers = map[collector.Scraper]bool{
collector.NewLocksScraper(): true,
collector.NewClusterStateScraper(): true,
collector.NewDatabaseSizeScraper(): true,
collector.NewConnectionsScraper(): true,
collector.NewMaxConnScraper(): true,
collector.NewSegmentScraper(): true,
collector.NewConnDetailScraper(): true,
collector.NewUsersScraper(): true,
collector.NewBgWriterStateScraper(): true,
collector.NewSystemScraper(): false,
collector.NewQueryScraper(): false,
collector.NewDynamicMemoryScraper(): false,
collector.NewDiskScraper(): false,
}
var gathers prometheus.Gatherers
func main() {
kingpin.Version("1.1.1")
kingpin.HelpFlag.Short('h')
logger.AddFlags(kingpin.CommandLine)
kingpin.Parse()
metricsHandleFunc := newHandler(*disableDefaultMetrics, scrapers)
mux := http.NewServeMux()
mux.HandleFunc(*metricPath, metricsHandleFunc)
logger.Warnf("Greenplum exporter is starting and will listening on : %s", *listenAddress)
logger.Error(http.ListenAndServe(*listenAddress, mux).Error())
}
func newHandler(disableDefaultMetrics bool, scrapers map[collector.Scraper]bool) http.HandlerFunc {
registry := prometheus.NewRegistry()
enabledScrapers := make([]collector.Scraper, 0, 16)
for scraper, enable := range scrapers {
if enable {
enabledScrapers = append(enabledScrapers, scraper)
}
}
greenPlumCollector := collector.NewCollector(enabledScrapers)
registry.MustRegister(greenPlumCollector)
if disableDefaultMetrics {
gathers = prometheus.Gatherers{registry}
} else {
gathers = prometheus.Gatherers{registry, prometheus.DefaultGatherer}
}
handler := promhttp.HandlerFor(gathers, promhttp.HandlerOpts{
ErrorHandling: promhttp.ContinueOnError,
})
return handler.ServeHTTP
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。