Skip to content
This repository has been archived by the owner on Nov 8, 2022. It is now read-only.

Commit

Permalink
New metric schema
Browse files Browse the repository at this point in the history
  • Loading branch information
tiffanyfay committed May 5, 2016
1 parent 9b60b7f commit 5f5c089
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 31 deletions.
2 changes: 1 addition & 1 deletion .gitignore
@@ -1,2 +1,2 @@
snap-collector-etcd
snap-plugin-collector-etcd
build
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Expand Up @@ -10,7 +10,7 @@ This repository has dedicated developers from Intel working on updates. The most
## Contributing Code
**_IMPORTANT_**: We encourage contributions to the project from the community. We ask that you keep the following guidelines in mind when planning your contribution.

* Whether your contribution is for a bug fix or a feature request, **create an [Issue](https://github.com/intelsdi-x/snap-collector-etcd/issues)** and let us know what you are thinking
* Whether your contribution is for a bug fix or a feature request, **create an [Issue](https://github.com/intelsdi-x/snap-plugin-collector-etcd/issues)** and let us know what you are thinking
* **For bugs**, if you have already found a fix, feel free to submit a Pull Request referencing the Issue you created
* **For feature requests**, we want to improve upon the library incrementally which means small changes at a time. In order ensure your PR can be reviewed in a timely manner, please keep PRs small, e.g. <10 files and <500 lines changed. If you think this is unrealistic, then mention that within the issue and we can discuss it

Expand Down
58 changes: 47 additions & 11 deletions Godeps/Godeps.json 100644 → 100755

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -30,7 +30,7 @@ All OSs currently supported by snap:
Clone repo into `$GOPATH/src/github.com/intelsdi-x/`:

```
$ git clone https://github.com/intelsdi-x/snap-collector-etcd.git
$ git clone https://github.com/intelsdi-x/snap-plugin-collector-etcd.git
```

Build the plugin by running make within the cloned repo:
Expand Down
29 changes: 13 additions & 16 deletions etcd/etcd.go
Expand Up @@ -19,13 +19,13 @@ import (
"errors"
"fmt"
"net/http"
"os"
"strconv"
"strings"
"time"

"github.com/intelsdi-x/snap/control/plugin"
"github.com/intelsdi-x/snap/control/plugin/cpolicy"
"github.com/intelsdi-x/snap/core"
"github.com/intelsdi-x/snap/core/ctypes"
)

Expand Down Expand Up @@ -74,7 +74,7 @@ var (

type Etcd struct{}

func (e *Etcd) CollectMetrics(mts []plugin.PluginMetricType) ([]plugin.PluginMetricType, error) {
func (e *Etcd) CollectMetrics(mts []plugin.MetricType) ([]plugin.MetricType, error) {
config := mts[0].Config().Table()
hostcfg, ok := config["etcd_host"]
if !ok {
Expand All @@ -87,14 +87,14 @@ func (e *Etcd) CollectMetrics(mts []plugin.PluginMetricType) ([]plugin.PluginMet

filter := make([]string, len(mts))
for i, m := range mts {
filter[i] = m.Namespace_[len(m.Namespace_)-1]
filter[i] = m.Namespace().Strings()[len(m.Namespace().Strings())-1]
}

return gathermts(host.Value, filter)
}

//GetMetricTypes returns metric types for testing
func (e *Etcd) GetMetricTypes(cfg plugin.PluginConfigType) ([]plugin.PluginMetricType, error) {
func (e *Etcd) GetMetricTypes(cfg plugin.ConfigType) ([]plugin.MetricType, error) {
hostcfg, ok := cfg.Table()["etcd_host"]
if !ok {
return nil, errNoHost
Expand Down Expand Up @@ -129,7 +129,7 @@ func Meta() *plugin.PluginMeta {
)
}

func gathermts(host string, filter []string) ([]plugin.PluginMetricType, error) {
func gathermts(host string, filter []string) ([]plugin.MetricType, error) {
resp, err := http.Get(fmt.Sprintf("%s/metrics", host))
if err != nil {
return nil, err
Expand All @@ -138,10 +138,9 @@ func gathermts(host string, filter []string) ([]plugin.PluginMetricType, error)
return nil, errReqFailed
}

mtsmap := make(map[string]plugin.PluginMetricType)
mtsmap := make(map[string]plugin.MetricType)
scanner := bufio.NewScanner(resp.Body)

hn, err := os.Hostname()
if err != nil {
return nil, err
}
Expand All @@ -150,37 +149,35 @@ func gathermts(host string, filter []string) ([]plugin.PluginMetricType, error)
txt := scanner.Text()
if !strings.Contains(txt, "{") && !strings.Contains(txt, "#") {
nsslice := strings.Split(txt, " ")
mtsmap[nsslice[0]] = plugin.PluginMetricType{
Namespace_: []string{"intel", "etcd", nsslice[0]},
mtsmap[nsslice[0]] = plugin.MetricType{
Namespace_: core.NewNamespace("intel", "etcd", nsslice[0]),
Data_: nsslice[1],
Source_: hn,
Timestamp_: time.Now(),
}
}
}

// No filter given; this was a GetMetricTypes call.
if len(filter) == 0 {
mts := make([]plugin.PluginMetricType, 0, len(mtsmap)+len(derivatives))
mts := make([]plugin.MetricType, 0, len(mtsmap)+len(derivatives))
for _, v := range mtsmap {
mts = append(mts, v)
}
for k := range derivatives {
mts = append(mts, plugin.PluginMetricType{Namespace_: []string{"intel", "etcd", "derivative", k}})
mts = append(mts, plugin.MetricType{Namespace_: core.NewNamespace("intel", "etcd", "derivative", k)})
}
return mts, nil
}

// Walk through filter and pluck out metrics.
// if we find the requested metric in derivatives,
// then derive the value from `from`.
mts := make([]plugin.PluginMetricType, 0, len(filter))
mts := make([]plugin.MetricType, 0, len(filter))
for _, f := range filter {
from, ok := derivatives[f]
if ok {
mt := plugin.PluginMetricType{
Namespace_: []string{"intel", "etcd", "derivative", f},
Source_: hn,
mt := plugin.MetricType{
Namespace_: core.NewNamespace("intel", "etcd", "derivative", f),
Timestamp_: time.Now(),
}
sum, err := strconv.ParseFloat(mtsmap[from[0]].Data_.(string), 64)
Expand Down
2 changes: 1 addition & 1 deletion main.go
Expand Up @@ -17,7 +17,7 @@ package main
import (
"os"

"github.com/intelsdi-x/snap-collector-etcd/etcd"
"github.com/intelsdi-x/snap-plugin-collector-etcd/etcd"
"github.com/intelsdi-x/snap/control/plugin"
)

Expand Down

0 comments on commit 5f5c089

Please sign in to comment.