From 483e3179288aed32b2f70e11b1679f9f97ee46a8 Mon Sep 17 00:00:00 2001 From: lufia Date: Mon, 12 Dec 2022 18:02:52 +0900 Subject: [PATCH 1/6] remove plugins from packaging/config.json --- README.md | 4 ---- mackerel-plugin_gen.go | 12 ------------ packaging/config.json | 3 --- 3 files changed, 19 deletions(-) diff --git a/README.md b/README.md index fc9180387..012d3c3ca 100644 --- a/README.md +++ b/README.md @@ -25,9 +25,7 @@ Documentation for each plugin is located in its respective sub directory. * [mackerel-plugin-docker](./mackerel-plugin-docker/README.md) * [mackerel-plugin-elasticsearch](./mackerel-plugin-elasticsearch/README.md) * [mackerel-plugin-fluentd](./mackerel-plugin-fluentd/README.md) -* [mackerel-plugin-flume](./mackerel-plugin-flume/README.md) * [mackerel-plugin-gostats](./mackerel-plugin-gostats/README.md) -* [mackerel-plugin-graphite](./mackerel-plugin-graphite/README.md) * [mackerel-plugin-h2o](./mackerel-plugin-h2o/README.md) * [mackerel-plugin-haproxy](./mackerel-plugin-haproxy/README.md) * [mackerel-plugin-inode](./mackerel-plugin-inode/README.md) @@ -41,7 +39,6 @@ Documentation for each plugin is located in its respective sub directory. * [mackerel-plugin-mssql](./mackerel-plugin-mssql/README.md) * [mackerel-plugin-multicore](./mackerel-plugin-multicore/README.md) * [mackerel-plugin-munin](./mackerel-plugin-munin/README.md) -* [mackerel-plugin-murmur](./mackerel-plugin-murmur/README.md) * [mackerel-plugin-mysql](./mackerel-plugin-mysql/README.md) * [mackerel-plugin-nginx](./mackerel-plugin-nginx/README.md) * [mackerel-plugin-openldap](./mackerel-plugin-openldap/README.md) @@ -68,7 +65,6 @@ Documentation for each plugin is located in its respective sub directory. * [mackerel-plugin-varnish](./mackerel-plugin-varnish/README.md) * [mackerel-plugin-windows-process-stats](./mackerel-plugin-windows-process-stats/README.md) * [mackerel-plugin-windows-server-sessions](./mackerel-plugin-windows-server-sessions/README.md) -* [mackerel-plugin-xentop](./mackerel-plugin-xentop/README.md) Installation ============ diff --git a/mackerel-plugin_gen.go b/mackerel-plugin_gen.go index d924e172b..c02f62235 100644 --- a/mackerel-plugin_gen.go +++ b/mackerel-plugin_gen.go @@ -22,9 +22,7 @@ import ( "github.com/mackerelio/mackerel-agent-plugins/mackerel-plugin-docker/lib" "github.com/mackerelio/mackerel-agent-plugins/mackerel-plugin-elasticsearch/lib" "github.com/mackerelio/mackerel-agent-plugins/mackerel-plugin-fluentd/lib" - "github.com/mackerelio/mackerel-agent-plugins/mackerel-plugin-flume/lib" "github.com/mackerelio/mackerel-agent-plugins/mackerel-plugin-gostats/lib" - "github.com/mackerelio/mackerel-agent-plugins/mackerel-plugin-graphite/lib" "github.com/mackerelio/mackerel-agent-plugins/mackerel-plugin-h2o/lib" "github.com/mackerelio/mackerel-agent-plugins/mackerel-plugin-haproxy/lib" "github.com/mackerelio/mackerel-agent-plugins/mackerel-plugin-inode/lib" @@ -58,7 +56,6 @@ import ( "github.com/mackerelio/mackerel-agent-plugins/mackerel-plugin-uptime/lib" "github.com/mackerelio/mackerel-agent-plugins/mackerel-plugin-uwsgi-vassal/lib" "github.com/mackerelio/mackerel-agent-plugins/mackerel-plugin-varnish/lib" - "github.com/mackerelio/mackerel-agent-plugins/mackerel-plugin-xentop/lib" ) func runPlugin(plug string) error { @@ -99,12 +96,8 @@ func runPlugin(plug string) error { mpelasticsearch.Do() case "fluentd": mpfluentd.Do() - case "flume": - mpflume.Do() case "gostats": mpgostats.Do() - case "graphite": - mpgraphite.Do() case "h2o": mph2o.Do() case "haproxy": @@ -171,8 +164,6 @@ func runPlugin(plug string) error { mpuwsgivassal.Do() case "varnish": mpvarnish.Do() - case "xentop": - mpxentop.Do() default: return fmt.Errorf("unknown plugin: %q", plug) } @@ -198,9 +189,7 @@ var plugins = []string{ "docker", "elasticsearch", "fluentd", - "flume", "gostats", - "graphite", "h2o", "haproxy", "inode", @@ -234,5 +223,4 @@ var plugins = []string{ "uptime", "uwsgi-vassal", "varnish", - "xentop", } diff --git a/packaging/config.json b/packaging/config.json index 343dc8288..5f1776e67 100644 --- a/packaging/config.json +++ b/packaging/config.json @@ -15,9 +15,7 @@ "aws-s3-requests", "conntrack", "elasticsearch", - "flume", "gostats", - "graphite", "haproxy", "jmx-jolokia", "jvm", @@ -47,7 +45,6 @@ "twemproxy", "uwsgi-vassal", "varnish", - "xentop", "aws-cloudfront", "aws-ec2-ebs", "fluentd", From de17880982a24f69b76f2aaaca00adbf40d9654c Mon Sep 17 00:00:00 2001 From: lufia Date: Mon, 12 Dec 2022 18:11:51 +0900 Subject: [PATCH 2/6] remove mackerel-plugin-graphite --- mackerel-plugin-graphite/README.md | 35 +-- mackerel-plugin-graphite/go.mod | 12 + mackerel-plugin-graphite/go.sum | 22 ++ mackerel-plugin-graphite/lib/cache_meta.go | 58 ---- mackerel-plugin-graphite/lib/graphite.go | 269 ------------------ mackerel-plugin-graphite/lib/graphite_test.go | 186 ------------ mackerel-plugin-graphite/lib/meta.go | 6 - mackerel-plugin-graphite/lib/metrics.go | 115 -------- mackerel-plugin-graphite/lib/metrics_test.go | 106 ------- mackerel-plugin-graphite/lib/relay_meta.go | 34 --- mackerel-plugin-graphite/main.go | 2 +- t/convention.t | 1 + 12 files changed, 38 insertions(+), 808 deletions(-) create mode 100644 mackerel-plugin-graphite/go.mod create mode 100644 mackerel-plugin-graphite/go.sum delete mode 100644 mackerel-plugin-graphite/lib/cache_meta.go delete mode 100644 mackerel-plugin-graphite/lib/graphite.go delete mode 100644 mackerel-plugin-graphite/lib/graphite_test.go delete mode 100644 mackerel-plugin-graphite/lib/meta.go delete mode 100644 mackerel-plugin-graphite/lib/metrics.go delete mode 100644 mackerel-plugin-graphite/lib/metrics_test.go delete mode 100644 mackerel-plugin-graphite/lib/relay_meta.go diff --git a/mackerel-plugin-graphite/README.md b/mackerel-plugin-graphite/README.md index 493079d2d..749bb39e2 100644 --- a/mackerel-plugin-graphite/README.md +++ b/mackerel-plugin-graphite/README.md @@ -1,37 +1,6 @@ mackerel-plugin-graphite =================== -Graphite carbon custom metrics plugin for mackerel.io agent. - -## Synopsis - -This plugin posts metrics that carbon-cache and carbon-relay collect themselves. -carbon-aggregator is not implemented. -It posts all metrics which were collected by 15 minutes because of reflection delay. - -```shell -mackerel-plugin-graphite -host= -webhost= -webport= -type=(cache or relay) (-instance= -metric-label-prefix=) -``` - -## Example of mackerel-agent.conf - -### carbon-cache - -``` -[plugin.metrics.graphite-carbon] -command = "/path/to/mackerel-plugin-graphite -host=127.0.0.1 -webhost=hostname -port=8000 -type=cache" -``` - -You don't need specify instance option. -This plugin automatically attaches `*` to instance name which means all instances of existing. - - -### carbon-relay - -``` -[plugin.metrics.graphite-carbon] -command = "/path/to/mackerel-plugin-graphite -host=127.0.0.1 -webhost=hostname -port=8000 -type=relay -instance=a" -``` - -If you use carbon-relay, you must specify instance option. +This plugin moved to [mackerelio/mackerel-plugin-graphite][url] +[url]: https://github.com/mackerelio/mackerel-plugin-graphite diff --git a/mackerel-plugin-graphite/go.mod b/mackerel-plugin-graphite/go.mod new file mode 100644 index 000000000..4fdb8fc5f --- /dev/null +++ b/mackerel-plugin-graphite/go.mod @@ -0,0 +1,12 @@ +module github.com/mackerelio/mackerel-agent-plugins/mackerel-plugin-graphite + +go 1.19 + +require github.com/mackerelio/mackerel-plugin-graphite v1.0.0 + +require ( + github.com/mackerelio/go-mackerel-plugin-helper v0.1.2 // indirect + github.com/mackerelio/golib v1.2.1 // indirect + golang.org/x/lint v0.0.0-20210508222113-6edffad5e616 // indirect + golang.org/x/tools v0.1.5 // indirect +) diff --git a/mackerel-plugin-graphite/go.sum b/mackerel-plugin-graphite/go.sum new file mode 100644 index 000000000..d15f16489 --- /dev/null +++ b/mackerel-plugin-graphite/go.sum @@ -0,0 +1,22 @@ +github.com/mackerelio/go-mackerel-plugin-helper v0.1.2 h1:p/KTlMK/mocWAIjNuYzpCybYvkfAEroDZBDAiOuz2QQ= +github.com/mackerelio/go-mackerel-plugin-helper v0.1.2/go.mod h1:Vfs2Fk1FfE8c8mufAQKcWBtGI0GCrOLGvaJg+kS5yz4= +github.com/mackerelio/golib v1.2.1 h1:SDcDn6Jw3p9bi1N0bg1Z/ilG5qcBB23qL8xNwrU0gg4= +github.com/mackerelio/golib v1.2.1/go.mod h1:b8ZaapsHGH1FlEJlCqfD98CqafLeyMevyATDlID2BsM= +github.com/mackerelio/mackerel-plugin-graphite v1.0.0 h1:2vo1MpZIuUYPRr1rHYp9a2qgFMtniFGGbxyVemg9mh0= +github.com/mackerelio/mackerel-plugin-graphite v1.0.0/go.mod h1:Mdj5nfc2UvMBgjZSbNNm7+QPicPMrs5lkuUH+7moOP4= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/lint v0.0.0-20210508222113-6edffad5e616 h1:VLliZ0d+/avPrXXH+OakdXhpJuEoBZuwh1m2j7U6Iug= +golang.org/x/lint v0.0.0-20210508222113-6edffad5e616/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY= +golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg= +golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20220319134239-a9b59b0215f8 h1:OH54vjqzRWmbJ62fjuhxy7AxFFgoHN0/DPc/UrL8cAs= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/tools v0.0.0-20200130002326-2f3ba24bd6e7/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.1.5 h1:ouewzE6p+/VEB31YYnTbEJdi8pFqKp4P4n85vwo3DHA= +golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= +golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= diff --git a/mackerel-plugin-graphite/lib/cache_meta.go b/mackerel-plugin-graphite/lib/cache_meta.go deleted file mode 100644 index 8ddb93ff3..000000000 --- a/mackerel-plugin-graphite/lib/cache_meta.go +++ /dev/null @@ -1,58 +0,0 @@ -package mpgraphite - -var cachePrefix = "graphite-carbon.cache." - -var cacheMeta = map[string]meta{ - "avgUpdateTime": { - label: " Average Update Time", - unit: "float", - }, - "committedPoints": { - label: " Committed Points", - unit: "integer", - }, - "cpuUsage": { - label: " CPU Usage", - unit: "float", - }, - "creates": { - label: " Creates", - unit: "integer", - }, - "errors": { - label: " Errors", - unit: "integer", - }, - "memUsage": { - label: " Memory Usage", - unit: "integer", - }, - "metricsReceived": { - label: " Metrics Received", - unit: "integer", - }, - "pointsPerUpdate": { - label: " Points Per Update", - unit: "float", - }, - "updateOperations": { - label: " Update Operations", - unit: "integer", - }, - "cache_overflow": { - label: " Overflow", - unit: "integer", - }, - "cache_queries": { - label: " Queries", - unit: "integer", - }, - "cache_queues": { - label: " Queues", - unit: "integer", - }, - "cache_size": { - label: " Size", - unit: "integer", - }, -} diff --git a/mackerel-plugin-graphite/lib/graphite.go b/mackerel-plugin-graphite/lib/graphite.go deleted file mode 100644 index f57989aa2..000000000 --- a/mackerel-plugin-graphite/lib/graphite.go +++ /dev/null @@ -1,269 +0,0 @@ -package mpgraphite - -import ( - "encoding/json" - "flag" - "fmt" - "io" - "io/ioutil" - "log" - "net/http" - "os" - "strings" - - mp "github.com/mackerelio/go-mackerel-plugin-helper" -) - -// GraphitePlugin is plugin for Graphite -type GraphitePlugin struct { - Host string - WebHost string - WebPort string - Type string - Instance string - LabelPrefix string - URL string -} - -// GraphDefinition interface for mackerelplugin -func (p GraphitePlugin) GraphDefinition() map[string]mp.Graphs { - var graphdef map[string]mp.Graphs - switch p.Type { - case "cache": - graphdef = p.cacheGraphDefinition() - case "relay": - graphdef = p.relayGraphDefinition() - } - return graphdef -} - -// cacheGraphDefinition returns Graphs for carbon-cache -func (p GraphitePlugin) cacheGraphDefinition() map[string]mp.Graphs { - data, err := p.fetchData() - if err != nil { - log.Fatalln(err) - } - - set := make(map[string]struct{}) - for _, m := range data { - instance := m.getInstanceName() - if !m.isDataAllNil() { - set[instance] = struct{}{} - } - } - - graphdef := make(map[string]mp.Graphs) - for key, m := range cacheMeta { - var ms []mp.Metrics - - var thetype string - if m.unit == "float" { - thetype = "float64" - } else { - thetype = "uint64" - } - - for instance := range set { - ms = append(ms, mp.Metrics{ - Name: instance, - Label: instance, - Type: thetype, - }) - } - - graphdef[cachePrefix+key] = mp.Graphs{ - Label: p.LabelPrefix + m.label, - Unit: m.unit, - Metrics: ms, - } - } - - return graphdef -} - -// relayGraphDefinition returns Graphs for carbon-relay -func (p GraphitePlugin) relayGraphDefinition() map[string]mp.Graphs { - data, err := p.fetchData() - if err != nil { - log.Fatalln(err) - } - - set := make(map[string]struct{}) - for _, m := range data { - dest := m.getDestinationName() - if dest != "" && !m.isDataAllNil() { - set[dest] = struct{}{} - } - } - - graphdef := make(map[string]mp.Graphs) - for key, m := range relayMeta { - var unit string - if m.unit == "float" { - unit = "float64" - } else if m.unit == "integer" { - unit = "uint64" - } - - if !strings.Contains(key, "destinations_") { - graphdef[relayPrefix+key] = mp.Graphs{ - Label: p.LabelPrefix + m.label, - Unit: m.unit, - Metrics: []mp.Metrics{ - {Name: key, Label: key, Type: unit}, - }, - } - } else { - var ms []mp.Metrics - for dest := range set { - ms = append(ms, mp.Metrics{ - Name: strings.Replace(dest, ":", "-", -1), - Label: dest, - Type: unit, - }) - } - - graphdef[relayPrefix+key] = mp.Graphs{ - Label: p.LabelPrefix + m.label, - Unit: m.unit, - Metrics: ms, - } - } - } - return graphdef -} - -// FetchMetrics interface for mackerelplugin -// But, don't use this -func (p GraphitePlugin) FetchMetrics() (map[string]interface{}, error) { - return nil, nil -} - -func (p GraphitePlugin) outputValues(w io.Writer) { - data, err := p.fetchData() - if err != nil { - log.Fatalln("fetchData():", err) - } - - for _, m := range data { - key := m.getMetricKey() - if key == "" { - continue - } - unit := m.getUnitType() - for _, point := range m.Datapoints { - if point[0] != nil { - printValue(w, key, point[0], uint64(point[1].(float64)), unit) - } - } - } -} - -func printValue(w io.Writer, key string, value interface{}, now uint64, unit string) { - switch unit { - case "integer": - fmt.Fprintf(w, "%s\t%d\t%d\n", key, uint64(value.(float64)), now) - case "float": - fmt.Fprintf(w, "%s\t%f\t%d\n", key, value.(float64), now) - } -} - -// fetchData fetches metrics data from -15min -func (p GraphitePlugin) fetchData() ([]metrics, error) { - req, err := http.NewRequest(http.MethodGet, p.URL, nil) - if err != nil { - return nil, err - } - req.Header.Set("User-Agent", "mackerel-plugin-graphite") - - res, err := http.DefaultClient.Do(req) - if err != nil { - return nil, err - } - defer res.Body.Close() - - b, _ := ioutil.ReadAll(res.Body) - var d []metrics - err = json.Unmarshal(b, &d) - if err != nil { - return nil, err - } - - return d, nil -} - -// Initialize plugin -func newGraphitePlugin(host, webHost, webPort, thetype, instance, labelPrefix string) GraphitePlugin { - plugin := GraphitePlugin{} - - // If a hostname is not specified, we get a name reported by the kernel. - if host == "" { - h, err := os.Hostname() - if err != nil { - log.Fatalln(err) - } - plugin.Host = strings.Replace(h, ".", "_", -1) - } else { - plugin.Host = strings.Replace(host, ".", "_", -1) - } - - plugin.WebHost = webHost - plugin.WebPort = webPort - - switch thetype { - case "cache": - plugin.Type = thetype - if instance == "" { - plugin.Instance = "*" - } else { - plugin.Instance = instance - } - case "relay": - plugin.Type = thetype - if instance == "" || instance == "*" { - log.Fatalln("You mush specify concrete instance name in case of relay") - } else { - plugin.Instance = instance - } - default: - log.Fatalln("Not accept such a type") - } - - plugin.LabelPrefix = labelPrefix - - var targets string - switch plugin.Type { - case "cache": - targets = fmt.Sprintf("target=carbon.agents.%s-%s.*&target=carbon.agents.%s-%s.*.*", plugin.Host, plugin.Instance, plugin.Host, plugin.Instance) - case "relay": - targets = fmt.Sprintf("target=carbon.relays.%s-%s.*&target=carbon.relays.%s-%s.destinations.*.*", plugin.Host, plugin.Instance, plugin.Host, plugin.Instance) - } - plugin.URL = fmt.Sprintf("http://%s:%s/render/?%s&from=-15min&format=json", plugin.WebHost, plugin.WebPort, targets) - - return plugin -} - -// Do the plugin -func Do() { - 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) - helper.Tempfile = *optTempfile - - if os.Getenv("MACKEREL_AGENT_PLUGIN_META") != "" { - helper.OutputDefinitions() - } else { - // Not using go-mackerel-plugin-helper method - // bacause we want to post multiple metrics with arbitrary timestamp - plugin.outputValues(os.Stdout) - } -} diff --git a/mackerel-plugin-graphite/lib/graphite_test.go b/mackerel-plugin-graphite/lib/graphite_test.go deleted file mode 100644 index 7d4db0917..000000000 --- a/mackerel-plugin-graphite/lib/graphite_test.go +++ /dev/null @@ -1,186 +0,0 @@ -package mpgraphite - -import ( - "bytes" - "encoding/json" - "net/http" - "net/http/httptest" - "regexp" - "testing" -) - -var cacheGoldenMetrics = []metrics{ - {"carbon.agents.host_hoge-a.avgUpdateTime", [][]interface{}{{0.1, 1}, {0.2, 2}}}, - {"carbon.agents.host_hoge-b.avgUpdateTime", [][]interface{}{{0.1, 1}, {0.2, 2}}}, - {"carbon.agents.host_hoge-a.cache.size", [][]interface{}{{1, 1}, {2, 2}}}, - {"carbon.agents.host_hoge-b.cache.size", [][]interface{}{{1, 1}, {2, 2}}}, -} - -var relayGoldenMetrics = []metrics{ - {"carbon.relays.host_hoge-a.cpuUsage", [][]interface{}{{0.1, 1}, {0.2, 2}}}, - {"carbon.relays.host_hoge-a.destinations.127_0_0_1:3004:a.sent", [][]interface{}{{1, 1}, {2, 2}}}, - {"carbon.relays.host_hoge-a.destinations.127_0_0_1:3104:b.sent", [][]interface{}{{1, 1}, {2, 2}}}, -} - -var cacheHandler = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - d, err := json.Marshal(cacheGoldenMetrics) - if err != nil { - http.Error(w, err.Error(), http.StatusInternalServerError) - return - } - w.Write(d) -}) - -var relayHandler = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - d, err := json.Marshal(relayGoldenMetrics) - if err != nil { - http.Error(w, err.Error(), http.StatusInternalServerError) - return - } - w.Write(d) -}) - -func TestFetchData(t *testing.T) { - ts := httptest.NewServer(cacheHandler) - defer ts.Close() - - plugin := GraphitePlugin{ - Host: "host_hoge", - WebHost: "webhost.hoge", - WebPort: "8000", - Type: "cache", - Instance: "*", - LabelPrefix: "Carbon", - URL: ts.URL, - } - - d, err := plugin.fetchData() - if err != nil { - t.Errorf("fetchData() failed: %v", err) - } - if actual := d[0].Target; actual != cacheGoldenMetrics[0].Target { - t.Errorf("fetchData(): %s should be %s", actual, cacheGoldenMetrics[0].Target) - } - if actual := d[0].Datapoints[0][0]; actual != cacheGoldenMetrics[0].Datapoints[0][0] { - t.Errorf("fetchData(): %s should be %s", actual, cacheGoldenMetrics[0].Datapoints[0][0]) - } -} - -func TestCacheGraphDefinition(t *testing.T) { - ts := httptest.NewServer(cacheHandler) - defer ts.Close() - - plugin := GraphitePlugin{ - Host: "host_hoge", - WebHost: "webhost.hoge", - WebPort: "8000", - Type: "cache", - Instance: "*", - LabelPrefix: "Carbon", - URL: ts.URL, - } - - graph := plugin.GraphDefinition() - if actual := len(graph); actual != len(cacheMeta) { - t.Errorf("GraphDefinition(): %d should be %d", actual, len(cacheMeta)) - } - for _, g := range graph { - if actual := len(g.Metrics); actual != 2 { - t.Errorf("GraphDefinition(): %d should be 2", actual) - } - } -} - -func TestRelayGraphDefinition(t *testing.T) { - ts := httptest.NewServer(relayHandler) - defer ts.Close() - - plugin := GraphitePlugin{ - Host: "host_hoge", - WebHost: "webhost.hoge", - WebPort: "8000", - Type: "relay", - Instance: "a", - LabelPrefix: "Carbon", - URL: ts.URL, - } - - graph := plugin.GraphDefinition() - if actual := len(graph); actual != len(relayMeta) { - t.Errorf("GraphDefinition(): %d should be %d", actual, len(relayMeta)) - } - for k, g := range graph { - matched, _ := regexp.MatchString(`cpuUsage|memUsage|metricsRecieved`, k) - if matched { - if actual := len(g.Metrics); actual != 1 { - t.Errorf("GraphDefinition(): %d should be 1", actual) - } - } else { - if actual := len(g.Metrics); actual != 2 { - t.Errorf("GraphDefinition(): %d should be 2", actual) - } - } - } -} - -func TestOutputValueForCache(t *testing.T) { - ts := httptest.NewServer(cacheHandler) - defer ts.Close() - - plugin := GraphitePlugin{ - Host: "host_hoge", - WebHost: "webhost.hoge", - WebPort: "8000", - Type: "cache", - Instance: "*", - LabelPrefix: "Carbon", - URL: ts.URL, - } - - s := new(bytes.Buffer) - plugin.outputValues(s) - - expected := `graphite-carbon.cache.avgUpdateTime.a 0.100000 1 -graphite-carbon.cache.avgUpdateTime.a 0.200000 2 -graphite-carbon.cache.avgUpdateTime.b 0.100000 1 -graphite-carbon.cache.avgUpdateTime.b 0.200000 2 -graphite-carbon.cache.cache_size.a 1 1 -graphite-carbon.cache.cache_size.a 2 2 -graphite-carbon.cache.cache_size.b 1 1 -graphite-carbon.cache.cache_size.b 2 2 -` - - if actual := string(s.Bytes()); actual != expected { - t.Errorf("outputValues(): %s should be %s", actual, expected) - } -} - -func TestOutputValueForRelay(t *testing.T) { - ts := httptest.NewServer(relayHandler) - defer ts.Close() - - plugin := GraphitePlugin{ - Host: "host_hoge", - WebHost: "webhost.hoge", - WebPort: "8000", - Type: "relay", - Instance: "a", - LabelPrefix: "Carbon", - URL: ts.URL, - } - - s := new(bytes.Buffer) - plugin.outputValues(s) - - expected := `graphite-carbon.relay.cpuUsage.cpuUsage 0.100000 1 -graphite-carbon.relay.cpuUsage.cpuUsage 0.200000 2 -graphite-carbon.relay.destinations_sent.127_0_0_1-3004-a 1 1 -graphite-carbon.relay.destinations_sent.127_0_0_1-3004-a 2 2 -graphite-carbon.relay.destinations_sent.127_0_0_1-3104-b 1 1 -graphite-carbon.relay.destinations_sent.127_0_0_1-3104-b 2 2 -` - - if actual := string(s.Bytes()); actual != expected { - t.Errorf("outputValues(): %s should be %s", actual, expected) - } -} diff --git a/mackerel-plugin-graphite/lib/meta.go b/mackerel-plugin-graphite/lib/meta.go deleted file mode 100644 index f7b123ed5..000000000 --- a/mackerel-plugin-graphite/lib/meta.go +++ /dev/null @@ -1,6 +0,0 @@ -package mpgraphite - -type meta struct { - label string - unit string -} diff --git a/mackerel-plugin-graphite/lib/metrics.go b/mackerel-plugin-graphite/lib/metrics.go deleted file mode 100644 index e3941f3f1..000000000 --- a/mackerel-plugin-graphite/lib/metrics.go +++ /dev/null @@ -1,115 +0,0 @@ -package mpgraphite - -import ( - "regexp" - "strings" -) - -type metrics struct { - Target string - Datapoints [][]interface{} -} - -// carbon.agents.host_name-{instance|a}.{metric} -// carbon.agents.host_name-{instance|a}.cache.{metric} -var cacheRegexp = regexp.MustCompile(`carbon\.agents\..*-(.*?)\.(.*)`) - -// carbon.relays.host_name-a.{metric} -// carbon.relays.host_name-a.destinations.{instance|127_0_0_1:3004:a}.{metric} -var relayRegexp = regexp.MustCompile(`carbon\.relays\..*-.*?\.(.*)`) - -func (m metrics) getInstanceName() string { - matched := cacheRegexp.FindStringSubmatch(m.Target) - if matched != nil { - return matched[1] - } - return "" -} - -func (m metrics) getDestinationName() string { - matched := relayRegexp.FindStringSubmatch(m.Target) - if matched == nil { - return "" - } - - if !strings.Contains(matched[1], ".") { - // If metric is {cpuUsage,memUsage,metricsRecieved} - return "" - } - - return strings.Split(matched[1], ".")[1] -} - -func (m metrics) getMetricName() string { - // In case of carbon-cache - matched := cacheRegexp.FindStringSubmatch(m.Target) - if matched != nil { - metric := matched[2] - if strings.Contains(matched[2], ".") { - metric = strings.Replace(metric, ".", "_", -1) - } - return metric - } - - // In case of carbon-relay - matched = relayRegexp.FindStringSubmatch(m.Target) - if matched != nil { - metric := matched[1] - if !strings.Contains(metric, ".") { - return metric - } - return "destinations_" + strings.Split(metric, ".")[2] - } - - return "" -} - -func (m metrics) getUnitType() string { - name := m.getMetricName() - if m, ok := cacheMeta[name]; ok { - return m.unit - } - if m, ok := relayMeta[name]; ok { - return m.unit - } - return "" -} - -func (m metrics) isDataAllNil() bool { - for _, d := range m.Datapoints { - if d[0] != nil { - return false - } - } - return true -} - -func (m metrics) getMetricKey() string { - // In case of carbon-cache - matched := cacheRegexp.FindStringSubmatch(m.Target) - if matched != nil { - instance := matched[1] - metric := matched[2] - if strings.Contains(matched[2], ".") { - metric = strings.Replace(metric, ".", "_", -1) - } - return cachePrefix + metric + "." + instance - } - - // In case of carbon-relay - matched = relayRegexp.FindStringSubmatch(m.Target) - if matched != nil { - metric := matched[1] - if !strings.Contains(metric, ".") { - // If metric is {cpuUsage,memUsage,metricsRecieved} - return relayPrefix + metric + "." + metric - } - split := strings.Split(metric, ".") - dest := split[1] - metric = split[2] - dest = strings.Replace(dest, ":", "-", -1) - return relayPrefix + "destinations_" + metric + "." + dest - } - - return "" -} diff --git a/mackerel-plugin-graphite/lib/metrics_test.go b/mackerel-plugin-graphite/lib/metrics_test.go deleted file mode 100644 index 1f0cb9c49..000000000 --- a/mackerel-plugin-graphite/lib/metrics_test.go +++ /dev/null @@ -1,106 +0,0 @@ -package mpgraphite - -import ( - "testing" -) - -func TestGetInstanceName(t *testing.T) { - cases := []struct{ target, expected string }{ - {"carbon.agents.t_e_s_t-1.avgUpdateTime", "1"}, - {"carbon.agents.t_e_s_t-2.cache.size", "2"}, - } - - for _, tc := range cases { - m := metrics{} - m.Target = tc.target - if actual := m.getInstanceName(); actual != tc.expected { - t.Errorf("getInstanceName(): %s should be '%s'", actual, tc.expected) - } - } -} - -func TestGetDestinationName(t *testing.T) { - cases := []struct{ target, expected string }{ - {"carbon.relays.t_e_s_t-a.avgUpdateTime", ""}, - {"carbon.relays.t_e_s_t-a.destinations.127_0_0_1:3004:a.sent", "127_0_0_1:3004:a"}, - } - - for _, tc := range cases { - m := metrics{} - m.Target = tc.target - if actual := m.getDestinationName(); actual != tc.expected { - t.Errorf("getDestinationName(): %s should be '%s'", actual, tc.expected) - } - } -} - -func TestGetMetricName(t *testing.T) { - cases := []struct{ target, expected string }{ - {"carbon.agents.t_e_s_t-a.avgUpdateTime", "avgUpdateTime"}, - {"carbon.agents.t_e_s_t-a.cache.size", "cache_size"}, - {"carbon.relays.t_e_s_t-a.cpuUsage", "cpuUsage"}, - {"carbon.relays.t_e_s_t-a.destinations.127_0_0_1:3004:a.sent", "destinations_sent"}, - } - - for _, tc := range cases { - m := metrics{} - m.Target = tc.target - if actual := m.getMetricName(); actual != tc.expected { - t.Errorf("getMetricName(): %s should be '%s'", actual, tc.expected) - } - } -} - -func TestGetUnitType(t *testing.T) { - cases := []struct{ target, expected string }{ - {"carbon.agents.t_e_s_t-a.avgUpdateTime", "float"}, - {"carbon.agents.t_e_s_t-a.cache.size", "integer"}, - {"carbon.relays.t_e_s_t-a.cpuUsage", "float"}, - {"carbon.relays.t_e_s_t-a.destinations.127_0_0_1:3004:a.sent", "integer"}, - } - - for _, tc := range cases { - m := metrics{} - m.Target = tc.target - if actual := m.getUnitType(); actual != tc.expected { - t.Errorf("getUnitType(): %s should be '%s'", actual, tc.expected) - } - } -} - -func TestCheckAllNil(t *testing.T) { - cases := [](struct { - target string - datapoints [][]interface{} - expected bool - }){ - {"carbon.agents.t_e_s_t-a.avgUpdateTime", [][]interface{}{{nil, 1}, {nil, 2}}, true}, - {"carbon.agents.t_e_s_t-1.avgUpdateTime", [][]interface{}{{1, 1}, {nil, 2}}, false}, - } - - for _, tc := range cases { - m := metrics{} - m.Target = tc.target - m.Datapoints = tc.datapoints - if actual := m.isDataAllNil(); actual != tc.expected { - t.Errorf("isDataAllNil(): %v should be '%v'", actual, tc.expected) - } - } -} - -func TestGetMetricKey(t *testing.T) { - cases := []struct{ target, expected string }{ - {"carbon.agents.t_e_s_t-a.avgUpdateTime", "graphite-carbon.cache.avgUpdateTime.a"}, - {"carbon.agents.t_e_s_t-a.cache.size", "graphite-carbon.cache.cache_size.a"}, - {"carbon.relays.t_e_s_t-a.cpuUsage", "graphite-carbon.relay.cpuUsage.cpuUsage"}, - {"carbon.relays.t_e_s_t-a.destinations.127_0_0_1:3004:a.sent", "graphite-carbon.relay.destinations_sent.127_0_0_1-3004-a"}, - } - - for _, tc := range cases { - m := metrics{} - m.Target = tc.target - if actual := m.getMetricKey(); actual != tc.expected { - t.Errorf("getMetricKey(): %s should be '%s'", actual, tc.expected) - } - } -} diff --git a/mackerel-plugin-graphite/lib/relay_meta.go b/mackerel-plugin-graphite/lib/relay_meta.go deleted file mode 100644 index bfb083623..000000000 --- a/mackerel-plugin-graphite/lib/relay_meta.go +++ /dev/null @@ -1,34 +0,0 @@ -package mpgraphite - -var relayPrefix = "graphite-carbon.relay." - -var relayMeta = map[string]meta{ - "cpuUsage": { - label: " CPU Usage", - unit: "float", - }, - "memUsage": { - label: " Memory Usage", - unit: "integer", - }, - "metricsRecieved": { - label: " Metrics Recieved", - unit: "integer", - }, - "destinations_attemptedRelays": { - label: " Attempted Relays", - unit: "integer", - }, - "destinations_queuedUntilConnected": { - label: " Queued Until Connected", - unit: "integer", - }, - "destinations_queuedUntilReady": { - label: " Queued Until Ready", - unit: "integer", - }, - "destinations_sent": { - label: " Sent", - unit: "integer", - }, -} diff --git a/mackerel-plugin-graphite/main.go b/mackerel-plugin-graphite/main.go index c40af7534..efd459ffb 100644 --- a/mackerel-plugin-graphite/main.go +++ b/mackerel-plugin-graphite/main.go @@ -1,6 +1,6 @@ package main -import "github.com/mackerelio/mackerel-agent-plugins/mackerel-plugin-graphite/lib" +import "github.com/mackerelio/mackerel-plugin-graphite/lib" func main() { mpgraphite.Do() diff --git a/t/convention.t b/t/convention.t index dca418381..05b17356f 100644 --- a/t/convention.t +++ b/t/convention.t @@ -12,6 +12,7 @@ my $plugins_in_other_repository = [qw( mackerel-plugin-aws-waf mackerel-plugin-gcp-compute-engine mackerel-plugin-gearmand + mackerel-plugin-graphite mackerel-plugin-json mackerel-plugin-nvidia-smi )]; From 27b9c0953dcb5f469047766e691d63439502abc1 Mon Sep 17 00:00:00 2001 From: lufia Date: Mon, 12 Dec 2022 18:20:39 +0900 Subject: [PATCH 3/6] remove mackerel-plugin-xentop --- mackerel-plugin-xentop/README.md | 17 +-- mackerel-plugin-xentop/go.mod | 12 ++ mackerel-plugin-xentop/go.sum | 22 +++ mackerel-plugin-xentop/lib/xentop.go | 214 --------------------------- mackerel-plugin-xentop/main.go | 2 +- t/convention.t | 1 + 6 files changed, 38 insertions(+), 230 deletions(-) create mode 100644 mackerel-plugin-xentop/go.mod create mode 100644 mackerel-plugin-xentop/go.sum delete mode 100644 mackerel-plugin-xentop/lib/xentop.go diff --git a/mackerel-plugin-xentop/README.md b/mackerel-plugin-xentop/README.md index 172176756..736db566c 100644 --- a/mackerel-plugin-xentop/README.md +++ b/mackerel-plugin-xentop/README.md @@ -1,19 +1,6 @@ mackerel-plugin-xentop ====================== -Xen custom metrics plugin for mackerel.io agent. -Xen metrics are retrieved by `xentop` command. - -## Synopsis - -```shell -mackerel-plugin-xentop [-xenversion=] [-tempfile=] -``` - -## Example of mackerel-agent.conf - -``` -[plugin.metrics.xentop] -command = "/path/to/mackerel-plugin-xentop" -``` +This plugin moved to [mackerelio/mackerel-plugin-xentop][url] +[url]: https://github.com/mackerelio/mackerel-plugin-xentop diff --git a/mackerel-plugin-xentop/go.mod b/mackerel-plugin-xentop/go.mod new file mode 100644 index 000000000..dfd9a5c07 --- /dev/null +++ b/mackerel-plugin-xentop/go.mod @@ -0,0 +1,12 @@ +module github.com/mackerelio/mackerel-agent-plugins/mackerel-plugin-xentop + +go 1.19 + +require github.com/mackerelio/mackerel-plugin-xentop v1.0.0 + +require ( + github.com/mackerelio/go-mackerel-plugin-helper v0.1.2 // indirect + github.com/mackerelio/golib v1.2.1 // indirect + golang.org/x/lint v0.0.0-20210508222113-6edffad5e616 // indirect + golang.org/x/tools v0.1.5 // indirect +) diff --git a/mackerel-plugin-xentop/go.sum b/mackerel-plugin-xentop/go.sum new file mode 100644 index 000000000..f31146e65 --- /dev/null +++ b/mackerel-plugin-xentop/go.sum @@ -0,0 +1,22 @@ +github.com/mackerelio/go-mackerel-plugin-helper v0.1.2 h1:p/KTlMK/mocWAIjNuYzpCybYvkfAEroDZBDAiOuz2QQ= +github.com/mackerelio/go-mackerel-plugin-helper v0.1.2/go.mod h1:Vfs2Fk1FfE8c8mufAQKcWBtGI0GCrOLGvaJg+kS5yz4= +github.com/mackerelio/golib v1.2.1 h1:SDcDn6Jw3p9bi1N0bg1Z/ilG5qcBB23qL8xNwrU0gg4= +github.com/mackerelio/golib v1.2.1/go.mod h1:b8ZaapsHGH1FlEJlCqfD98CqafLeyMevyATDlID2BsM= +github.com/mackerelio/mackerel-plugin-xentop v1.0.0 h1:K/uOe2gEefIM+emZ4RKMW2A9fWBY6Co4jLBNp8cm1IY= +github.com/mackerelio/mackerel-plugin-xentop v1.0.0/go.mod h1:d78+X+uXT8Lu1BLJzt9TPlo9+yt8Cp0h3XHXd5Uh0sg= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/lint v0.0.0-20210508222113-6edffad5e616 h1:VLliZ0d+/avPrXXH+OakdXhpJuEoBZuwh1m2j7U6Iug= +golang.org/x/lint v0.0.0-20210508222113-6edffad5e616/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY= +golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg= +golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20220319134239-a9b59b0215f8 h1:OH54vjqzRWmbJ62fjuhxy7AxFFgoHN0/DPc/UrL8cAs= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/tools v0.0.0-20200130002326-2f3ba24bd6e7/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.1.5 h1:ouewzE6p+/VEB31YYnTbEJdi8pFqKp4P4n85vwo3DHA= +golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= +golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= diff --git a/mackerel-plugin-xentop/lib/xentop.go b/mackerel-plugin-xentop/lib/xentop.go deleted file mode 100644 index 129d34522..000000000 --- a/mackerel-plugin-xentop/lib/xentop.go +++ /dev/null @@ -1,214 +0,0 @@ -package mpxentop - -import ( - "bufio" - "flag" - "fmt" - "os" - "os/exec" - "strconv" - "strings" - - mp "github.com/mackerelio/go-mackerel-plugin-helper" -) - -// index from table headers to array index -// This is generated dynamically at generateIndex -var index = map[string]int{} - -var graphdef = map[string]mp.Graphs{ - "xentop.cpu.#": { - Label: "Xentop CPU", - Unit: "percentage", - Metrics: []mp.Metrics{ - {Name: "cpu", Label: "cpu", Stacked: true, Diff: true}, - }, - }, - "xentop.memory.#": { - Label: "Xentop Memory", - Unit: "percentage", - Metrics: []mp.Metrics{ - {Name: "memory", Label: "memory", Stacked: true}, - }, - }, - "xentop.nettx.#": { - Label: "Xentop Nettx", - Unit: "bytes", - Metrics: []mp.Metrics{ - {Name: "nettx", Label: "nettx", Stacked: true, Diff: true}, - }, - }, - "xentop.netrx.#": { - Label: "Xentop Netrx", - Unit: "bytes", - Metrics: []mp.Metrics{ - {Name: "netrx", Label: "netrx", Stacked: true, Diff: true}, - }, - }, - "xentop.vbdrd.#": { - Label: "Xentop VBD_RD", - Unit: "iops", - Metrics: []mp.Metrics{ - {Name: "vbdrd", Label: "vbdrd", Stacked: true, Diff: true}, - }, - }, - "xentop.vbdwr.#": { - Label: "Xentop VBD_WR", - Unit: "iops", - Metrics: []mp.Metrics{ - {Name: "vbdwr", Label: "vbdwr", Stacked: true, Diff: true}, - }, - }, -} - -// XentopPlugin mackerel plugin for xentop -type XentopPlugin struct { - XenVersion int -} - -// FetchMetrics interface for mackerelplugin -func (m XentopPlugin) FetchMetrics() (map[string]interface{}, error) { - stat := make(map[string]interface{}) - - var cmd *exec.Cmd - if m.XenVersion == 4 { - cmd = exec.Command("/bin/sh", "-c", "xentop --batch -i 1 -f") - } else { - cmd = exec.Command("/bin/sh", "-c", "xentop --batch -i 1") - } - stdout, err := cmd.StdoutPipe() - - if err != nil { - fmt.Println(err) - os.Exit(1) - } - - execErr := cmd.Start() - if execErr != nil { - fmt.Println(execErr) - os.Exit(1) - } - - dom0 := false - scanner := bufio.NewScanner(stdout) - hasIndex := false - for scanner.Scan() { - sf := strings.Fields(string(scanner.Text())) - if sf[0] == "NAME" { - generateIndex(sf, index) - hasIndex = true - continue - } - if !hasIndex { - continue - } - if stringInSlice("n/a", sf) { - changeIndex(&index) - dom0 = true - } - name := normalizeXenName(sf[index["NAME"]]) - - var errParse error - var tmpval float64 // avoid `stat[*] *= 1000` because of go interface bug - - tmpval, errParse = strconv.ParseFloat(sf[index["CPU(sec)"]], 64) - if errParse != nil { - return nil, errParse - } - stat[fmt.Sprintf("xentop.cpu.%s.cpu", name)] = tmpval * 100 / 60 - stat[fmt.Sprintf("xentop.memory.%s.memory", name)], errParse = strconv.ParseFloat(sf[index["MEM(%)"]], 64) - if errParse != nil { - return nil, errParse - } - tmpval, errParse = strconv.ParseFloat(sf[index["NETTX(k)"]], 64) - if errParse != nil { - return nil, errParse - } - stat[fmt.Sprintf("xentop.nettx.%s.nettx", name)] = tmpval * 1000 - tmpval, errParse = strconv.ParseFloat(sf[index["NETRX(k)"]], 64) - if errParse != nil { - return nil, errParse - } - stat[fmt.Sprintf("xentop.netrx.%s.netrx", name)] = tmpval * 1000 - stat[fmt.Sprintf("xentop.vbdrd.%s.vbdrd", name)], errParse = strconv.ParseFloat(sf[index["VBD_RD"]], 64) - if errParse != nil { - return nil, errParse - } - stat[fmt.Sprintf("xentop.vbdwr.%s.vbdwr", name)], errParse = strconv.ParseFloat(sf[index["VBD_WR"]], 64) - if errParse != nil { - return nil, errParse - } - if dom0 { - revertIndex(&index) - dom0 = false - } - } - if err := scanner.Err(); err != nil { - panic(err) - } - - return stat, nil -} - -// GraphDefinition interface for mackerelplugin -func (m XentopPlugin) GraphDefinition() map[string]mp.Graphs { - return graphdef -} - -// Do the plugin -func Do() { - optTempfile := flag.String("tempfile", "", "Temp file name") - optXenVersion := flag.Int("xenversion", 4, "Xen Version") - flag.Parse() - - var xentop XentopPlugin - - xentop.XenVersion = *optXenVersion - - helper := mp.NewMackerelPlugin(xentop) - - if *optTempfile != "" { - helper.Tempfile = *optTempfile - } - - helper.Run() -} - -func normalizeXenName(raw string) string { - return strings.Replace(raw, ".", "_", -1) -} - -func stringInSlice(a string, list []string) bool { - for _, b := range list { - if b == a { - return true - } - } - return false -} - -func generateIndex(sf []string, index map[string]int) { - i := 0 - for _, column := range sf { - index[column] = i - i++ - } -} - -func changeIndex(p *map[string]int) { - maxmemPer := (*p)["MAXMEM(%)"] - for key, value := range *p { - if value >= maxmemPer { - (*p)[key]++ - } - } -} - -func revertIndex(p *map[string]int) { - maxmemPer := (*p)["MAXMEM(%)"] - for key, value := range *p { - if value >= maxmemPer { - (*p)[key]-- - } - } -} diff --git a/mackerel-plugin-xentop/main.go b/mackerel-plugin-xentop/main.go index ceab96ca1..73f802949 100644 --- a/mackerel-plugin-xentop/main.go +++ b/mackerel-plugin-xentop/main.go @@ -1,6 +1,6 @@ package main -import "github.com/mackerelio/mackerel-agent-plugins/mackerel-plugin-xentop/lib" +import "github.com/mackerelio/mackerel-plugin-xentop/lib" func main() { mpxentop.Do() diff --git a/t/convention.t b/t/convention.t index 05b17356f..70fe6b753 100644 --- a/t/convention.t +++ b/t/convention.t @@ -15,6 +15,7 @@ my $plugins_in_other_repository = [qw( mackerel-plugin-graphite mackerel-plugin-json mackerel-plugin-nvidia-smi + mackerel-plugin-xentop )]; my $is_in_other_repository = { map { $_ => 1 } @$plugins_in_other_repository, From 4f14504dafee399528499ddf537b3ba6b54d3393 Mon Sep 17 00:00:00 2001 From: lufia Date: Mon, 12 Dec 2022 18:25:23 +0900 Subject: [PATCH 4/6] remove mackerel-plugin-flume --- mackerel-plugin-flume/README.md | 21 +-- mackerel-plugin-flume/go.mod | 10 ++ mackerel-plugin-flume/go.sum | 11 ++ mackerel-plugin-flume/lib/flume.go | 229 ------------------------ mackerel-plugin-flume/lib/flume_test.go | 89 --------- mackerel-plugin-flume/main.go | 2 +- t/convention.t | 1 + 7 files changed, 25 insertions(+), 338 deletions(-) create mode 100644 mackerel-plugin-flume/go.mod create mode 100644 mackerel-plugin-flume/go.sum delete mode 100644 mackerel-plugin-flume/lib/flume.go delete mode 100644 mackerel-plugin-flume/lib/flume_test.go diff --git a/mackerel-plugin-flume/README.md b/mackerel-plugin-flume/README.md index c13bf8152..253583173 100644 --- a/mackerel-plugin-flume/README.md +++ b/mackerel-plugin-flume/README.md @@ -1,23 +1,6 @@ mackerel-plugin-flume ===================== -Flume custom metrics plugin for mackerel.io agent. - -## Synopsis - -```shell -mackerel-plugin-flume [-host=] [-port=] [-metric-key-prefix=] -``` - -## Example of mackerel-agent.conf - -``` -[plugin.metrics.flume] -command = "/path/to/mackerel-plugin-flume" -``` - -## Documents - -* [Monitoring](https://flume.apache.org/FlumeUserGuide.html#monitoring) -* [JSON Reporting](https://flume.apache.org/FlumeUserGuide.html#json-reporting) +This plugin moved to [mackerelio/mackerel-plugin-flume][url] +[url]: https://github.com/mackerelio/mackerel-plugin-flume diff --git a/mackerel-plugin-flume/go.mod b/mackerel-plugin-flume/go.mod new file mode 100644 index 000000000..39e8cc152 --- /dev/null +++ b/mackerel-plugin-flume/go.mod @@ -0,0 +1,10 @@ +module github.com/mackerelio/mackerel-agent-plugins/mackerel-plugin-flume + +go 1.19 + +require github.com/mackerelio/mackerel-plugin-flume v1.0.0 + +require ( + github.com/mackerelio/go-mackerel-plugin v0.1.2 // indirect + github.com/mackerelio/golib v1.2.1 // indirect +) diff --git a/mackerel-plugin-flume/go.sum b/mackerel-plugin-flume/go.sum new file mode 100644 index 000000000..1a3397d9a --- /dev/null +++ b/mackerel-plugin-flume/go.sum @@ -0,0 +1,11 @@ +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/mackerelio/go-mackerel-plugin v0.1.2 h1:bbxd2aBCYfrxOdBnvTUyyx8ckeVW2hhb41ewhXJheDA= +github.com/mackerelio/go-mackerel-plugin v0.1.2/go.mod h1:NnKukHcC4C8yTElL+4vdEjTA1zFA42hLCn1s2K+2UNU= +github.com/mackerelio/golib v1.2.0/go.mod h1:jSdKpwSkTVLi0wyk3YZ6enh6H19p02wUE8ShAFxaAPQ= +github.com/mackerelio/golib v1.2.1 h1:SDcDn6Jw3p9bi1N0bg1Z/ilG5qcBB23qL8xNwrU0gg4= +github.com/mackerelio/golib v1.2.1/go.mod h1:b8ZaapsHGH1FlEJlCqfD98CqafLeyMevyATDlID2BsM= +github.com/mackerelio/mackerel-plugin-flume v1.0.0 h1:0hunHL9/0M2jaGl6mm0tzzLmf9qskqN6C2yi86s/HGk= +github.com/mackerelio/mackerel-plugin-flume v1.0.0/go.mod h1:QKi5YBp3WNNiOM+uPPP8MNz3I+qs1FaP3XpFpJXBFMU= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/stretchr/testify v1.7.1 h1:5TQK59W5E3v0r2duFAb7P95B6hEeOyEnHRa8MjYSMTY= +gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo= diff --git a/mackerel-plugin-flume/lib/flume.go b/mackerel-plugin-flume/lib/flume.go deleted file mode 100644 index 98a615d68..000000000 --- a/mackerel-plugin-flume/lib/flume.go +++ /dev/null @@ -1,229 +0,0 @@ -package mpflume - -import ( - "encoding/json" - "flag" - "fmt" - "net/http" - "strconv" - "strings" - - mp "github.com/mackerelio/go-mackerel-plugin" -) - -const ( - // Channel is Flume Channel Type - Channel = "CHANNEL" - // Sink is Flume Sink Type - Sink = "SINK" - // Source is Flume Source Type - Source = "SOURCE" -) - -// FlumePlugin mackerel plugin -type FlumePlugin struct { - URI string - Prefix string -} - -// MetricKeyPrefix interface for PluginWithPrefix -func (p *FlumePlugin) MetricKeyPrefix() string { - if p.Prefix == "" { - p.Prefix = "flume" - } - return p.Prefix -} - -// GraphDefinition interface for mackerelplugin -func (p *FlumePlugin) GraphDefinition() map[string]mp.Graphs { - labelPrefix := strings.Title(p.Prefix) - return map[string]mp.Graphs{ - "channel.capacity.#": { - Label: labelPrefix + " Channel Capacity", - Unit: "integer", - Metrics: []mp.Metrics{ - {Name: "ChannelCapacity", Label: "capacity"}, - {Name: "ChannelSize", Label: "size"}, - }, - }, - "channel.use_rate.#": { - Label: labelPrefix + " Channel Use Rate", - Unit: "percentage", - Metrics: []mp.Metrics{ - {Name: "ChannelFillPercentage", Label: "fill percentage"}, - }, - }, - "channel.event_put_num.#": { - Label: labelPrefix + " Channel Event Put Num", - Unit: "integer", - Metrics: []mp.Metrics{ - {Name: "EventPutAttemptCount", Label: "attempt", Diff: true}, - {Name: "EventPutSuccessCount", Label: "success", Diff: true}, - }, - }, - "channel.event_take_num.#": { - Label: labelPrefix + " Channel Event Take Num", - Unit: "integer", - Metrics: []mp.Metrics{ - {Name: "EventTakeAttemptCount", Label: "attempt", Diff: true}, - {Name: "EventTakeSuccessCount", Label: "success", Diff: true}, - }, - }, - "sink.batch_num.#": { - Label: labelPrefix + " Sink Batch Num", - Unit: "integer", - Metrics: []mp.Metrics{ - {Name: "BatchCompleteCount", Label: "complete", Diff: true}, - {Name: "BatchEmptyCount", Label: "empty", Diff: true}, - {Name: "BatchUnderflowCount", Label: "underflow", Diff: true}, - }, - }, - "sink.connection.#": { - Label: labelPrefix + " Sink Connection", - Unit: "integer", - Metrics: []mp.Metrics{ - {Name: "ConnectionCreatedCount", Label: "created", Diff: true}, - {Name: "ConnectionClosedCount", Label: "closed", Diff: true}, - {Name: "ConnectionFailedCount", Label: "failed", Diff: true}, - }, - }, - "sink.event_drain_num.#": { - Label: labelPrefix + " Sink Event Drain Num", - Unit: "integer", - Metrics: []mp.Metrics{ - {Name: "EventDrainAttemptCount", Label: "attempt", Diff: true}, - {Name: "EventDrainSuccessCount", Label: "success", Diff: true}, - }, - }, - "source.append_num.#": { - Label: labelPrefix + " Source Append Num", - Unit: "integer", - Metrics: []mp.Metrics{ - {Name: "AppendAcceptedCount", Label: "accepted", Diff: true}, - {Name: "AppendReceivedCount", Label: "received", Diff: true}, - }, - }, - "source.append_batch_num.#": { - Label: labelPrefix + " Source Append Batch Num", - Unit: "integer", - Metrics: []mp.Metrics{ - {Name: "AppendBatchAcceptedCount", Label: "accepted", Diff: true}, - {Name: "AppendBatchReceivedCount", Label: "received", Diff: true}, - }, - }, - "source.event_num.#": { - Label: labelPrefix + " Source Event Num", - Unit: "integer", - Metrics: []mp.Metrics{ - {Name: "EventAcceptedCount", Label: "accepted", Diff: true}, - {Name: "EventReceivedCount", Label: "received", Diff: true}, - }, - }, - "source.connection.#": { - Label: labelPrefix + " Source Connection", - Unit: "integer", - Metrics: []mp.Metrics{ - {Name: "OpenConnectionCount", Label: "open"}, - }, - }, - } -} - -// FetchMetrics interface for mackerelplugin -func (p *FlumePlugin) FetchMetrics() (map[string]float64, error) { - m, err := p.getMetrics() - if err != nil { - return nil, err - } - return p.parseMetrics(m), nil -} - -func (p *FlumePlugin) getMetrics() (map[string]interface{}, error) { - req, err := http.NewRequest(http.MethodGet, p.URI, nil) - if err != nil { - return nil, err - } - req.Header.Set("User-Agent", "mackerel-plugin-flume") - - res, err := http.DefaultClient.Do(req) - if err != nil { - return nil, err - } - defer res.Body.Close() - var m map[string]interface{} - dec := json.NewDecoder(res.Body) - if err := dec.Decode(&m); err != nil { - return nil, err - } - return m, nil -} - -func (p *FlumePlugin) parseMetrics(metrics map[string]interface{}) map[string]float64 { - ret := make(map[string]float64) - for k, v := range metrics { - array := strings.Split(k, ".") - typeName := array[0] - componentName := array[1] - switch typeName { - case Channel: - p.parseChannel(ret, componentName, v.(map[string]interface{})) - case Sink: - p.parseSink(ret, componentName, v.(map[string]interface{})) - case Source: - p.parseSource(ret, componentName, v.(map[string]interface{})) - } - } - - return ret -} - -func (p *FlumePlugin) convertFloat64(value string) float64 { - f, _ := strconv.ParseFloat(value, 64) - return f -} - -func (p *FlumePlugin) parseChannel(ret map[string]float64, componentName string, value map[string]interface{}) { - ret["channel.capacity."+componentName+".ChannelCapacity"] = p.convertFloat64(value["ChannelCapacity"].(string)) - ret["channel.capacity."+componentName+".ChannelSize"] = p.convertFloat64(value["ChannelSize"].(string)) - ret["channel.use_rate."+componentName+".ChannelFillPercentage"] = p.convertFloat64(value["ChannelFillPercentage"].(string)) - ret["channel.event_put_num."+componentName+".EventPutAttemptCount"] = p.convertFloat64(value["EventPutAttemptCount"].(string)) - ret["channel.event_put_num."+componentName+".EventPutSuccessCount"] = p.convertFloat64(value["EventPutSuccessCount"].(string)) - ret["channel.event_take_num."+componentName+".EventTakeAttemptCount"] = p.convertFloat64(value["EventTakeAttemptCount"].(string)) - ret["channel.event_take_num."+componentName+".EventTakeSuccessCount"] = p.convertFloat64(value["EventTakeSuccessCount"].(string)) -} - -func (p *FlumePlugin) parseSink(ret map[string]float64, componentName string, value map[string]interface{}) { - ret["sink.batch_num."+componentName+".BatchCompleteCount"] = p.convertFloat64(value["BatchCompleteCount"].(string)) - ret["sink.batch_num."+componentName+".BatchEmptyCount"] = p.convertFloat64(value["BatchEmptyCount"].(string)) - ret["sink.batch_num."+componentName+".BatchUnderflowCount"] = p.convertFloat64(value["BatchUnderflowCount"].(string)) - ret["sink.connection."+componentName+".ConnectionCreatedCount"] = p.convertFloat64(value["ConnectionCreatedCount"].(string)) - ret["sink.connection."+componentName+".ConnectionClosedCount"] = p.convertFloat64(value["ConnectionClosedCount"].(string)) - ret["sink.connection."+componentName+".ConnectionFailedCount"] = p.convertFloat64(value["ConnectionFailedCount"].(string)) - ret["sink.event_drain_num."+componentName+".EventDrainAttemptCount"] = p.convertFloat64(value["EventDrainAttemptCount"].(string)) - ret["sink.event_drain_num."+componentName+".EventDrainSuccessCount"] = p.convertFloat64(value["EventDrainSuccessCount"].(string)) -} - -func (p *FlumePlugin) parseSource(ret map[string]float64, componentName string, value map[string]interface{}) { - ret["source.append_num."+componentName+".AppendAcceptedCount"] = p.convertFloat64(value["AppendAcceptedCount"].(string)) - ret["source.append_num."+componentName+".AppendReceivedCount"] = p.convertFloat64(value["AppendReceivedCount"].(string)) - ret["source.append_batch_num."+componentName+".AppendBatchAcceptedCount"] = p.convertFloat64(value["AppendBatchAcceptedCount"].(string)) - ret["source.append_batch_num."+componentName+".AppendBatchReceivedCount"] = p.convertFloat64(value["AppendBatchReceivedCount"].(string)) - ret["source.event_num."+componentName+".EventAcceptedCount"] = p.convertFloat64(value["EventAcceptedCount"].(string)) - ret["source.event_num."+componentName+".EventReceivedCount"] = p.convertFloat64(value["EventReceivedCount"].(string)) - ret["source.connection."+componentName+".OpenConnectionCount"] = p.convertFloat64(value["OpenConnectionCount"].(string)) -} - -// Do the plugin -func Do() { - optHost := flag.String("host", "localhost", "Host Name") - optPort := flag.String("port", "41414", "Port") - optPrefix := flag.String("metric-key-prefix", "", "Metric key prefix") - optTempfile := flag.String("tempfile", "", "Temp file name") - flag.Parse() - plugin := mp.NewMackerelPlugin(&FlumePlugin{ - URI: fmt.Sprintf("http://%s:%s/metrics", *optHost, *optPort), - Prefix: *optPrefix, - }) - plugin.Tempfile = *optTempfile - plugin.Run() -} diff --git a/mackerel-plugin-flume/lib/flume_test.go b/mackerel-plugin-flume/lib/flume_test.go deleted file mode 100644 index e56a38583..000000000 --- a/mackerel-plugin-flume/lib/flume_test.go +++ /dev/null @@ -1,89 +0,0 @@ -package mpflume - -import ( - "encoding/json" - "testing" - - "github.com/stretchr/testify/assert" -) - -var jsonDate = `{"SOURCE.source":{"EventReceivedCount":"260969","Type":"SOURCE","AppendBatchAcceptedCount":"8357","EventAcceptedCount":"260969","AppendReceivedCount":"0","StartTime":"1503541553238","OpenConnectionCount":"0","AppendAcceptedCount":"0","AppendBatchReceivedCount":"8357","StopTime":"0"},"CHANNEL.channel":{"ChannelCapacity":"5000000","ChannelFillPercentage":"0.0","Type":"CHANNEL","ChannelSize":"0","EventTakeSuccessCount":"260969","StartTime":"1503541553170","EventTakeAttemptCount":"277651","EventPutAttemptCount":"260969","EventPutSuccessCount":"260969","StopTime":"0"},"SINK.sink":{"ConnectionCreatedCount":"109","Type":"SINK","ConnectionClosedCount":"108","BatchCompleteCount":"1567","BatchEmptyCount":"11067","EventDrainAttemptCount":"260969","StartTime":"1503541553174","EventDrainSuccessCount":"260969","BatchUnderflowCount":"5615","StopTime":"0","ConnectionFailedCount":"0"}}` - -/* -{ - "SOURCE.source": { - "EventReceivedCount": "260969", - "Type": "SOURCE", - "AppendBatchAcceptedCount": "8357", - "EventAcceptedCount": "260969", - "AppendReceivedCount": "0", - "StartTime": "1503541553238", - "OpenConnectionCount": "0", - "AppendAcceptedCount": "0", - "AppendBatchReceivedCount": "8357", - "StopTime": "0" - }, - "CHANNEL.channel": { - "ChannelCapacity": "5000000", - "ChannelFillPercentage": "0.0", - "Type": "CHANNEL", - "ChannelSize": "0", - "EventTakeSuccessCount": "260969", - "StartTime": "1503541553170", - "EventTakeAttemptCount": "277651", - "EventPutAttemptCount": "260969", - "EventPutSuccessCount": "260969", - "StopTime": "0" - }, - "SINK.sink": { - "ConnectionCreatedCount": "109", - "Type": "SINK", - "ConnectionClosedCount": "108", - "BatchCompleteCount": "1567", - "BatchEmptyCount": "11067", - "EventDrainAttemptCount": "260969", - "StartTime": "1503541553174", - "EventDrainSuccessCount": "260969", - "BatchUnderflowCount": "5615", - "StopTime": "0", - "ConnectionFailedCount": "0" - } -} -*/ - -func getTestData() map[string]interface{} { - var data map[string]interface{} - _ = json.Unmarshal([]byte(jsonDate), &data) - return data -} - -func TestParseMetrics(t *testing.T) { - flume := &FlumePlugin{} - ret := flume.parseMetrics(getTestData()) - - // Channel - assert.EqualValues(t, ret["channel.capacity.channel.ChannelCapacity"], 5000000) - assert.EqualValues(t, ret["channel.capacity.channel.ChannelSize"], 0) - assert.EqualValues(t, ret["channel.use_rate.channel.ChannelFillPercentage"], 0) - assert.EqualValues(t, ret["channel.event_put_num.channel.EventPutAttemptCount"], 260969) - assert.EqualValues(t, ret["channel.event_put_num.channel.EventPutSuccessCount"], 260969) - assert.EqualValues(t, ret["channel.event_take_num.channel.EventTakeAttemptCount"], 277651) - assert.EqualValues(t, ret["channel.event_take_num.channel.EventTakeSuccessCount"], 260969) - // Sink - assert.EqualValues(t, ret["sink.batch_num.sink.BatchCompleteCount"], 1567) - assert.EqualValues(t, ret["sink.batch_num.sink.BatchEmptyCount"], 11067) - assert.EqualValues(t, ret["sink.batch_num.sink.BatchUnderflowCount"], 5615) - assert.EqualValues(t, ret["sink.connection.sink.ConnectionCreatedCount"], 109) - assert.EqualValues(t, ret["sink.connection.sink.ConnectionClosedCount"], 108) - assert.EqualValues(t, ret["sink.connection.sink.ConnectionFailedCount"], 0) - assert.EqualValues(t, ret["sink.event_drain_num.sink.EventDrainAttemptCount"], 260969) - assert.EqualValues(t, ret["sink.event_drain_num.sink.EventDrainSuccessCount"], 260969) - // Source - assert.EqualValues(t, ret["source.append_num.source.AppendAcceptedCount"], 0) - assert.EqualValues(t, ret["source.append_num.source.AppendReceivedCount"], 0) - assert.EqualValues(t, ret["source.append_batch_num.source.AppendBatchAcceptedCount"], 8357) - assert.EqualValues(t, ret["source.append_batch_num.source.AppendBatchReceivedCount"], 8357) - assert.EqualValues(t, ret["source.event_num.source.EventAcceptedCount"], 260969) - assert.EqualValues(t, ret["source.event_num.source.EventReceivedCount"], 260969) - assert.EqualValues(t, ret["source.connection.source.OpenConnectionCount"], 0) -} diff --git a/mackerel-plugin-flume/main.go b/mackerel-plugin-flume/main.go index 7aa7d2e45..8d7970cdb 100644 --- a/mackerel-plugin-flume/main.go +++ b/mackerel-plugin-flume/main.go @@ -1,6 +1,6 @@ package main -import "github.com/mackerelio/mackerel-agent-plugins/mackerel-plugin-flume/lib" +import "github.com/mackerelio/mackerel-plugin-flume/lib" func main() { mpflume.Do() diff --git a/t/convention.t b/t/convention.t index 70fe6b753..69dbe0c54 100644 --- a/t/convention.t +++ b/t/convention.t @@ -10,6 +10,7 @@ my $plugins_in_other_repository = [qw( mackerel-plugin-aws-kinesis-firehose mackerel-plugin-aws-rekognition mackerel-plugin-aws-waf + mackerel-plugin-flume mackerel-plugin-gcp-compute-engine mackerel-plugin-gearmand mackerel-plugin-graphite From 20c59e46bd64482f9591d1ef441afd1cd84236dc Mon Sep 17 00:00:00 2001 From: lufia Date: Mon, 12 Dec 2022 18:28:30 +0900 Subject: [PATCH 5/6] remove mackerel-plugin-murmur --- mackerel-plugin-murmur/README.md | 15 +----- mackerel-plugin-murmur/go.mod | 17 +++++++ mackerel-plugin-murmur/go.sum | 38 +++++++++++++++ mackerel-plugin-murmur/lib/murmur.go | 71 ---------------------------- mackerel-plugin-murmur/main.go | 2 +- t/convention.t | 1 + 6 files changed, 59 insertions(+), 85 deletions(-) create mode 100644 mackerel-plugin-murmur/go.mod create mode 100644 mackerel-plugin-murmur/go.sum delete mode 100644 mackerel-plugin-murmur/lib/murmur.go diff --git a/mackerel-plugin-murmur/README.md b/mackerel-plugin-murmur/README.md index 83632f465..791116ca6 100644 --- a/mackerel-plugin-murmur/README.md +++ b/mackerel-plugin-murmur/README.md @@ -1,17 +1,6 @@ mackerel-plugin-murmur ====================== -Murmur custom metrics plugin for mackerel.io agent. +This plugin moved to [mackerelio/mackerel-plugin-murmur][url] -## Synopsis - -```shell -mackerel-plugin-murmur [-host=] [-port=] [-tempfile=] [-timeout=] -``` - -## Example of mackerel-agent.conf - -``` -[plugin.metrics.murmur] -command = "/path/to/mackerel-plugin-murmur -host=localhost -port=64738 -timeout 250" -``` \ No newline at end of file +[url]: https://github.com/mackerelio/mackerel-plugin-murmur diff --git a/mackerel-plugin-murmur/go.mod b/mackerel-plugin-murmur/go.mod new file mode 100644 index 000000000..d60ae6b5e --- /dev/null +++ b/mackerel-plugin-murmur/go.mod @@ -0,0 +1,17 @@ +module github.com/mackerelio/mackerel-agent-plugins/mackerel-plugin-murmur + +go 1.19 + +require ( + github.com/mackerelio/go-mackerel-plugin-helper v0.1.2 + github.com/mackerelio/mackerel-plugin-murmur v1.0.0 + layeh.com/gumble v0.0.0-20221205141517-d1df60a3cc14 +) + +require ( + github.com/golang/protobuf v1.5.2 // indirect + github.com/mackerelio/golib v1.2.1 // indirect + golang.org/x/lint v0.0.0-20210508222113-6edffad5e616 // indirect + golang.org/x/tools v0.1.5 // indirect + google.golang.org/protobuf v1.27.1 // indirect +) diff --git a/mackerel-plugin-murmur/go.sum b/mackerel-plugin-murmur/go.sum new file mode 100644 index 000000000..419bdffc3 --- /dev/null +++ b/mackerel-plugin-murmur/go.sum @@ -0,0 +1,38 @@ +github.com/dchote/go-openal v0.0.0-20171116030048-f4a9a141d372/go.mod h1:74z+CYu2/mx4N+mcIS/rsvfAxBPBV9uv8zRAnwyFkdI= +github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= +github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw= +github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= +github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.7 h1:81/ik6ipDQS2aGcBfIN5dHDB36BwrStyeAQquSYCV4o= +github.com/mackerelio/go-mackerel-plugin-helper v0.1.2 h1:p/KTlMK/mocWAIjNuYzpCybYvkfAEroDZBDAiOuz2QQ= +github.com/mackerelio/go-mackerel-plugin-helper v0.1.2/go.mod h1:Vfs2Fk1FfE8c8mufAQKcWBtGI0GCrOLGvaJg+kS5yz4= +github.com/mackerelio/golib v1.2.1 h1:SDcDn6Jw3p9bi1N0bg1Z/ilG5qcBB23qL8xNwrU0gg4= +github.com/mackerelio/golib v1.2.1/go.mod h1:b8ZaapsHGH1FlEJlCqfD98CqafLeyMevyATDlID2BsM= +github.com/mackerelio/mackerel-plugin-murmur v1.0.0 h1:wqDh/698DRxYfXy3qiQskQ4VQBQN17q2ifMgLwdh5ps= +github.com/mackerelio/mackerel-plugin-murmur v1.0.0/go.mod h1:8eFvDM9WIF2Ifr8ou0IgLBBOLXnnuG5+CJIJ5wjqk6c= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/lint v0.0.0-20210508222113-6edffad5e616 h1:VLliZ0d+/avPrXXH+OakdXhpJuEoBZuwh1m2j7U6Iug= +golang.org/x/lint v0.0.0-20210508222113-6edffad5e616/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY= +golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg= +golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20220319134239-a9b59b0215f8 h1:OH54vjqzRWmbJ62fjuhxy7AxFFgoHN0/DPc/UrL8cAs= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/tools v0.0.0-20200130002326-2f3ba24bd6e7/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.1.5 h1:ouewzE6p+/VEB31YYnTbEJdi8pFqKp4P4n85vwo3DHA= +golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= +golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE= +google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= +google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= +google.golang.org/protobuf v1.27.1 h1:SnqbnDw1V7RiZcXPx5MEeqPv2s79L9i7BJUlG/+RurQ= +google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= +layeh.com/gopus v0.0.0-20161224163843-0ebf989153aa/go.mod h1:AOef7vHz0+v4sWwJnr0jSyHiX/1NgsMoaxl+rEPz/I0= +layeh.com/gumble v0.0.0-20221205141517-d1df60a3cc14 h1:wY8eeq7DpM5iAugNbFrvuhdtmN8XM1iU+Ki5YZWjukg= +layeh.com/gumble v0.0.0-20221205141517-d1df60a3cc14/go.mod h1:tWPVA9ZAfImNwabjcd9uDE+Mtz0Hfs7a7G3vxrnrwyc= diff --git a/mackerel-plugin-murmur/lib/murmur.go b/mackerel-plugin-murmur/lib/murmur.go deleted file mode 100644 index d2e2bd781..000000000 --- a/mackerel-plugin-murmur/lib/murmur.go +++ /dev/null @@ -1,71 +0,0 @@ -package mpmurmur - -import ( - "flag" - "fmt" - "time" - - mp "github.com/mackerelio/go-mackerel-plugin-helper" - "layeh.com/gumble/gumble" -) - -var graphdef = map[string]mp.Graphs{ - "murmur.connections": { - Label: "Murmur Connections", - Unit: "integer", - Metrics: []mp.Metrics{ - {Name: "con_cur", Label: "Current users", Diff: false, Type: "uint32"}, - {Name: "con_max", Label: "Maximum users", Diff: false, Type: "uint32"}, - }, - }, -} - -// MurmurPlugin mackerel plugin for Murmur -type MurmurPlugin struct { - Host string - Timeout uint64 -} - -// FetchMetrics interface for mackerelplugin -func (m MurmurPlugin) FetchMetrics() (map[string]interface{}, error) { - resp, err := gumble.Ping(m.Host, 0, time.Millisecond*time.Duration(m.Timeout)) - - if err != nil { - return nil, err - } - - metrics := map[string]interface{}{ - "con_cur": uint32(resp.ConnectedUsers), - "con_max": uint32(resp.MaximumUsers), - } - - return metrics, nil -} - -// GraphDefinition interface for mackerelplugin -func (m MurmurPlugin) GraphDefinition() map[string]mp.Graphs { - return graphdef -} - -// Do the plugin -func Do() { - optHost := flag.String("host", "localhost", "Hostname") - optPort := flag.String("port", "64738", "Port") - optTimeout := flag.Uint64("timeout", 1000, "Timeout (ms)") - optTempfile := flag.String("tempfile", "", "Temp file name") - flag.Parse() - - var murmur MurmurPlugin - - murmur.Host = fmt.Sprintf("%s:%s", *optHost, *optPort) - murmur.Timeout = *optTimeout - helper := mp.NewMackerelPlugin(murmur) - - if *optTempfile != "" { - helper.Tempfile = *optTempfile - } else { - helper.SetTempfileByBasename(fmt.Sprintf("mackerel-plugin-murmur-%s-%s", *optHost, *optPort)) - } - - helper.Run() -} diff --git a/mackerel-plugin-murmur/main.go b/mackerel-plugin-murmur/main.go index ede36d592..11e7173bb 100644 --- a/mackerel-plugin-murmur/main.go +++ b/mackerel-plugin-murmur/main.go @@ -1,6 +1,6 @@ package main -import "github.com/mackerelio/mackerel-agent-plugins/mackerel-plugin-murmur/lib" +import "github.com/mackerelio/mackerel-plugin-murmur/lib" func main() { mpmurmur.Do() diff --git a/t/convention.t b/t/convention.t index 69dbe0c54..85fa6403e 100644 --- a/t/convention.t +++ b/t/convention.t @@ -15,6 +15,7 @@ my $plugins_in_other_repository = [qw( mackerel-plugin-gearmand mackerel-plugin-graphite mackerel-plugin-json + mackerel-plugin-murmur mackerel-plugin-nvidia-smi mackerel-plugin-xentop )]; From 5672761a9d93da43cd3f103a9a1ef3efb57ba49e Mon Sep 17 00:00:00 2001 From: lufia Date: Mon, 12 Dec 2022 18:28:59 +0900 Subject: [PATCH 6/6] cleanup go.mod and go.sum --- go.mod | 1 - go.sum | 4 ---- 2 files changed, 5 deletions(-) diff --git a/go.mod b/go.mod index b134e7192..e5b497468 100644 --- a/go.mod +++ b/go.mod @@ -43,7 +43,6 @@ require ( github.com/ziutek/mymysql v1.5.4 golang.org/x/sync v0.1.0 golang.org/x/text v0.5.0 - layeh.com/gumble v0.0.0-20200818122324-146f9205029b ) require ( diff --git a/go.sum b/go.sum index d2c36d03a..cacd3fe12 100644 --- a/go.sum +++ b/go.sum @@ -265,7 +265,6 @@ github.com/d2g/hardwareaddr v0.0.0-20190221164911-e7d9fbe030e4/go.mod h1:bMl4RjI github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/dchote/go-openal v0.0.0-20171116030048-f4a9a141d372/go.mod h1:74z+CYu2/mx4N+mcIS/rsvfAxBPBV9uv8zRAnwyFkdI= github.com/denverdino/aliyungo v0.0.0-20190125010748-a747050bb1ba/go.mod h1:dV8lFg6daOBZbT6/BDGIz6Y3WFGn8juu6G+CQ6LHtl0= github.com/dgrijalva/jwt-go v0.0.0-20170104182250-a601269ab70c/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ= github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ= @@ -1274,9 +1273,6 @@ k8s.io/kube-openapi v0.0.0-20200805222855-6aeccd4b50c6/go.mod h1:UuqjUnNftUyPE5H k8s.io/kube-openapi v0.0.0-20201113171705-d219536bb9fd/go.mod h1:WOJ3KddDSol4tAGcJo0Tvi+dK12EcqSLqcWsryKMpfM= k8s.io/kubernetes v1.13.0/go.mod h1:ocZa8+6APFNC2tX1DZASIbocyYT5jHzqFVsY5aoB7Jk= k8s.io/utils v0.0.0-20201110183641-67b214c5f920/go.mod h1:jPW/WVKK9YHAvNhRxK0md/EJ228hCsBRufyofKtW8HA= -layeh.com/gopus v0.0.0-20161224163843-0ebf989153aa/go.mod h1:AOef7vHz0+v4sWwJnr0jSyHiX/1NgsMoaxl+rEPz/I0= -layeh.com/gumble v0.0.0-20200818122324-146f9205029b h1:Kne6wkHqbqrygRsqs5XUNhSs84DFG5TYMeCkCbM56sY= -layeh.com/gumble v0.0.0-20200818122324-146f9205029b/go.mod h1:tWPVA9ZAfImNwabjcd9uDE+Mtz0Hfs7a7G3vxrnrwyc= rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8= rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0= rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA=