當前位置: 首頁>>代碼示例>>Golang>>正文


Golang go-mackerel-plugin-helper.NewMackerelPlugin函數代碼示例

本文整理匯總了Golang中github.com/mackerelio/go-mackerel-plugin-helper.NewMackerelPlugin函數的典型用法代碼示例。如果您正苦於以下問題:Golang NewMackerelPlugin函數的具體用法?Golang NewMackerelPlugin怎麽用?Golang NewMackerelPlugin使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了NewMackerelPlugin函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: main

// Parse flags and Run helper (MackerelPlugin) with the given arguments.
func main() {
	// Flags
	var (
		tempfile string
		version  bool
	)

	// Define option flag parse
	flags := flag.NewFlagSet(Name, flag.ContinueOnError)
	flags.BoolVar(&version, "version", false, "Print version information and quit.")
	flags.StringVar(&tempfile, "tempfile", "/tmp/mackerel-plugin-conntrack", "Temp file name")

	// Parse commandline flag
	if err := flags.Parse(os.Args[1:]); err != nil {
		os.Exit(ExitCodeParseFlagError)
	}

	// Show version
	if version {
		fmt.Fprintf(os.Stderr, "%s version %s\n", Name, Version)
		os.Exit(ExitCodeOK)
	}

	// Create MackerelPlugin for Conntrack
	var c ConntrackPlugin
	helper := mp.NewMackerelPlugin(c)
	helper.Tempfile = tempfile

	helper.Run()
}
開發者ID:hfm,項目名稱:mackerel-plugin-conntrack,代碼行數:31,代碼來源:conntrack.go

示例2: Do

// Do the plugin
func Do() {
	optAPIKey := flag.String("api-key", "", "API Key")
	optDatabase := flag.String("database", "", "Database name")
	optIgnoreTableNames := flag.String("ignore-table", "", "Ignore Table name (Can be Comma-Separated)")
	optTempfile := flag.String("tempfile", "", "Temp file name")
	flag.Parse()

	var plugin TDTablePlugin
	plugin.APIKey = *optAPIKey
	plugin.Database = *optDatabase

	ignoreTableNames := []string{}
	if *optIgnoreTableNames != "" {
		ignoreTableNames = strings.Split(*optIgnoreTableNames, ",")
	}
	plugin.IgnoreTableNames = ignoreTableNames

	helper := mp.NewMackerelPlugin(plugin)
	helper.Tempfile = *optTempfile

	if os.Getenv("MACKEREL_AGENT_PLUGIN_META") != "" {
		helper.OutputDefinitions()
	} else {
		helper.OutputValues()
	}
}
開發者ID:supercaracal,項目名稱:mackerel-agent-plugins,代碼行數:27,代碼來源:mackerel-plugin-td-table-count.go

示例3: Run

// Run is to parse flags and Run helper (MackerelPlugin) with the given arguments.
func (c *CLI) Run(args []string) int {
	// Flags
	var (
		tempfile string
		version  bool
	)

	// Define option flag parse
	flags := flag.NewFlagSet(Name, flag.ContinueOnError)
	flags.BoolVar(&version, "version", false, "Print version information and quit.")
	flags.StringVar(&tempfile, "tempfile", "/tmp/mackerel-plugin-conntrack", "Temp file name")

	// Parse commandline flag
	if err := flags.Parse(args[1:]); err != nil {
		return ExitCodeParseFlagError
	}

	// Show version
	if version {
		fmt.Fprintf(c.errStream, "%s version %s\n", Name, Version)
		return ExitCodeOK
	}

	// Create MackerelPlugin for Conntrack
	var cp ConntrackPlugin
	helper := mp.NewMackerelPlugin(cp)
	helper.Tempfile = tempfile

	helper.Run()

	return ExitCodeOK
}
開發者ID:supercaracal,項目名稱:mackerel-agent-plugins,代碼行數:33,代碼來源:cli.go

示例4: main

func main() {
	optURI := flag.String("uri", "", "URI")
	optScheme := flag.String("scheme", "http", "Scheme")
	optHost := flag.String("host", "localhost", "Hostname")
	optPort := flag.String("port", "8080", "Port")
	optPath := flag.String("path", "/api/stats", "Path")
	optPrefix := flag.String("metric-key-prefix", "gostats", "Metric key prefix")
	optTempfile := flag.String("tempfile", "", "Temp file name")
	flag.Parse()

	gosrv := GostatsPlugin{
		Prefix: *optPrefix,
	}
	if *optURI != "" {
		gosrv.URI = *optURI
	} else {
		gosrv.URI = fmt.Sprintf("%s://%s:%s%s", *optScheme, *optHost, *optPort, *optPath)
	}

	helper := mp.NewMackerelPlugin(gosrv)
	if *optTempfile != "" {
		helper.Tempfile = *optTempfile
	} else {
		helper.Tempfile = fmt.Sprintf("/tmp/mackerel-plugin-gosrv")
	}

	helper.Run()
}
開發者ID:tjinjin,項目名稱:mackerel-agent-plugins,代碼行數:28,代碼來源:mackerel-plugin-gostats.go

示例5: main

func main() {
	optHost := flag.String("host", "localhost", "Hostname")
	optPort := flag.String("port", "27017", "Port")
	optUser := flag.String("username", "", "Username")
	optPass := flag.String("password", "", "Password")
	optVerbose := flag.Bool("v", false, "Verbose mode")
	optTempfile := flag.String("tempfile", "", "Temp file name")
	flag.Parse()

	var mongodb MongoDBPlugin
	mongodb.Verbose = *optVerbose
	if *optUser == "" && *optPass == "" {
		mongodb.Url = fmt.Sprintf("mongodb://%s:%s", *optHost, *optPort)
	} else {
		mongodb.Url = fmt.Sprintf("mongodb://%s:%[email protected]%s:%s", *optUser, *optPass, *optHost, *optPort)
	}

	helper := mp.NewMackerelPlugin(mongodb)
	if *optTempfile != "" {
		helper.Tempfile = *optTempfile
	} else {
		helper.Tempfile = fmt.Sprintf("/tmp/mackerel-plugin-mongodb-%s-%s", *optHost, *optPort)
	}

	if os.Getenv("MACKEREL_AGENT_PLUGIN_META") != "" {
		helper.OutputDefinitions()
	} else {
		helper.OutputValues()
	}
}
開發者ID:atsaki,項目名稱:mackerel-agent-plugins,代碼行數:30,代碼來源:mongodb.go

示例6: Do

// Do the plugin
func Do() {
	optHost := flag.String("host", "localhost", "Hostname")
	optPort := flag.String("port", "6379", "Port")
	optPassowrd := flag.String("password", "", "Password")
	optSocket := flag.String("socket", "", "Server socket (overrides host and port)")
	optPrefix := flag.String("metric-key-prefix", "redis", "Metric key prefix")
	optTimeout := flag.Int("timeout", 5, "Timeout")
	optTempfile := flag.String("tempfile", "", "Temp file name")
	flag.Parse()

	redis := RedisPlugin{
		Timeout: *optTimeout,
		Prefix:  *optPrefix,
	}
	if *optSocket != "" {
		redis.Socket = *optSocket
	} else {
		redis.Host = *optHost
		redis.Port = *optPort
		redis.Password = *optPassowrd
	}
	helper := mp.NewMackerelPlugin(redis)
	helper.Tempfile = *optTempfile

	if os.Getenv("MACKEREL_AGENT_PLUGIN_META") != "" {
		helper.OutputDefinitions()
	} else {
		helper.OutputValues()
	}
}
開發者ID:supercaracal,項目名稱:mackerel-agent-plugins,代碼行數:31,代碼來源:redis.go

示例7: main

