2018-10-05 21:43:01 +00:00
|
|
|
package inputs
|
|
|
|
|
|
|
|
import (
|
2018-10-17 19:51:35 +00:00
|
|
|
"errors"
|
2018-10-05 21:43:01 +00:00
|
|
|
"fmt"
|
|
|
|
"strconv"
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Nginx is based on telegraf nginx plugin.
|
|
|
|
type Nginx struct {
|
2018-10-16 00:38:36 +00:00
|
|
|
baseInput
|
2018-10-17 19:51:35 +00:00
|
|
|
URLs []string `json:"urls"`
|
2018-10-05 21:43:01 +00:00
|
|
|
}
|
|
|
|
|
2018-10-16 00:38:36 +00:00
|
|
|
// PluginName is based on telegraf plugin name.
|
|
|
|
func (n *Nginx) PluginName() string {
|
|
|
|
return "nginx"
|
|
|
|
}
|
|
|
|
|
2018-10-05 21:43:01 +00:00
|
|
|
// TOML encodes to toml string
|
|
|
|
func (n *Nginx) TOML() string {
|
|
|
|
s := make([]string, len(n.URLs))
|
2018-10-05 21:43:01 +00:00
|
|
|
for k, v := range n.URLs {
|
2018-10-05 21:43:01 +00:00
|
|
|
s[k] = strconv.Quote(v)
|
|
|
|
}
|
2018-10-16 00:38:36 +00:00
|
|
|
return fmt.Sprintf(`[[inputs.%s]]
|
2018-10-05 21:43:01 +00:00
|
|
|
# An array of Nginx stub_status URI to gather stats.
|
2018-10-05 21:43:01 +00:00
|
|
|
# exp http://localhost/server_status
|
2018-10-05 21:43:01 +00:00
|
|
|
urls = [%s]
|
2018-10-16 00:38:36 +00:00
|
|
|
`, n.PluginName(), strings.Join(s, ", "))
|
2018-10-05 21:43:01 +00:00
|
|
|
}
|
2018-10-17 19:51:35 +00:00
|
|
|
|
|
|
|
// UnmarshalTOML decodes the parsed data to the object
|
|
|
|
func (n *Nginx) UnmarshalTOML(data interface{}) error {
|
|
|
|
dataOK, ok := data.(map[string]interface{})
|
|
|
|
if !ok {
|
|
|
|
return errors.New("bad urls for nginx input plugin")
|
|
|
|
}
|
|
|
|
urls, ok := dataOK["urls"].([]interface{})
|
|
|
|
if !ok {
|
|
|
|
return errors.New("urls is not an array for nginx input plugin")
|
|
|
|
}
|
|
|
|
for _, url := range urls {
|
|
|
|
n.URLs = append(n.URLs, url.(string))
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|