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 marcin-krolik/kromar-core-namespace
Browse files Browse the repository at this point in the history
New metric schema
  • Loading branch information
marcin-krolik committed May 11, 2016
2 parents cabdf5d + 36960bc commit e2c0fad
Show file tree
Hide file tree
Showing 6 changed files with 112 additions and 129 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
before_install:
- go get github.com/tools/godep
- if [ ! -d $SNAP_PLUGIN_SOURCE ]; then mkdir -p $HOME/gopath/src/github.com/intelsdi-x; ln -s $TRAVIS_BUILD_DIR $SNAP_PLUGIN_SOURCE; fi # CI for forks not from intelsdi-x
Expand Down
117 changes: 61 additions & 56 deletions Godeps/Godeps.json

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

42 changes: 17 additions & 25 deletions collector/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ package collector

import (
"fmt"
"os"
"strings"
"sync"
"time"
Expand All @@ -25,10 +24,11 @@ import (

"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-plugin-utilities/config"
"github.com/intelsdi-x/snap-plugin-utilities/ns"
str "github.com/intelsdi-x/snap-plugin-utilities/strings"
"github.com/intelsdi-x/snap-plugin-utilities/str"

openstackintel "github.com/intelsdi-x/snap-plugin-collector-cinder/openstack"
"github.com/intelsdi-x/snap-plugin-collector-cinder/openstack/services"
Expand All @@ -37,24 +37,18 @@ import (

const (
name = "cinder"
version = 1
version = 2
plgtype = plugin.CollectorPluginType
vendor = "intel"
fs = "openstack"
)

// New creates initialized instance of Cinder collector
func New() *collector {
host, err := os.Hostname()
if err != nil {
host = "localhost"
}

providers := map[string]*gophercloud.ProviderClient{}
allTenants := map[string]string{}
allLimits := map[string]types.Limits{}
return &collector{
host: host,
allTenants: allTenants,
providers: providers,
allLimits: allLimits,
Expand All @@ -63,8 +57,8 @@ func New() *collector {

// GetMetricTypes returns list of available metric types
// It returns error in case retrieval was not successful
func (c *collector) GetMetricTypes(cfg plugin.PluginConfigType) ([]plugin.PluginMetricType, error) {
mts := []plugin.PluginMetricType{}
func (c *collector) GetMetricTypes(cfg plugin.ConfigType) ([]plugin.MetricType, error) {
mts := []plugin.MetricType{}

var err error
c.allTenants, err = getTenants(cfg)
Expand All @@ -86,8 +80,8 @@ func (c *collector) GetMetricTypes(cfg plugin.PluginConfigType) ([]plugin.Plugin
}

for _, namespace := range namespaces {
mts = append(mts, plugin.PluginMetricType{
Namespace_: strings.Split(namespace, "/"),
mts = append(mts, plugin.MetricType{
Namespace_: core.NewNamespace(strings.Split(namespace, "/")...),
Config_: cfg.ConfigDataNode,
})
}
Expand All @@ -97,7 +91,7 @@ func (c *collector) GetMetricTypes(cfg plugin.PluginConfigType) ([]plugin.Plugin

// CollectMetrics returns list of requested metric values
// It returns error in case retrieval was not successful
func (c *collector) CollectMetrics(metricTypes []plugin.PluginMetricType) ([]plugin.PluginMetricType, error) {
func (c *collector) CollectMetrics(metricTypes []plugin.MetricType) ([]plugin.MetricType, error) {
// get admin tenant from configuration. admin tenant is needed for gathering volumes and snapshots metrics at once
item, err := config.GetConfigItem(metricTypes[0], "tenant")
if err != nil {
Expand All @@ -123,12 +117,12 @@ func (c *collector) CollectMetrics(metricTypes []plugin.PluginMetricType) ([]plu
return nil, fmt.Errorf("Incorrect namespace lenth. Expected 6 is %d", len(namespace))
}

tenant := namespace[3]
tenant := namespace[3].Value
collectTenants.Add(tenant)

if str.Contains(namespace, "limits") {
if str.Contains(namespace.Strings(), "limits") {
collectLimits = true
} else if str.Contains(namespace, "volumes") {
} else if str.Contains(namespace.Strings(), "volumes") {
collectVolumes = true
} else {
collectSnapshots = true
Expand Down Expand Up @@ -223,9 +217,9 @@ func (c *collector) CollectMetrics(metricTypes []plugin.PluginMetricType) ([]plu
}
}

metrics := []plugin.PluginMetricType{}
metrics := []plugin.MetricType{}
for _, metricType := range metricTypes {
namespace := metricType.Namespace()
namespace := metricType.Namespace().Strings()
tenant := namespace[3]
// Construct temporary struct to accommodate all gathered metrics
metricContainer := struct {
Expand All @@ -239,10 +233,9 @@ func (c *collector) CollectMetrics(metricTypes []plugin.PluginMetricType) ([]plu
}

// Extract values by namespace from temporary struct and create metrics
metric := plugin.PluginMetricType{
Source_: c.host,
metric := plugin.MetricType{
Timestamp_: time.Now(),
Namespace_: namespace,
Namespace_: metricType.Namespace(),
Data_: ns.GetValueByNamespace(metricContainer, namespace[4:]),
}
metrics = append(metrics, metric)
Expand Down Expand Up @@ -271,7 +264,6 @@ func Meta() *plugin.PluginMeta {
}

type collector struct {
host string
allTenants map[string]string
service services.Service
common openstackintel.Commoner
Expand All @@ -282,7 +274,7 @@ type collector struct {
func (c *collector) authenticate(cfg interface{}, tenant string) error {
if _, found := c.providers[tenant]; !found {
// get credentials and endpoint from configuration
items, err := config.GetConfigItems(cfg, []string{"endpoint", "user", "password"})
items, err := config.GetConfigItems(cfg, "endpoint", "user", "password")
if err != nil {
return err
}
Expand All @@ -307,7 +299,7 @@ func (c *collector) authenticate(cfg interface{}, tenant string) error {
}

func getTenants(cfg interface{}) (map[string]string, error) {
items, err := config.GetConfigItems(cfg, []string{"endpoint", "user", "password"})
items, err := config.GetConfigItems(cfg, "endpoint", "user", "password")
if err != nil {
return nil, err
}
Expand Down
Loading

0 comments on commit e2c0fad

Please sign in to comment.