本文整理汇总了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()
}
示例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()
}
}
示例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
}
示例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()
}
示例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()
}
}
示例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()
}
}
示例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()
}
示例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()
}
示例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)
}
}
示例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()
}
}
示例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()
}
}
示例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()
}
示例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()
}
}
示例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()
}
}
示例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()
}
}