Git Product home page Git Product logo

go-insights's Introduction

New Relic Insights Client

NOTICE: This library is now deprecated in favor of newrelic-client-go

A Go library for interacting with insights.

CircleCI Go Report Card GoDoc License Release

Disclaimer

New Relic has open-sourced this integration to enable monitoring of this technology. This integration is provided AS-IS WITHOUT WARRANTY OR SUPPORT, although you can report issues and contribute to this integration via GitHub. Support for this integration is available with an Expert Services subscription.

Contents

There are two parts to this library:

  • The Command Line Interface is a compiled standalone binary that can be executed to insert or query Newrelic Insights.
  • The Insights Client Library can be used in a go project for posting to and querying events from insights.

CLI

The Insights CLI can be used to query and insert data in insights. The following commands and flags are supported:

usage: go-insights --key=KEY --id=ID [<flags>] <command> [<args> ...]

Flags:
  --help         Show help (also see --help-long and --help-man).
  -k, --key=KEY  Your insights key.
  -i, --id=ID    Your New Relic account ID
  -u, --url=URL  Custom insights endpoint.
  --version      Show application version.
  -d, --debug    Enable debug level logging.

Commands:
  help [<command>...]
    Show help.

  insert <file path>
    Insert data to insights.

  query <query string>
    Query data in insights.

Insights Client Library

The client library has two functions. It contains a query client and an insert client.

Query Client

The query client will make an API call to insights and return the results of your query in a QueryResponse struct:

type QueryResponse struct {
  Results  []map[string]interface{} `json:"results"`
  Metadata QueryMetadata            `json:"metadata"`
}

Insert Client

The insert client will insert data into insights. There are two methods of use. You can send single events one at a time. Alternatively, you can run the client in batch mode, which runs a goroutine and sends events to insights in batches.

Sending Single Events

package main

import (
  "fmt"

  insights "github.com/newrelic/go-insights/client"
)

type TestType struct {
  EventType    string `json:"eventType"`
  AwesomeScore int    `json:"AwesomeScore"`
}

insightAccountID := "0"
insightInsertKey := "abc123example"

client := insights.NewInsertClient(insightInsertKey, insightAccountID)
if validationErr := client.Validate(); validationErr != nil {
  //however it is appropriate to handle this in your use case
  log.Errorf("Validation Error!")
}

testData := TestType{
  EventType:    "testEvent",
  AwesomeScore: 25,
}

if postErr := client.PostEvent(testData); postErr != nil {
  log.Errorf("Error: %v\n", err)
}

Enqueueing Events in Batch Mode

package main

import (
  "fmt"
  "time"

  insights "github.com/newrelic/go-insights/client"
)

type TestType struct {
  EventType    string `json:"eventType"`
  AwesomeScore int    `json:"AwesomeScore"`
}

func main() {
  insightAccountID := "0"
  insightInsertKey := "abc123example"

  // Create the client instance
  client := insights.NewInsertClient(insightInsertKey, insightAccountID)
  if validationErr := client.Validate(); validationErr != nil {
    //however it is appropriate to handle this in your use case
    log.Errorf("Validation Error!")
  }
  if startError := client.Start(); startError != nil {
    log.Errorf("failed to start client")
  }

  // Add some data with delay
  for x := 0; x < 10; x++ {
    fmt.Printf("Enqueueing data: %d\n", x)
    err := client.EnqueueEvent(TestType{EventType: "YourTable", AwesomeScore: 9000 + x})
    if err != nil {
      fmt.Printf("Error: %v\n", err)
      return
    }
    time.Sleep(10 * time.Second)
  }

  // Make sure nothing is pending in the queue
  client.Flush()
}

go-insights's People

Contributors

a-james-faria avatar bpecknr avatar cgilling avatar sschwartzman avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

go-insights's Issues

Go Module Support?

Is this something your folks are interested in? If so I could do a PR.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.