AppOptics API

The AppOptics API allows full control over the product, including not only metric CRUD but also publishing/updating dashboards, alerts, and more.

Here’s some quick examples:

#!/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'', auth=(api_token, ''), json=payload)
#!/usr/bin/env ruby

require 'appoptics/metrics'
require 'usagewatch_ext'

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

while true
  queue =
    tags: {
        device: 'macbook',
        language: 'ruby'
    queue.add cpu: usw.uw_cpuused
    queue.add disk_perc: usw.uw_diskused_perc

  sleep 30


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 \
    -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

$url      = '';
$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);
echo "HTTP Status Code: " . $http_status;
echo $result
#requires -version 2.0

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

#AppOptics API Token

#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" = @(
        "name" = "cpu"
        "value" = $CPU.PercentProcessorTime
        "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 "" -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:

API Documentation

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