func main() {
	optURI := flag.String("uri", "", "URI")
	optScheme := flag.String("scheme", "http", "Scheme")
	optHost := flag.String("host", "localhost", "Hostname")
	optPort := flag.String("port", "8080", "Port")
	optPath := flag.String("path", "/nginx_status", "Path")
	optTempfile := flag.String("tempfile", "", "Temp file name")
	optHeader := &stringSlice{}
	flag.Var(optHeader, "header", "Set http header (e.g. \"Host: servername\")")
	flag.Parse()

	var nginx NginxPlugin
	if *optURI != "" {
		nginx.URI = *optURI
	} else {
		nginx.URI = fmt.Sprintf("%s://%s:%s%s", *optScheme, *optHost, *optPort, *optPath)
	}
	nginx.Header = *optHeader

	helper := mp.NewMackerelPlugin(nginx)
	if *optTempfile != "" {
		helper.Tempfile = *optTempfile
	} else {
		helper.Tempfile = fmt.Sprintf("/tmp/mackerel-plugin-nginx")
	}
	helper.Run()
}
開發者ID:tjinjin,項目名稱:mackerel-agent-plugins,代碼行數:27,代碼來源:nginx.go

示例8: Do

// Do the plugin
func Do() {
	optHost := flag.String("host", "localhost", "Hostname")
	optPort := flag.String("port", "3306", "Port")
	optSocket := flag.String("socket", "", "Port")
	optUser := flag.String("username", "root", "Username")
	optPass := flag.String("password", "", "Password")
	optTempfile := flag.String("tempfile", "", "Temp file name")
	optInnoDB := flag.Bool("disable_innodb", false, "Disable InnoDB metrics")
	optMetricKeyPrefix := flag.String("metric-key-prefix", "mysql", "metric key prefix")
	optEnableExtended := flag.Bool("enable_extended", false, "Enable Extended metrics")
	flag.Parse()

	var mysql MySQLPlugin

	if *optSocket != "" {
		mysql.Target = *optSocket
		mysql.isUnixSocket = true
	} else {
		mysql.Target = fmt.Sprintf("%s:%s", *optHost, *optPort)
	}
	mysql.Username = *optUser
	mysql.Password = *optPass
	mysql.DisableInnoDB = *optInnoDB
	mysql.prefix = *optMetricKeyPrefix
	mysql.EnableExtended = *optEnableExtended
	helper := mp.NewMackerelPlugin(mysql)
	helper.Tempfile = *optTempfile
	helper.Run()
}
開發者ID:supercaracal,項目名稱:mackerel-agent-plugins,代碼行數:30,代碼來源:mysql.go

示例9: main

func main() {
	optHost := flag.String("host", "", "Hostname")
	optWebHost := flag.String("webhost", "", "Graphite-web hostname")
	optWebPort := flag.String("webport", "", "Graphite-web port")
	optType := flag.String("type", "", "Carbon type (cache or relay)")
	optInstance := flag.String("instance", "", "Instance name")
	optLabelPrefix := flag.String("metric-label-prefix", "Carbon", "Metric Label Prefix")
	optTempfile := flag.String("tempfile", "", "Temp file name")
	flag.Parse()

	plugin := newGraphitePlugin(*optHost, *optWebHost, *optWebPort, *optType, *optInstance, *optLabelPrefix)

	helper := mp.NewMackerelPlugin(plugin)
	if *optTempfile != "" {
		helper.Tempfile = *optTempfile
	} else {
		helper.Tempfile = "/tmp/mackerel-plugin-graphite"
	}

	if os.Getenv("MACKEREL_AGENT_PLUGIN_META") != "" {
		helper.OutputDefinitions()
	} else {
		// Not using go-mackerel-plugin-helper method
		// bacause we want to post mulitple metrics with arbitary timestamp
		plugin.outputValues(os.Stdout)
	}
}
開發者ID:tjinjin,項目名稱:mackerel-agent-plugins,代碼行數:27,代碼來源:graphite.go

