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 #1 from lynxbat/master
Browse files Browse the repository at this point in the history
Inital commit. Beginning of use on Intel SDI github
  • Loading branch information
lynxbat committed Aug 13, 2014
2 parents d7f2476 + f370881 commit 8e08252
Show file tree
Hide file tree
Showing 13 changed files with 1,189 additions and 0 deletions.
109 changes: 109 additions & 0 deletions agent/agent.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
package agent

import (
"github.com/lynxbat/pulse/agent/collection"
"github.com/lynxbat/pulse/agent/scheduling"
"github.com/lynxbat/pulse/agent/publishing"
"fmt"
"time"
)

// TODO defined by Collector Config
var caching = true
var caching_ttl float64 = 1

// MAC
// Move out
//const UNIX_SOCK = "/usr/local/Cellar/collectd/5.4.1/var/run/collectd-unixsock"

// VM
// Move out
// TODO defined by Collector Config
const UNIX_SOCK = "/var/run/collectd-unixsock"

type CommandResponse struct {
Message string
StatusCode int
}

func GetMetricList() []collection.Metric{
// TODO make all collector plugins explicit
// CollectD collector
collectd_coll := collection.NewCollectDCollector(UNIX_SOCK, caching, caching_ttl)
metrics := collectd_coll.GetMetricList()

// TODO make all collector plugins explicit
// Facter collector
facter_coll := collection.NewFacterCollector("facter", caching, caching_ttl)
metrics = append(metrics, facter_coll.GetMetricList()...)

// TODO make all collector plugins explicit
// Container collector
container_coll := collection.NewContainerCollector()
metrics = append(metrics, container_coll.GetMetricList()...)


// metrics := []collection.Metric{}
return metrics
}

// TODO convert string to CollectorConfig interface once implemented
func GetMetricValues(string...interface {}) []collection.Metric{
// Our metric slice
metrics := []collection.Metric{}
// TODO collect for each collector provided
// <>
// Static for now
metrics = getFromCollectDCollector(metrics)
// metrics = getFromFacterCollector(metrics)
metrics = getFromLibcontainerCollector(metrics)
//
return metrics
}

func StartScheduler() {

metrics := GetMetricValues()
// Testing scheduler

// convert to newMetricTask to add error handling on construction

start := time.Now()
// stop := time.Now().Add(time.Hour * 24 * 30)

t := scheduling.MetricTask{
Label: "Foo",
Metadata: map[string]string{
"created_at": time.Now().Format("2006/01/02 15:04:05"),
"source": "code debugging",
"created_by": "nick",
},
Metrics: metrics[len(metrics)-3:],
// start, stop, interval
Schedule: scheduling.NewSchedule(time.Second * 10, start),
PublisherConfig: publishing.STDOUTPublishingConfig{},
}
fmt.Println(t)
}

func getFromCollectDCollector(metrics []collection.Metric) []collection.Metric{
c := collection.NewCollectDCollector(UNIX_SOCK, caching, caching_ttl)
new_metrics := c.GetMetricValues(c.GetMetricList())
return append(metrics, new_metrics...)
}

func getFromFacterCollector(metrics []collection.Metric) []collection.Metric{
c := collection.NewFacterCollector("facter", caching, caching_ttl)
new_metrics := c.GetMetricValues(c.GetMetricValues([]collection.Metric{}))
return append(metrics, new_metrics...)
}

func getFromLibcontainerCollector(metrics []collection.Metric) []collection.Metric{
c := collection.NewContainerCollector()
new_metrics := c.GetMetricValues()
return append(metrics, new_metrics...)
}




267 changes: 267 additions & 0 deletions agent/bench_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,267 @@
package agent

import (
"testing"
"github.com/lynxbat/pulse/agent/collection"
"runtime"
)

const test_caching = true
const test_caching_ttl float64 = 5

func TestMetric(t *testing.T) {}

func BenchmarkMetricCollectDSingleCore(b *testing.B) {
count := 1
c := collection.NewCollectDCollector(UNIX_SOCK, test_caching, test_caching_ttl)
l := c.GetMetricList()
addition := count - len(l)

for x := 0; x < addition; x++ {
l = append(l, l[0])
}
l = l[:count]

// fmt.Printf("\nTotal metrics: %v\n", len(l))
for n := 0; n < b.N; n++ {
c.GetMetricValues(l)
}
}

func BenchmarkMetricCollectDSingleCore10(b *testing.B) {
count := 10
c := collection.NewCollectDCollector(UNIX_SOCK, test_caching, test_caching_ttl)
l := c.GetMetricList()
addition := count - len(l)

for x := 0; x < addition; x++ {
l = append(l, l[0])
}
l = l[:count]

// fmt.Printf("\nTotal metrics: %v\n", len(l))
for n := 0; n < b.N; n++ {
c.GetMetricValues(l)
}
}

func BenchmarkMetricCollectDSingleCore100(b *testing.B) {
count := 100
c := collection.NewCollectDCollector(UNIX_SOCK, test_caching, test_caching_ttl)
l := c.GetMetricList()
addition := count - len(l)

for x := 0; x < addition; x++ {
l = append(l, l[0])
}
l = l[:count]

// fmt.Printf("\nTotal metrics: %v\n", len(l))
for n := 0; n < b.N; n++ {
c.GetMetricValues(l)
}
}

func BenchmarkMetricCollectDSingleCore1000(b *testing.B) {
count := 1000
c := collection.NewCollectDCollector(UNIX_SOCK, test_caching, test_caching_ttl)
l := c.GetMetricList()
addition := count - len(l)

for x := 0; x < addition; x++ {
l = append(l, l[0])
}
l = l[:count]

// fmt.Printf("\nTotal metrics: %v\n", len(l))
for n := 0; n < b.N; n++ {
c.GetMetricValues(l)
}
}

