forked from influxdata/telegraf
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Closes influxdata#34
- Loading branch information
Jeffrey Allen
committed
Oct 22, 2015
1 parent
ae7ad22
commit b212d47
Showing
4 changed files
with
125 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
package riemann | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"os" | ||
|
||
"github.com/influxdb/influxdb/client/v2" | ||
"github.com/influxdb/telegraf/outputs" | ||
"github.com/allenj/raidman" | ||
) | ||
|
||
type Riemann struct { | ||
URL string | ||
Transport string | ||
|
||
client raidman.Client | ||
} | ||
|
||
var sampleConfig = ` | ||
# URL of server | ||
url = "localhost:5555" | ||
# transport protocol to use either tcp or udp | ||
transport = "tcp" | ||
` | ||
|
||
func (r *Riemann) Connect() error { | ||
c, err := raidman.Dial(r.Transport, r.URL) | ||
|
||
if err != nil { | ||
return err | ||
} | ||
|
||
r.client = *c | ||
return nil | ||
} | ||
|
||
func (r *Riemann) Close() error { | ||
r.client.Close() | ||
return nil | ||
} | ||
|
||
func (r *Riemann) SampleConfig() string { | ||
return sampleConfig | ||
} | ||
|
||
func (r *Riemann) Description() string { | ||
return "Configuration for the Riemann server to send metrics to" | ||
} | ||
|
||
func (r *Riemann) Write(points []*client.Point) error { | ||
if len(points) == 0 { | ||
return nil | ||
} | ||
|
||
var events []*raidman.Event | ||
for _, p := range points { | ||
ev := buildEvent(p) | ||
events = append(events, &ev) | ||
} | ||
|
||
var senderr = r.client.SendMulti(events) | ||
if senderr != nil { | ||
return errors.New(fmt.Sprintf("FAILED to send riemann message: %s\n", | ||
senderr)) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func buildEvent(p *client.Point) (raidman.Event) { | ||
host := p.Tags()["host"] | ||
|
||
if len(host) == 0 { | ||
hostname, err := os.Hostname() | ||
if err != nil { | ||
host = "unknown" | ||
} else { | ||
host = hostname | ||
} | ||
} | ||
|
||
var event = &raidman.Event{ | ||
Host: host, | ||
Service: p.Name(), | ||
This comment has been minimized.
Sorry, something went wrong. |
||
Metric: p.Fields()["value"], | ||
This comment has been minimized.
Sorry, something went wrong.
rzagabe
|
||
} | ||
|
||
return *event | ||
} | ||
|
||
func init() { | ||
outputs.Add("riemann", func() outputs.Output { | ||
return &Riemann{} | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package riemann | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/influxdb/telegraf/testutil" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestConnectAndWrite(t *testing.T) { | ||
if testing.Short() { | ||
t.Skip("Skipping integration test in short mode") | ||
} | ||
|
||
url := testutil.GetLocalHost() + ":5555" | ||
|
||
r := &Riemann{ | ||
URL: url, | ||
Transport: "tcp", | ||
} | ||
|
||
err := r.Connect() | ||
require.NoError(t, err) | ||
|
||
err = r.Write(testutil.MockBatchPoints().Points()) | ||
require.NoError(t, err) | ||
} |
This feels quite uncomfortable to assign the service name to the metric name. IMO
telegraf
would be a better fit.Edit: What about setting the field
Host
to{hostname}-telegraf
instead.