示例10: main

func main() {
	optProcess := flag.String("process", "", "Process name")
	optTempfile := flag.String("tempfile", "", "Temp file name")
	flag.Parse()

	if *optProcess == "" {
		logger.Warningf("Process name is required")
		flag.PrintDefaults()
		os.Exit(1)
	}

	var fd ProcfdPlugin
	fd.Process = *optProcess
	openFd = RealOpenFd{fd.Process}
	fd.NormalizedProcess = normalizeForMetricName(*optProcess)

	helper := mp.NewMackerelPlugin(fd)
	if *optTempfile != "" {
		helper.Tempfile = *optTempfile
	} else {
		helper.Tempfile = fmt.Sprintf("/tmp/mackerel-plugin-proc-fd")
	}

	if os.Getenv("MACKEREL_AGENT_PLUGIN_META") != "" {
		helper.OutputDefinitions()
	} else {
		helper.OutputValues()
	}
}
開發者ID:netmarkjp,項目名稱:mackerel-agent-plugins,代碼行數:29,代碼來源:proc_fd.go

示例11: main

func main() {
	optHost := flag.String("host", "unix:///var/run/docker.sock", "Host for socket")
	optCommand := flag.String("command", "docker", "Command path to docker")
	optTempfile := flag.String("tempfile", "", "Temp file name")
	flag.Parse()

	var docker DockerPlugin

	docker.Host = fmt.Sprintf("%s", *optHost)
	docker.DockerCommand = *optCommand
	_, err := exec.LookPath(docker.DockerCommand)
	if err != nil {
		log.Fatalf("Docker command is not found: %s", docker.DockerCommand)
	}

	pb, err := newPathBuilder()
	if err != nil {
		log.Fatalf("failed to resolve docker metrics path: %s. It may be no Docker containers exists.", err)
	}
	docker.pathBuilder = pb

	helper := mp.NewMackerelPlugin(docker)

	if *optTempfile != "" {
		helper.Tempfile = *optTempfile
	} else {
		helper.Tempfile = fmt.Sprintf("/tmp/mackerel-plugin-docker-%s", normalizeMetricName(*optHost))
	}

	if os.Getenv("MACKEREL_AGENT_PLUGIN_META") != "" {
		helper.OutputDefinitions()
	} else {
		helper.OutputValues()
	}
}
開發者ID:yano3,項目名稱:mackerel-agent-plugins,代碼行數:35,代碼來源:docker.go

示例12: main

func main() {
	optAddress := flag.String("address", "http://localhost:8080", "URL or Unix Domain Socket")
	optPath := flag.String("path", "/_raindrops", "Path")
	optMetricKey := flag.String("metric-key-prefix", "", "Metric Key Prefix")
	optVersion := flag.Bool("version", false, "Version")
	optTempfile := flag.String("tempfile", "", "Temp file name")
	flag.Parse()

	if *optVersion {
		fmt.Println("0.3")
		os.Exit(0)
	}

	var rack RackStatsPlugin
	rack.Address = *optAddress
	rack.Path = *optPath
	rack.MetricKey = *optMetricKey

	helper := mp.NewMackerelPlugin(rack)
	if *optTempfile != "" {
		helper.Tempfile = *optTempfile
	} else {
		helper.Tempfile = fmt.Sprintf("/tmp/mackerel-plugin-rack-stats")
	}

	helper.Run()
}
開發者ID:tjinjin,項目名稱:mackerel-agent-plugins,代碼行數:27,代碼來源:rack.go

示例13: main

