Skip to content
This repository has been archived by the owner on Feb 12, 2022. It is now read-only.

Metric Collection Examples

textractor edited this page Dec 8, 2017 · 16 revisions

Examples & Screencasts


Argus Web

Collection of metric data is not supported within the web interface, only the web services.

Argus SDK

This simple example illustrates how to post metrics. The actual metric objects being posted in this example are returned as the result of the createMetricObjects method and not explicitly shown here.

public static void main(String[] args) {

    int maxConnections = 10;
    ArgusService service = ArgusService.getInstance("https://argus.mycompany.com/argusws", maxConnections);
    service.getAuthService().login("aUsername", "aPassword");
    
    while(<there is data to post>) {
        postMetrics(service, data);
    }

}

void postMetrics(ArgusService service, List<Metric> metrics) {
    try {
        PutResult result = service.getMetricService().putMetrics(metrics);
        System.out.println(MessageFormat.format("Succeeded: {0}, Failed: {1}.",
                           result.getSuccessCount(), result.getFailCount()));
    } catch(TokenExpiredException e) {
	try {
                // Looks like my access token has expired.
                // So I will obtain a new access token using refresh token.
		service.getAuthService().obtainNewAccessToken();
	} catch(TokenExpiredException e1) {
                // Looks like the refresh token itself has expired.
                // So I will re-login to Argus using username and password.
		service.getAuthService().login("aUsername", "aPassword");
	} catch (IOException e1) {
                //Handle IOException as you would normally do.
		e1.printStackTrace();
	}
    } catch (IOException e) {
        //Handle IOException as you would normally do.
	e.printStackTrace();
    } 
}

Curl

This simple example uses curl to post a single metric having a single datapoint.

#!/bin/bash
payload='[  
   {  
      "scope":"TestScope",
      "metric":"TestMetric",
      "tags":{  
         "TestTag":"TagValue"
      },
      "datapoints":{  
         "1476422377000":"4364764952043520"
      }
   }
]'

curl -X POST -H "Content-Type: application/json" \
     -d '{"username":"aUsername","password":"aPassword"}' \
     https://argus.mycompany.com/argusws/v2/auth/login \
     -o tokens.out

# You can use any utility of your choice to extract the accessToken 
# from the tokens.out file. 

curl -H "Authorization: Bearer <accessToken from tokens.out>" \
     -H "Content-Type: application/json" \
     -X POST -d "$payload" \
     https://argus.mycompany.com/argusws/collection/metrics

For more information on authentication tokens, see Authentication.

If you are interested in using Python to interact with Argus, see the Argus Python client library.

Clone this wiki locally