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

Commit

Permalink
Merge pull request #4 from essentialkaos/develop
Browse files Browse the repository at this point in the history
Version 2.0.0
  • Loading branch information
andyone authored Jun 13, 2016
2 parents b04c70b + 4ba51db commit e06183b
Show file tree
Hide file tree
Showing 9 changed files with 287 additions and 143 deletions.
19 changes: 19 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
language: go

go:
- 1.6.2
- tip

sudo: false

os:
- linux

before_install:
- go get pkg.re/essentialkaos/ek.v1

script:
- go build examples/annotations_example.go
- go build examples/async_example.go
- go build examples/basic_example.go
- go build examples/collector_example.go
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Dummy make file
#
7 changes: 7 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
## Changelog

#### v2.0.0

* Added usage examples
* Using values instead pointers for measurements (gauge/counter) structs
* Now `librato.AddMetrics` supports sending many metrics at once
* Code refactoring

#### v1.2.1

* Added pkg.re usage
Expand Down
55 changes: 55 additions & 0 deletions examples/annotations_example.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package main

// ////////////////////////////////////////////////////////////////////////////////// //

import (
"fmt"
"time"

"github.com/essentialkaos/librato"
)

// ////////////////////////////////////////////////////////////////////////////////// //

func main() {
librato.Mail = "[email protected]"
librato.Token = "abcd1234abcd1234abcd1234abcd1234abcd1234abcd1234abcd1234abcd1234"

// Add annotation to example:annotation_1 stream
errs := librato.AddAnnotation("example:annotation_1",
librato.Annotation{
Title: "Deploy v31",
Source: "server123",
Desc: "Revision: abcd1234",
Links: []string{
"https://build-service.com/build/31",
"https://git-repo.com/commit/abcd1234",
},
},
)

if len(errs) != 0 {
fmt.Println("Errors:")

for _, err := range errs {
fmt.Printf(" %v\n", err)
}
} else {
fmt.Println("Annotation added")
}

time.Sleep(time.Minute)

// Delete stream example:annotation_1 with all annotations
errs = librato.DeleteAnnotations("example:annotation_1")

if len(errs) != 0 {
fmt.Println("Errors:")

for _, err := range errs {
fmt.Printf(" %v\n", err)
}
} else {
fmt.Println("Annotation deleted")
}
}
40 changes: 40 additions & 0 deletions examples/async_example.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package main

// ////////////////////////////////////////////////////////////////////////////////// //

import (
"fmt"
"time"

"pkg.re/essentialkaos/ek.v1/rand"

"github.com/essentialkaos/librato"
)

// ////////////////////////////////////////////////////////////////////////////////// //

func main() {
librato.Mail = "[email protected]"
librato.Token = "abcd1234abcd1234abcd1234abcd1234abcd1234abcd1234abcd1234abcd1234"

// Create struct for async sending metrics data
// With this preferences metrics will be sended to Librato once
// a minute or if queue size reached 60 elements
metrics, err := librato.NewMetrics(time.Minute, 60)

if err != nil {
fmt.Printf("Error: %v\n", err)
return
}

for {
metrics.Add(
librato.Gauge{
Name: "example:gauge_1",
Value: rand.Int(1000),
},
)

time.Sleep(15 * time.Second)
}
}
49 changes: 49 additions & 0 deletions examples/basic_example.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package main

// ////////////////////////////////////////////////////////////////////////////////// //

import (
"fmt"
"time"

"pkg.re/essentialkaos/ek.v1/rand"

"github.com/essentialkaos/librato"
)

// ////////////////////////////////////////////////////////////////////////////////// //

func main() {
librato.Mail = "[email protected]"
librato.Token = "abcd1234abcd1234abcd1234abcd1234abcd1234abcd1234abcd1234abcd1234"

for {
errs := librato.AddMetric(
librato.Gauge{
Name: "example:gauge_1",
Value: rand.Int(1000),
},
librato.Gauge{
Name: "example:gauge_2",
Value: float64(rand.Int(1000)) / float64(rand.Int(20)),
Source: "go_librato_example",
},
librato.Counter{
Name: "example:counter_1",
Value: rand.Int(1000),
},
)

if len(errs) != 0 {
fmt.Println("Errors:")

for _, err := range errs {
fmt.Printf(" %v\n", err)
}
} else {
fmt.Println("Data sended to Librato Metrics")
}

time.Sleep(time.Minute)
}
}
54 changes: 54 additions & 0 deletions examples/collector_example.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package main

// ////////////////////////////////////////////////////////////////////////////////// //

import (
"fmt"
"time"

"pkg.re/essentialkaos/ek.v1/rand"

"github.com/essentialkaos/librato"
)

// ////////////////////////////////////////////////////////////////////////////////// //

func main() {
librato.Mail = "[email protected]"
librato.Token = "abcd1234abcd1234abcd1234abcd1234abcd1234abcd1234abcd1234abcd1234"

collector := librato.NewCollector(time.Minute, collectSomeMetrics)
collector.ErrorHandler = errorHandler

for {
time.Sleep(time.Hour)
}
}

func collectSomeMetrics() []librato.Measurement {
fmt.Println("Metrics collected")

return []librato.Measurement{
librato.Gauge{
Name: "example:gauge_1",
Value: rand.Int(1000),
},
librato.Gauge{
Name: "example:gauge_2",
Value: float64(rand.Int(1000)) / float64(rand.Int(20)),
Source: "go_librato_example",
},
librato.Counter{
Name: "example:counter_1",
Value: rand.Int(1000),
},
}
}

func errorHandler(errs []error) {
fmt.Println("Errors:")

for _, err := range errs {
fmt.Printf(" %v\n", err)
}
}
Loading

0 comments on commit e06183b

Please sign in to comment.