Welcome, Guest Login

Support Center

Removing custom application metrics

Last Updated: Apr 23, 2014 03:40PM EDT
While data will naturally age out of the Stackdriver system, there are times when test data or mistaken key names have been sent where you would like to remove the old keys from being visible to the system.  You can now send a request to schedule the metric to be removed so that it isn't shown in the list for graphs or alerts.

Note that the removal will take effect roughly two hours after the request has been sent.  Also, if you begin sending a custom metric with the same name again, the previous data will start to appear again.

To do this, you send a message to the Stackdriver gateway that looks very similar to those used to send the custom metric initially.

Example data point

data_point = {
   ‘name’: ‘my_custom_metric’,
   #Note: Stackdriver rejects when the collected_at value is older than 2 hours.
   ‘collected_at’: 1325394000,
   #Note: Include an instance value if your metric is tied to an instance.
   'instance': 'i-123a567b', 
}

 

The data point is submitted to the gateway as part of a gateway message.  The gateway message includes the timestamp the message is created or submitted, your customer identifier, and the protocol version for the message.  The timestamp is used to disambiguate messages.  Messages with the same timestamp are assumed to be the same (see below).  The ‘timestamp’ field must be an integer.  If you want to delete a custom metric that is associated with an instance, include the optional instance field with the instance id of your instance as you did when sending the metric originally.
 
The protocol version defines the schema of the message. The current protocol version (and that which is described in this document) is version 1.

Example gateway message

 

    sd_post = {
        'timestamp': int(time.time()),
        'proto_version': 1,
        'data': data_point,
        }

 

The final message preparation is defining the HTTP headers.  The gateway protocol requires that messages be JSON-encoded.  The API key is also included in the header.

Example headers

 

 headers = {
        'content-type': 'application/json',
        'x-stackdriver-apikey': args.apikey
        }
Submit the measurement to Stackdriver by POSTing it to the gateway at https://custom-gateway.stackdriver.com/v1/custom.  In the code fragment below, we use the Python “requests” module for HTTP messaging; it can be installed via ‘pip install requests’ or ‘easy_install requests’.

Example http request

 import requests
 resp = requests.post('https://custom-gateway.stackdriver.com/v1/delete_custom',
                       data=json.dumps(sd_post),
                       headers=headers)

Putting it all together

 
A complete working example that combines all the pieces we have discussed in shown below.
 
import requests
import json
import time

def delete_custom_metric():
        data_point = {
            'name': 'my_custom_metric',
            #Note: Stackdriver rejects when the collected_at value is older than 2 hours.             
            'collected_at': 1325394000,
            #Note: Include an instance value if your metric is tied to an instance.  
            'instance': 'i-123a567b',
            }
        gateway_msg = {
            'timestamp': int(time.time()),
            'proto_version': 1,
            'data': data_point,
            }
        headers = {
            'content-type': 'application/json',
            'x-stackdriver-apikey': '4VP31M3RJ5JWN29E1LMSE0'
            }
        resp = requests.post(
            'https://custom-gateway.stackdriver.com/v1/delete_custom',
            data=json.dumps(gateway_msg),
            headers=headers)
        
        if not resp.ok:
            print resp.content
            assert resp.ok, 'Failed to delete custom metric.'
        else:
            print "Published."

if __name__ == '__main__':
    delete_custom_metric()
 
 
https://cdn.desk.com/
false
desk
Loading
seconds ago
a minute ago
minutes ago
an hour ago
hours ago
a day ago
days ago
about
false
Invalid characters found
/customer/en/portal/articles/autocomplete