Documentation forAppOptics

AppOptics API

The AppOptics API allows full control over the product, including not only metric CRUD but also publishing/updating dashboards, alerts, and more. The API requires authentication with a token with every request. To find your API tokens, log in to your account and navigate to your Organization settings (click on Gravatar, Organization Details and select the API Tokens menu). Read the API Tokens and Token Roles article to learn more.

Here are some quick examples:

Python
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import psutil
import requests
import time

api_token = 'TOKEN_HERE'

while True:
  cpu = psutil.cpu_percent(interval=None, percpu=False)
  memory = psutil.virtual_memory()
  payload = {'tags': {'language': 'python', 'device': 'maybe-a-macbook'},
             'measurements': [{'name': 'test.cpu', 'value': cpu},
                              {'name': 'test.mem', 'value': memory[2]}]}
  print requests.post('https://api.appoptics.com/v1/measurements', auth=(api_token, ''), json=payload)
  time.sleep(30)
Ruby
#!/usr/bin/env ruby

require 'appoptics/metrics'
require 'usagewatch_ext'

api_token = "TOKEN_HERE"
AppOptics::Metrics.authenticate api_token
usw = Usagewatch

while true
  queue = AppOptics::Metrics::Queue.new(
    tags: {
        device: 'macbook',
        language: 'ruby'
      }
    )
    queue.add cpu: usw.uw_cpuused
    queue.add disk_perc: usw.uw_diskused_perc
    queue.submit

  sleep 30
end
Bash
APPOPTICS_TOKEN="TOKEN_HERE"
APPOPTICS_CREDENTIALS="${APPOPTICS_TOKEN}:"
APPOPTICS_API="https://api.appoptics.com"

while true; do
  cpu=$(ps aux | awk '{s=s+$3}; END{print s}')
  mem=$(ps aux | awk '{s=s+$4}; END{print s}')
  echo "%CPU: ${cpu}  %MEM: ${mem}"

 curl \
    -u $APPOPTICS_CREDENTIALS \
    -H "Content-Type: application/json" \
    -d '{
      "tags": {
        "device": "macbook",
        "language": "bash"
      },
      "measurements": [{
        "name": "cpu",
        "value": '$cpu'},
        {"name": "memory",
        "value": '$mem'}]
    }' \
    -X POST ${APPOPTICS_API}/v1/measurements

  sleep 30
done
PHP
#!/usr/bin/php

<?php
$url      = 'https://api.appoptics.com/v1/measurements';
$api_token  = 'TOKEN_HERE';

$curl = curl_init($url);
$curl_post_data = array(
  "measurements" => array(
   array("name" => "php-example-0", "value" => "22", "tags" => array("test" => "test-1"))
   )
);

$headers = array(
    'Content-Type: application/json'
);

curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($curl_post_data));
curl_setopt($curl, CURLOPT_USERPWD, "$api_token:");
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);

$result = curl_exec($curl);
$http_status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
curl_close($curl);
echo "HTTP Status Code: " . $http_status;
echo $result
?>
PowerShell
#requires -version 2.0

#Enable TLS 1.2 for PowerShell
[Net.ServicePointManager]::SecurityProtocol =
[Net.SecurityProtocolType]::Tls12

#AppOptics API Token
$TOKEN = "TOKEN_HERE"

#Prevent Credential Window prompt by creating a user
$API_TOKEN = New-Object System.Management.Automation.PSCredential ($TOKEN,(new-object System.Security.SecureString))

#Get CPU Percent Used
$CPU = Get-WmiObject -Query "SELECT PercentProcessorTime FROM Win32_PerfFormattedData_PerfOS_Processor WHERE Name = '_Total'"

#Get Memory Availailble in MegaBytes
$MEM= Get-WmiObject -Query "SELECT AvailableMBytes FROM Win32_PerfFormattedData_PerfOS_Memory"

#Create Hashtable for metrics
$HTABLE = @{
    "tags" = @{
        "device" = "winvm"
        "language" = "ps"
    }
    "measurements" = @(
        [ordered]@{
        "name" = "cpu"
        "value" = $CPU.PercentProcessorTime
        },
        [ordered]@{
        "name" = "memory"
        "value" = $MEM.AvailableMBytes
        }
    )
}

#Convert Hasttable to JSON omitting whitespace
$BODY = (ConvertTo-Json -InputObject $HTABLE -Depth 4 -Compress)

#Publish metric to API
$CMD = Invoke-RestMethod -Uri "https://api.appoptics.com/v1/measurements" -Method Post -ContentType "application/json" -Credential $API_TOKEN -Body $BODY

Language Bindings

Language bindings are API wrappers that make it easy to instrument your code and send custome metrics to AppOptics with a single line of code. Currently the following languages are supported:

Community Created Language Bindings

These bindings are created and maintained by the community. Any issues with the library should be directed to the author.

API Documentation

If you're interested in hitting the API directly, head to the API documentation to get started.

Navigation Notice: When the APM Integrated Experience is enabled, AppOptics shares a common navigation and enhanced feature set with other integrated experience products. How you navigate AppOptics and access its features may vary from these instructions.

The scripts are not supported under any SolarWinds support program or service. The scripts are provided AS IS without warranty of any kind. SolarWinds further disclaims all warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The risk arising out of the use or performance of the scripts and documentation stays with you. In no event shall SolarWinds or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the scripts or documentation.