Skip to content

Commit

Permalink
Fixed intelsdi-x#1675: Updated exemplary streaming collector plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
IzabellaRaulin committed Jul 6, 2017
1 parent a492827 commit 28e5473
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion glide.lock

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

Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ limitations under the License.
package main

import (
"github.com/intelsdi-x/snap-plugin-lib-go/examples/snap-plugin-collector-rand-streaming/rand"
"github.com/intelsdi-x/snap-plugin-lib-go/v1/plugin"
"github.com/intelsdi-x/snap/plugin/collector/snap-plugin-stream-collector-rand1/rand"
)

const (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ limitations under the License.
package rand

import (
"context"
"fmt"
"math/rand"
"time"
Expand Down Expand Up @@ -61,21 +62,21 @@ type RandCollector struct {
metrics []plugin.Metric
}

// StreamMetrics taks both an in and out channel of []plugin.Metric
// StreamMetrics takes both an in and out channel of []plugin.Metric
//
// The metrics_in channel is used to set/update the metrics that Snap is
// currently requesting to be collected by the plugin.
//
// The metrics_out channel is used by the plugin to send the collected metrics
// to Snap.
func (r *RandCollector) StreamMetrics(
ctx context.Context,
metrics_in chan []plugin.Metric,
metrics_out chan []plugin.Metric,
err chan string) error {

go r.streamIt(metrics_out, err)
go r.drainMetrics(metrics_in)

r.drainMetrics(metrics_in)
return nil
}

Expand Down Expand Up @@ -125,7 +126,7 @@ func (r *RandCollector) streamIt(ch chan []plugin.Metric, err chan string) {
}
}
ch <- metrics
time.Sleep(time.Second * time.Duration(rand.Int63n(10)))
time.Sleep(time.Millisecond * time.Duration(rand.Int63n(1000)))
}
}

Expand All @@ -145,7 +146,6 @@ func (RandCollector) GetMetricTypes(cfg plugin.Config) ([]plugin.Metric, error)
for _, val := range vals {
metric := plugin.Metric{
Namespace: plugin.NewNamespace("random", val),
Version: 1,
}
metrics = append(metrics, metric)
}
Expand Down

0 comments on commit 28e5473

Please sign in to comment.