func BenchmarkMetricCollectDSingleCore100000(b *testing.B) {
count := 100000
c := collection.NewCollectDCollector(UNIX_SOCK, test_caching, test_caching_ttl)
l := c.GetMetricList()
addition := count - len(l)

for x := 0; x < addition; x++ {
l = append(l, l[0])
}
l = l[:count]

// fmt.Printf("\nTotal metrics: %v\n", len(l))
for n := 0; n < b.N; n++ {
c.GetMetricValues(l)
}
}

func BenchmarkMetricCollectDMultiCore(b *testing.B) {
count := 1
c := collection.NewCollectDCollector(UNIX_SOCK, test_caching, test_caching_ttl)
l := c.GetMetricList()
addition := count - len(l)

for x := 0; x < addition; x++ {
l = append(l, l[0])
}
l = l[:count]

// fmt.Printf("\nTotal metrics: %v\n", len(l))
for n := 0; n < b.N; n++ {
c.GetMetricValues(l, runtime.NumCPU())
}
}

func BenchmarkMetricCollectDMultiCore10(b *testing.B) {
count := 10
c := collection.NewCollectDCollector(UNIX_SOCK, test_caching, test_caching_ttl)
l := c.GetMetricList()
addition := count - len(l)

for x := 0; x < addition; x++ {
l = append(l, l[0])
}
l = l[:count]

// fmt.Printf("\nTotal metrics: %v\n", len(l))
for n := 0; n < b.N; n++ {
c.GetMetricValues(l, runtime.NumCPU())
}
}

func BenchmarkMetricCollectDMultiCore100(b *testing.B) {
count := 100
c := collection.NewCollectDCollector(UNIX_SOCK, test_caching, test_caching_ttl)
l := c.GetMetricList()
addition := count - len(l)

for x := 0; x < addition; x++ {
l = append(l, l[0])
}
l = l[:count]

// fmt.Printf("\nTotal metrics: %v\n", len(l))
for n := 0; n < b.N; n++ {
c.GetMetricValues(l, runtime.NumCPU())
}
}

func BenchmarkMetricCollectDMultiCore1000(b *testing.B) {
count := 1000
c := collection.NewCollectDCollector(UNIX_SOCK, test_caching, test_caching_ttl)
l := c.GetMetricList()
addition := count - len(l)

for x := 0; x < addition; x++ {
l = append(l, l[0])
}
l = l[:count]

// fmt.Printf("\nTotal metrics: %v\n", len(l))
for n := 0; n < b.N; n++ {
c.GetMetricValues(l, runtime.NumCPU())
}
}

func BenchmarkMetricCollectDMultiCore100000(b *testing.B) {
count := 100000
c := collection.NewCollectDCollector(UNIX_SOCK, test_caching, test_caching_ttl)
l := c.GetMetricList()
addition := count - len(l)

for x := 0; x < addition; x++ {
l = append(l, l[0])
}
l = l[:count]

// fmt.Printf("\nTotal metrics: %v\n", len(l))
for n := 0; n < b.N; n++ {
c.GetMetricValues(l, runtime.NumCPU())
}
}

func BenchmarkMetricFacterSingleCore(b *testing.B) {
count := 1
c := collection.NewFacterCollector("facter", test_caching, test_caching_ttl)
l := c.GetMetricList()
addition := count - len(l)

for x := 0; x < addition; x++ {
l = append(l, l[0])
}
l = l[:count]

// fmt.Printf("\nTotal metrics: %v\n", len(l))
for n := 0; n < b.N; n++ {
c.GetMetricValues(l)
}
}

func BenchmarkMetricFacterSingleCore10(b *testing.B) {
count := 10
c := collection.NewFacterCollector("facter", test_caching, test_caching_ttl)
l := c.GetMetricList()
addition := count - len(l)

for x := 0; x < addition; x++ {
l = append(l, l[0])
}
l = l[:count]

// fmt.Printf("\nTotal metrics: %v\n", len(l))
for n := 0; n < b.N; n++ {
c.GetMetricValues(l)
}
}

func BenchmarkMetricFacterSingleCore100(b *testing.B) {
count := 100
c := collection.NewFacterCollector("facter", test_caching, test_caching_ttl)
l := c.GetMetricList()
addition := count - len(l)

for x := 0; x < addition; x++ {
l = append(l, l[0])
}
l = l[:count]

// fmt.Printf("\nTotal metrics: %v\n", len(l))
for n := 0; n < b.N; n++ {
c.GetMetricValues(l)
}
}

func BenchmarkMetricFacterSingleCore1000(b *testing.B) {
count := 1000
c := collection.NewFacterCollector("facter", test_caching, test_caching_ttl)
l := c.GetMetricList()
addition := count - len(l)

for x := 0; x < addition; x++ {
l = append(l, l[0])
}
l = l[:count]

// fmt.Printf("\nTotal metrics: %v\n", len(l))
for n := 0; n < b.N; n++ {
c.GetMetricValues(l)
}
}

func BenchmarkMetricFacterSingleCore100000(b *testing.B) {
count := 100000
c := collection.NewFacterCollector("facter", test_caching, test_caching_ttl)
l := c.GetMetricList()
addition := count - len(l)

for x := 0; x < addition; x++ {
l = append(l, l[0])
}
l = l[:count]

// fmt.Printf("\nTotal metrics: %v\n", len(l))
for n := 0; n < b.N; n++ {
c.GetMetricValues(l)
}
}
Loading

0 comments on commit 8e08252

Please sign in to comment.