Back to top icon

New Relic Developers

Infrastructure SDK

Report custom data from your hosts and extend New Relic Infrastructure with the same SDK used by our developers.

New Relic Infrastructure includes numerous integrations with cloud technologies as well as on-host tools like Apache and Kubernetes. But if you want to instrument a technology that’s not available out of the box, Infrastructure includes an integration SDK for building your own on-host infrastructure reporting.

You can use the SDK to generate three types of data—metric, event, and inventory—that target a specific entity.

1. Metric data captures numeric data.

Here’s an example metric payload:

[ 
    {
         "event_type":"MyorgNginxSample",
         "net.connectionsActive": 54,  # metric data (a key/value pair)
         "net.requestsPerSecond": 21,  # metric data (a key/value pair)
         "net.reading": 23,   # metric data (a key/value pair)
    }
]

2. Event data captures one-off system events.

Here’s an example event payload:

[
   {
      "summary":"More than 10 request errors logged in the last 5 minutes",
      "category": "notifications"
   }
]

3. Inventory data tracks the current state of your environment.

Here’s an example inventory payload:

{
    "events/worker_connections": {
        "value": 1024
    },
    "http/gzip" : {
        "value": "on"
    }
}

Each type of data can be inserted through simple methods exposed in the Infrastructure SDK.

Here's a sample method: 

func main() {
  // Create Integration
  i, err := integration.New(integrationName, integrationVersion, integration.Args(&args))
  if err != nil {
    log.Error(err.Error())
    os.Exit(1)
  }
  entity := i.LocalEntity()
  // Add an event
  if args.All() || args.Events {
    err = entity.AddEvent(event.New("restart", "status"))
    if err != nil {
      log.Error(err.Error())
    }
 }
 // Add Inventory item
 if args.All() || args.Inventory {
   err = entity.SetInventoryItem("customInventory", "version", "3.0.1")
   if err != nil {
     log.Error(err.Error())
   }
 }
 // Add Metric
 if args.All() || args.Metrics {
   m := entity.NewMetricSet("CustomSample")
   err = m.SetMetric("myMetric", 1337, metric.GAUGE)
   if err != nil {
     log.Error(err.Error())
   }
 }
 if err = i.Publish(); err != nil {
   log.Error(err.Error())
 }
}

Learn more and start building

Group 7 Created with Sketch.

Documentation

To get started building your integration, see Introduction to the integrations SDK

Group 9 Created with Sketch.

NRU Tutorials

Check out the latest tutorial on the the infrastructure SDK.

Group 8 Created with Sketch.

Community Forum

Connect with other developers in the New Relic Explorers Hub

GitHub

For examples of integrations and other technologies, see our GitHub repo.