func main() {
	optURI := flag.String("uri", "", "URI")
	optScheme := flag.String("scheme", "http", "Scheme")
	optHost := flag.String("host", "localhost", "Hostname")
	optPort := flag.String("port", "5000", "Port")
	optPath := flag.String("path", "/server-status?json", "Path")
	optTempfile := flag.String("tempfile", "", "Temp file name")
	flag.Parse()

	var plack PlackPlugin
	if *optURI != "" {
		plack.URI = *optURI
	} else {
		plack.URI = fmt.Sprintf("%s://%s:%s%s", *optScheme, *optHost, *optPort, *optPath)
	}

	helper := mp.NewMackerelPlugin(plack)
	if *optTempfile != "" {
		helper.Tempfile = *optTempfile
	} else {
		helper.Tempfile = fmt.Sprintf("/tmp/mackerel-plugin-plack")
	}

	if os.Getenv("MACKEREL_AGENT_PLUGIN_META") != "" {
		helper.OutputDefinitions()
	} else {
		helper.OutputValues()
	}
}
開發者ID:yano3,項目名稱:mackerel-agent-plugins,代碼行數:29,代碼來源:plack.go

示例14: Do

// Do the plugin
func Do() {
	optURI := flag.String("uri", "", "URI")
	optScheme := flag.String("scheme", "http", "Scheme")
	optHost := flag.String("host", "localhost", "Hostname")
	optPort := flag.String("port", "5000", "Port")
	optPath := flag.String("path", "/server-status?json", "Path")
	optPrefix := flag.String("metric-key-prefix", "plack", "Prefix")
	optLabelPrefix := flag.String("metric-label-prefix", "", "Label Prefix")
	optTempfile := flag.String("tempfile", "", "Temp file name")
	flag.Parse()

	plack := PlackPlugin{URI: *optURI, Prefix: *optPrefix, LabelPrefix: *optLabelPrefix}
	if plack.URI == "" {
		plack.URI = fmt.Sprintf("%s://%s:%s%s", *optScheme, *optHost, *optPort, *optPath)
	}
	if plack.LabelPrefix == "" {
		plack.LabelPrefix = strings.Title(plack.Prefix)
	}

	helper := mp.NewMackerelPlugin(plack)
	if *optTempfile != "" {
		helper.Tempfile = *optTempfile
	} else {
		helper.Tempfile = fmt.Sprintf("/tmp/mackerel-plugin-plack")
	}

	if os.Getenv("MACKEREL_AGENT_PLUGIN_META") != "" {
		helper.OutputDefinitions()
	} else {
		helper.OutputValues()
	}
}
開發者ID:supercaracal,項目名稱:mackerel-agent-plugins,代碼行數:33,代碼來源:plack.go

示例15: main

func main() {
	optUri := flag.String("uri", "", "URI")
	optScheme := flag.String("scheme", "http", "Scheme")
	optHost := flag.String("host", "localhost", "Hostname")
	optPort := flag.String("port", "8080", "Port")
	optPath := flag.String("path", "/nginx_status", "Path")
	optTempfile := flag.String("tempfile", "", "Temp file name")
	optHeader := &stringSlice{}
	flag.Var(optHeader, "header", "Set http header (e.g. \"Host: servername\")")
	flag.Parse()

	var nginx NginxPlugin
	if *optUri != "" {
		nginx.Uri = *optUri
	} else {
		nginx.Uri = fmt.Sprintf("%s://%s:%s%s", *optScheme, *optHost, *optPort, *optPath)
	}
	nginx.Header = *optHeader

	helper := mp.NewMackerelPlugin(nginx)
	if *optTempfile != "" {
		helper.Tempfile = *optTempfile
	} else {
		helper.Tempfile = fmt.Sprintf("/tmp/mackerel-plugin-nginx")
	}

	if os.Getenv("MACKEREL_AGENT_PLUGIN_META") != "" {
		helper.OutputDefinitions()
	} else {
		helper.OutputValues()
	}
}
開發者ID:atsaki,項目名稱:mackerel-agent-plugins,代碼行數:32,代碼來源:nginx.go


注:本文中的github.com/mackerelio/go-mackerel-plugin-helper.NewMackerelPlugin函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。