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

Commit

Permalink
Merge pull request #9 from tiffanyfj/schema
Browse files Browse the repository at this point in the history
New Metric Schema
  • Loading branch information
tiffanyfay committed May 6, 2016
2 parents 8e37978 + 7244d90 commit 53a8962
Show file tree
Hide file tree
Showing 7 changed files with 106 additions and 79 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
sudo: required
language: go
go:
- 1.5.3
- 1.6
- 1.5.4
- 1.6.2
env:
global:
- SNAP_PLUGIN_SOURCE=/home/travis/gopath/src/github.com/intelsdi-x/snap-plugin-collector-dbi
Expand Down
77 changes: 57 additions & 20 deletions Godeps/Godeps.json

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

49 changes: 22 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,24 +167,19 @@ Create configuration file for dbi plugin (see [examples/configs/setfiles/dbi_cin

Set path to configuration file as `setfile` in Global Config (see [examples/configs/snap-config-sample.json](examples/configs/snap-config-sample.json)):
```json

{
"control": {
"cache_ttl": "5s"
},
"scheduler": {
"default_deadline": "5s",
"worker_pool_size": 5
},
"plugins": {
"collector": {
"dbi": {
"all": {
"setfile": "$SNAP_DBI_PLUGIN_DIR/examples/configs/setfiles/dbi_cinder_services.json"
"plugins": {
"collector": {
"dbi": {
"all": {
"setfile": "$SNAP_DBI_PLUGIN_DIR/examples/configs/setfiles/dbi_cinder_services.json"
}
}
}
},
"publisher": {},
"processor": {}
},
"publisher": {},
"processor": {}
}
}
}

Expand All @@ -200,7 +195,7 @@ Load dbi plugin for collecting:
$ snapctl plugin load $SNAP_DBI_PLUGIN_DIR/build/rootfs/snap-plugin-collector-dbi
Plugin loaded
Name: dbi
Version: 3
Version: 4
Type: collector
Signed: false
Loaded Time: Tue, 05 Apr 2016 07:49:53 UTC
Expand All @@ -211,23 +206,23 @@ See available metrics:
$ snapctl metric list
NAMESPACE VERSIONS
/intel/dbi/cinder/services/backup/disabled 3
/intel/dbi/cinder/services/backup/down 3
/intel/dbi/cinder/services/backup/up 3
/intel/dbi/cinder/services/scheduler/disabled 3
/intel/dbi/cinder/services/scheduler/down 3
/intel/dbi/cinder/services/scheduler/up 3
/intel/dbi/cinder/services/volume/disabled 3
/intel/dbi/cinder/services/volume/down 3
/intel/dbi/cinder/services/volume/up 3
/intel/dbi/cinder/services/backup/disabled 4
/intel/dbi/cinder/services/backup/down 4
/intel/dbi/cinder/services/backup/up 4
/intel/dbi/cinder/services/scheduler/disabled 4
/intel/dbi/cinder/services/scheduler/down 4
/intel/dbi/cinder/services/scheduler/up 4
/intel/dbi/cinder/services/volume/disabled 4
/intel/dbi/cinder/services/volume/down 4
/intel/dbi/cinder/services/volume/up 4
```

Load file plugin for publishing:
```
$ snapctl plugin load $SNAP_DIR/build/plugin/snap-publisher-file
Plugin loaded
Name: file
Version: 3
Version: 4
Type: publisher
Signed: false
Loaded Time: Tue, 05 Apr 2016 07:49:18 UTC
Expand Down
21 changes: 10 additions & 11 deletions dbi/dbi.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,14 @@ import (
"github.com/intelsdi-x/snap-plugin-utilities/config"
"github.com/intelsdi-x/snap/control/plugin"
"github.com/intelsdi-x/snap/control/plugin/cpolicy"
"github.com/intelsdi-x/snap/core"
)

const (
// Name of plugin
Name = "dbi"
// Version of plugin
Version = 3
Version = 4
// Type of plugin
Type = plugin.CollectorPluginType
)
Expand All @@ -47,10 +48,10 @@ type DbiPlugin struct {
}

// CollectMetrics returns values of desired metrics defined in mts
func (dbiPlg *DbiPlugin) CollectMetrics(mts []plugin.PluginMetricType) ([]plugin.PluginMetricType, error) {
func (dbiPlg *DbiPlugin) CollectMetrics(mts []plugin.MetricType) ([]plugin.MetricType, error) {

var err error
metrics := []plugin.PluginMetricType{}
metrics := []plugin.MetricType{}
data := map[string]interface{}{}

// initialization - done once
Expand All @@ -76,15 +77,13 @@ func (dbiPlg *DbiPlugin) CollectMetrics(mts []plugin.PluginMetricType) ([]plugin
return nil, err
}

hostname, _ := os.Hostname()

for _, m := range mts {
if value, ok := data[joinNamespace(m.Namespace())]; ok {
metric := plugin.PluginMetricType{
if value, ok := data[m.Namespace().String()]; ok {
metric := plugin.MetricType{
Namespace_: m.Namespace(),
Data_: value,
Source_: hostname,
Timestamp_: time.Now(),
Tags_: m.Tags(),
Version_: m.Version(),
}
metrics = append(metrics, metric)
Expand All @@ -102,9 +101,9 @@ func (dbiPlg *DbiPlugin) GetConfigPolicy() (*cpolicy.ConfigPolicy, error) {
}

// GetMetricTypes returns metrics types exposed by snap-plugin-collector-dbi
func (dbiPlg *DbiPlugin) GetMetricTypes(cfg plugin.PluginConfigType) ([]plugin.PluginMetricType, error) {
func (dbiPlg *DbiPlugin) GetMetricTypes(cfg plugin.ConfigType) ([]plugin.MetricType, error) {
metrics := map[string]interface{}{}
mts := []plugin.PluginMetricType{}
mts := []plugin.MetricType{}

err := dbiPlg.setConfig(cfg)
if err != nil {
Expand All @@ -118,7 +117,7 @@ func (dbiPlg *DbiPlugin) GetMetricTypes(cfg plugin.PluginConfigType) ([]plugin.P
}

for name := range metrics {
mts = append(mts, plugin.PluginMetricType{Namespace_: splitNamespace(name)})
mts = append(mts, plugin.MetricType{Namespace_: core.NewNamespace(splitNamespace(name)...)})
}

return mts, nil
Expand Down
2 changes: 1 addition & 1 deletion dbi/dbi_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// +build linux
// +build linux unit

/*
http://www.apache.org/licenses/LICENSE-2.0.txt
Expand Down
27 changes: 14 additions & 13 deletions dbi/mock/mockData.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,32 +20,33 @@ import (
"time"

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

var (

// Mts is a mocked metrics
Mts = []plugin.PluginMetricType{
Mts = []plugin.MetricType{

// 1) For db = dbName1 one query=q1 is executed which has no additional info (like name or prefix)
plugin.PluginMetricType{Namespace_: []string{"intel", "dbi", "dbName1", "categoryA"}},
plugin.PluginMetricType{Namespace_: []string{"intel", "dbi", "dbName1", "categoryB"}},
plugin.PluginMetricType{Namespace_: []string{"intel", "dbi", "dbName1", "categoryC"}},
plugin.MetricType{Namespace_: core.NewNamespace("intel", "dbi", "dbName1", "categoryA")},
plugin.MetricType{Namespace_: core.NewNamespace("intel", "dbi", "dbName1", "categoryB")},
plugin.MetricType{Namespace_: core.NewNamespace("intel", "dbi", "dbName1", "categoryC")},

// 2) For db = dbName2 two queries are executed:
// a) query=q1 - has no additional info (like name or prefix)
plugin.PluginMetricType{Namespace_: []string{"intel", "dbi", "dbName2", "categoryA"}},
plugin.PluginMetricType{Namespace_: []string{"intel", "dbi", "dbName2", "categoryB"}},
plugin.PluginMetricType{Namespace_: []string{"intel", "dbi", "dbName2", "categoryC"}},
plugin.MetricType{Namespace_: core.NewNamespace("intel", "dbi", "dbName2", "categoryA")},
plugin.MetricType{Namespace_: core.NewNamespace("intel", "dbi", "dbName2", "categoryB")},
plugin.MetricType{Namespace_: core.NewNamespace("intel", "dbi", "dbName2", "categoryC")},

// b) query=q2 - has defined additional info (like resultName or instancePrefix) which are appended to a namespace
plugin.PluginMetricType{Namespace_: []string{"intel", "dbi", "dbName2", "rName1", "category_prefix", "categoryA"}},
plugin.PluginMetricType{Namespace_: []string{"intel", "dbi", "dbName2", "rName1", "category_prefix", "categoryB"}},
plugin.PluginMetricType{Namespace_: []string{"intel", "dbi", "dbName2", "rName1", "category_prefix", "categoryC"}},
plugin.MetricType{Namespace_: core.NewNamespace("intel", "dbi", "dbName2", "rName1", "category_prefix", "categoryA")},
plugin.MetricType{Namespace_: core.NewNamespace("intel", "dbi", "dbName2", "rName1", "category_prefix", "categoryB")},
plugin.MetricType{Namespace_: core.NewNamespace("intel", "dbi", "dbName2", "rName1", "category_prefix", "categoryC")},

plugin.PluginMetricType{Namespace_: []string{"intel", "dbi", "dbName2", "rName2", "categoryA"}},
plugin.PluginMetricType{Namespace_: []string{"intel", "dbi", "dbName2", "rName2", "categoryB"}},
plugin.PluginMetricType{Namespace_: []string{"intel", "dbi", "dbName2", "rName2", "categoryC"}},
plugin.MetricType{Namespace_: core.NewNamespace("intel", "dbi", "dbName2", "rName2", "categoryA")},
plugin.MetricType{Namespace_: core.NewNamespace("intel", "dbi", "dbName2", "rName2", "categoryB")},
plugin.MetricType{Namespace_: core.NewNamespace("intel", "dbi", "dbName2", "rName2", "categoryC")},
}

// QueryOutput is a mocked query output
Expand Down
5 changes: 0 additions & 5 deletions examples/configs/snap-config-sample.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"control": {
"cache_ttl": "5s",
"plugins": {
"collector": {
"dbi": {
Expand All @@ -12,9 +11,5 @@
"publisher": {},
"processor": {}
}
},
"scheduler": {
"default_deadline": "5s",
"worker_pool_size": 5
}
}

0 comments on commit 53a8962

Please sign in to comment.