-
Notifications
You must be signed in to change notification settings - Fork 19
/
elasticsearch.go
74 lines (61 loc) · 2.36 KB
/
elasticsearch.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package main
import (
"os"
sdkArgs "github.com/newrelic/infra-integrations-sdk/args"
"github.com/newrelic/infra-integrations-sdk/integration"
"github.com/newrelic/infra-integrations-sdk/log"
)
type argumentList struct {
sdkArgs.DefaultArgumentList
Hostname string `default:"localhost" help:"Hostname or IP where Elasticsearch Node is running."`
Port int `default:"9200" help:"Port on which Elasticsearch Node is listening."`
Username string `default:"" help:"Username for accessing Elasticsearch Node"`
Password string `default:"" help:"Password for the given user."`
UseSSL bool `default:"false" help:"Signals whether to use SSL or not. Certificate bundle must be supplied"`
CABundleFile string `default:"" help:"Alternative Certificate Authority bundle file"`
CABundleDir string `default:"" help:"Alternative Certificate Authority bundle directory"`
Timeout int `default:"30" help:"Timeout for an API call"`
ConfigPath string `default:"/etc/elasticsearch/elasticsearch.yml" help:"Path to the ElasticSearch configuration .yml file."`
CollectIndices bool `default:"true" help:"Signals whether to collect indices metrics or not"`
CollectPrimaries bool `default:"true" help:"Signals whether to collect primaries metrics or not"`
}
const (
integrationName = "com.newrelic.elasticsearch"
integrationVersion = "0.1.2"
)
var (
args argumentList
)
func main() {
// Create Integration
i, err := integration.New(integrationName, integrationVersion, integration.Args(&args))
logErrorAndExit(err)
// Create a client for metrics
metricsClient, err := NewClient("")
logErrorAndExit(err)
if args.All() || args.Metrics {
populateMetrics(i, metricsClient)
}
// Create a client for inventory. Inventory needs to make REST calls against
// localhost to get information relative to this node only.
inventoryClient, err := NewClient("localhost")
logErrorAndExit(err)
if args.All() || args.Inventory {
populateInventory(i, inventoryClient)
}
logErrorAndExit(i.Publish())
}
// checkErr logs an error if it exists
func checkErr(f func() error) {
if err := f(); err != nil {
log.Error("%v", err)
}
}
// logErrorAndExit logs an error if it exits and
// exits with a status code of 1
func logErrorAndExit(err error) {
if err != nil {
log.Error("Encountered fatal error: %v", err)
os.Exit(1)
}
}