-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit eeab024
Showing
10 changed files
with
325 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
/bin/ | ||
coverage.xml | ||
/vendor/ | ||
!/vendor/vendor.json |
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,20 @@ | ||
# Change Log | ||
|
||
All notable changes to this project will be documented in this file. | ||
|
||
The format is based on [Keep a Changelog](http://keepachangelog.com/) | ||
and this project adheres to [Semantic Versioning](http://semver.org/). | ||
|
||
## Unreleased | ||
### Added | ||
- X | ||
|
||
### Changed | ||
- X | ||
|
||
### Removed | ||
- X | ||
|
||
## 0.1.0 - 2018-07-18 | ||
### Added | ||
- Initial version: Includes Metrics and Inventory data |
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,12 @@ | ||
Apache License | ||
Version 2.0, January 2004 | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Copyright [2018] New Relic, Inc. | ||
|
||
Licensed under the Apache License, version 2.0 (the "License"); you may not use | ||
this file except in compliance with the License. You may obtain a copy of the | ||
License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by | ||
applicable law or agreed to in writing, software distributed under the License | ||
is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, | ||
either express or implied. |
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,75 @@ | ||
INTEGRATION := $(shell basename $(shell pwd)) | ||
BINARY_NAME = nr-$(INTEGRATION) | ||
GO_PKGS := $(shell go list ./... | grep -v "/vendor/") | ||
GO_FILES := $(shell find src -type f -name "*.go") | ||
VALIDATE_DEPS = github.com/golang/lint/golint | ||
DEPS = github.com/kardianos/govendor | ||
TEST_DEPS = github.com/axw/gocov/gocov github.com/AlekSi/gocov-xml | ||
|
||
all: build | ||
|
||
build: clean validate compile test | ||
|
||
clean: | ||
@echo "=== $(INTEGRATION) === [ clean ]: removing binaries and coverage file..." | ||
@rm -rfv bin coverage.xml | ||
|
||
validate-deps: | ||
@echo "=== $(INTEGRATION) === [ validate-deps ]: installing validation dependencies..." | ||
@go get -v $(VALIDATE_DEPS) | ||
|
||
validate-only: | ||
@printf "=== $(INTEGRATION) === [ validate ]: running gofmt... " | ||
# `gofmt` expects files instead of packages. `go fmt` works with | ||
# packages, but forces -l -w flags. | ||
@OUTPUT="$(shell gofmt -l $(GO_FILES))" ;\ | ||
if [ -z "$$OUTPUT" ]; then \ | ||
echo "passed." ;\ | ||
else \ | ||
echo "failed. Incorrect syntax in the following files:" ;\ | ||
echo "$$OUTPUT" ;\ | ||
exit 1 ;\ | ||
fi | ||
@printf "=== $(INTEGRATION) === [ validate ]: running golint... " | ||
@OUTPUT="$(shell golint $(GO_PKGS))" ;\ | ||
if [ -z "$$OUTPUT" ]; then \ | ||
echo "passed." ;\ | ||
else \ | ||
echo "failed. Issues found:" ;\ | ||
echo "$$OUTPUT" ;\ | ||
exit 1 ;\ | ||
fi | ||
@printf "=== $(INTEGRATION) === [ validate ]: running go vet... " | ||
@OUTPUT="$(shell go vet $(GO_PKGS))" ;\ | ||
if [ -z "$$OUTPUT" ]; then \ | ||
echo "passed." ;\ | ||
else \ | ||
echo "failed. Issues found:" ;\ | ||
echo "$$OUTPUT" ;\ | ||
exit 1;\ | ||
fi | ||
|
||
validate: validate-deps validate-only | ||
|
||
compile-deps: | ||
@echo "=== $(INTEGRATION) === [ compile-deps ]: installing build dependencies..." | ||
@go get $(DEPS) | ||
@govendor sync | ||
|
||
compile-only: | ||
@echo "=== $(INTEGRATION) === [ compile ]: building $(BINARY_NAME)..." | ||
@go build -o bin/$(BINARY_NAME) $(GO_FILES) | ||
|
||
compile: compile-deps compile-only | ||
|
||
test-deps: compile-deps | ||
@echo "=== $(INTEGRATION) === [ test-deps ]: installing testing dependencies..." | ||
@go get -v $(TEST_DEPS) | ||
|
||
test-only: | ||
@echo "=== $(INTEGRATION) === [ test ]: running unit tests..." | ||
@gocov test $(GO_PKGS) | gocov-xml > coverage.xml | ||
|
||
test: test-deps test-only | ||
|
||
.PHONY: all build clean validate-deps validate-only validate compile-deps compile-only compile test-deps test-only test |
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,28 @@ | ||
# New Relic Infrastructure Integration for monitoring Network Ports | ||
|
||
Reports up or down status for a network (TCP, UDP etc) port | ||
|
||
## Requirements | ||
|
||
### New Relic Infrastructure Agent | ||
|
||
This is the description about how to run the Port Monitor Integration with New Relic Infrastructure agent, so it is required to have the agent installed (see [agent installation](https://docs.newrelic.com/docs/infrastructure/new-relic-infrastructure/installation/install-infrastructure-linux)). | ||
|
||
## Installation | ||
|
||
* Download an archive file for the port-monitor Integration | ||
* Place the executables under `bin` directory and the definition file `port-monitor-definition.yml` in `/var/db/newrelic-infra/newrelic-integrations` | ||
* Set execution permissions for the binary file `nr-port-monitor` | ||
* Place the integration configuration file `port-monitor-config.yml.sample` in `/etc/newrelic-infra/integrations.d` | ||
|
||
## Configuration | ||
|
||
In order to use the Port Monitor Integration it is required to configure `port-monitor-config.yml.sample` file. Firstly, rename the file to `port-monitor-config.yml`. Then, depending on your needs, specify all instances that you want to monitor. Once this is done, restart the Infrastructure agent. | ||
|
||
You can view your data in Insights by creating your own custom NRQL queries. To | ||
do so use **NetworkPortSample** event types. | ||
|
||
## Compatibility | ||
|
||
* Supported OS: linux | ||
* Edition: |
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,12 @@ | ||
integration_name: com.newrelic.tcp-port-monitor | ||
|
||
instances: | ||
- name: <INSTANCE IDENTIFIER> | ||
command: metrics | ||
arguments: | ||
address: localhost:80 | ||
network: tcp | ||
timeout: 5 | ||
labels: | ||
env: prod | ||
|
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,18 @@ | ||
name: com.newrelic.tcp-port-monitor | ||
description: Reports status and metrics for tcp-port-monitor service | ||
protocol_version: 1 | ||
os: linux | ||
|
||
commands: | ||
metrics: | ||
command: | ||
- ./bin/nr-tcp-port-monitor | ||
- --metrics | ||
interval: 15 | ||
|
||
inventory: | ||
command: | ||
- ./bin/nr-tcp-port-monitor | ||
- --inventory | ||
prefix: config/nr-tcp-port-monitor | ||
interval: 15 |
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,72 @@ | ||
package main | ||
|
||
import ( | ||
"net" | ||
"time" | ||
|
||
sdkArgs "github.com/newrelic/infra-integrations-sdk/args" | ||
"github.com/newrelic/infra-integrations-sdk/log" | ||
"github.com/newrelic/infra-integrations-sdk/metric" | ||
"github.com/newrelic/infra-integrations-sdk/sdk" | ||
) | ||
|
||
type argumentList struct { | ||
sdkArgs.DefaultArgumentList | ||
Network string `default:"tcp" help:"Network type. Known networks are tcp, tcp4 (IPv4-only), tcp6 (IPv6-only), udp, udp4 (IPv4-only), udp6 (IPv6-only), ip, ip4 (IPv4-only), ip6 (IPv6-only), unix, unixgram and unixpacket"` | ||
Address string `default:":80" help:"Address? host:port"` | ||
Timeout int `default:"5" help:"Timeout in seconds"` | ||
} | ||
|
||
const ( | ||
integrationName = "com.newrelic.tcp-port-monitor" | ||
integrationVersion = "0.1.0" | ||
) | ||
|
||
var args argumentList | ||
|
||
func populateInventory(inventory sdk.Inventory) error { | ||
// Insert here the logic of your integration to get the inventory data | ||
// Ex: inventory.SetItem("softwareVersion", "value", "1.0.1") | ||
// -- | ||
return nil | ||
} | ||
|
||
func populateMetrics(ms *metric.MetricSet) error { | ||
// Insert here the logic of your integration to get the metrics data | ||
// Ex: ms.SetMetric("requestsPerSecond", 10, metric.GAUGE) | ||
// -- | ||
status := 0 | ||
conn, err := net.DialTimeout("tcp", args.Address, time.Duration(args.Timeout)*time.Second) | ||
if err != nil { | ||
status = 0 | ||
} else { | ||
status = 1 | ||
conn.Close() | ||
} | ||
|
||
ms.SetMetric("network", args.Network, metric.ATTRIBUTE) | ||
ms.SetMetric("address", args.Address, metric.ATTRIBUTE) | ||
ms.SetMetric("status", status, metric.GAUGE) | ||
return nil | ||
} | ||
|
||
func main() { | ||
integration, err := sdk.NewIntegration(integrationName, integrationVersion, &args) | ||
fatalIfErr(err) | ||
|
||
if args.All || args.Inventory { | ||
fatalIfErr(populateInventory(integration.Inventory)) | ||
} | ||
|
||
if args.All || args.Metrics { | ||
ms := integration.NewMetricSet("NetworkPortSample") | ||
fatalIfErr(populateMetrics(ms)) | ||
} | ||
fatalIfErr(integration.Publish()) | ||
} | ||
|
||
func fatalIfErr(err error) { | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
} |
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,23 @@ | ||
package main | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func TestPopulateInventory(t *testing.T) { | ||
// Insert here the logic for your tests | ||
actual := 2 | ||
expected := 2 | ||
if actual != expected { | ||
t.Errorf("PopulateInventory was incorrect, got: %d, expected: %d", actual, expected) | ||
} | ||
} | ||
|
||
func TestPopulateMetrics(t *testing.T) { | ||
// Insert here the logic for your tests | ||
actual := "foo" | ||
expected := "foo" | ||
if actual != expected { | ||
t.Errorf("PopulateMetrics was incorrect, got: %s, expected: %s", actual, expected) | ||
} | ||
} |
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,61 @@ | ||
{ | ||
"comment": "", | ||
"ignore": "test", | ||
"package": [ | ||
{ | ||
"checksumSHA1": "Ksl4kXr4ty0HwjrLRLZOrNz05Bw=", | ||
"path": "github.com/Sirupsen/logrus", | ||
"revision": "ba1b36c82c5e05c4f912a88eab0dcd91a171688f", | ||
"revisionTime": "2017-03-14T19:23:53Z", | ||
"version": "v0.11.5", | ||
"versionExact": "v0.11.5" | ||
}, | ||
{ | ||
"checksumSHA1": "jyYVyZKBHiXT9Fecb7iRUyXWwdI=", | ||
"path": "github.com/newrelic/infra-integrations-sdk/args", | ||
"revision": "b31bc81a228f7cb48496dd6c87815a119df35907", | ||
"revisionTime": "2017-07-20T13:55:07Z", | ||
"version": "v1.0", | ||
"versionExact": "v1.0.0" | ||
}, | ||
{ | ||
"checksumSHA1": "4t7HNYy4VZjvfFY6PsrzU8g1hJQ=", | ||
"path": "github.com/newrelic/infra-integrations-sdk/cache", | ||
"revision": "b31bc81a228f7cb48496dd6c87815a119df35907", | ||
"revisionTime": "2017-07-20T13:55:07Z", | ||
"version": "v1.0", | ||
"versionExact": "v1.0.0" | ||
}, | ||
{ | ||
"checksumSHA1": "6eFl1VzgBKkUbpcOdVhSqLz2oD4=", | ||
"path": "github.com/newrelic/infra-integrations-sdk/log", | ||
"revision": "b31bc81a228f7cb48496dd6c87815a119df35907", | ||
"revisionTime": "2017-07-20T13:55:07Z", | ||
"version": "v1.0", | ||
"versionExact": "v1.0.0" | ||
}, | ||
{ | ||
"checksumSHA1": "v6d2OtRT+Xxb8Ytv3L7RzWU9cHI=", | ||
"path": "github.com/newrelic/infra-integrations-sdk/metric", | ||
"revision": "b31bc81a228f7cb48496dd6c87815a119df35907", | ||
"revisionTime": "2017-07-20T13:55:07Z", | ||
"version": "v1.0", | ||
"versionExact": "v1.0.0" | ||
}, | ||
{ | ||
"checksumSHA1": "QAOEN0X+lEiWTXI7LjOWj1u+yfs=", | ||
"path": "github.com/newrelic/infra-integrations-sdk/sdk", | ||
"revision": "b31bc81a228f7cb48496dd6c87815a119df35907", | ||
"revisionTime": "2017-07-20T13:55:07Z", | ||
"version": "v1.0", | ||
"versionExact": "v1.0.0" | ||
}, | ||
{ | ||
"checksumSHA1": "JFeS7JlZ3ntfWcTfyQE0q9KgRi8=", | ||
"path": "golang.org/x/sys/unix", | ||
"revision": "46eaec7899b1dd945c25db17c78ba3f0c58a6613", | ||
"revisionTime": "2017-11-02T20:35:00Z" | ||
} | ||
], | ||
"rootPath": "source.datanerd.us/FIT/port-monitor-plugin" | ||
} |