0

I have an app running in Google App Engine. Their ecosystem seems to provide some facilities for analytics from logs in StackDriver.

For the life of me I can't figure out how to get a simple chart of HTTP requests broken down by user agent or operating system.

How can I configure such a chart?

maniSidhu98
  • 130
  • 5
atxdba
  • 337
  • 1
  • 5
  • 15

1 Answers1

1

As of now that's not possible as explained in the table under the "Kinds of metrics" section of the documentation, where it says you can't create a custom metric with Value type STRING.

I've confirmed this by using the function create_metric_descriptor in the corresponding repo file and editing its body with:

descriptor.value_type = (monitoring_v3.enums.MetricDescriptor.ValueType.STRING)  

and got this error:

InvalidArgument: 400 Field metricDescriptor.valueType had an invalid value of "STRING": When creating metric custom.googleapis.com/my_metric_6365: the value type is not supported for custom metrics.

Anyways, you could still get valuable information from Stackdriver Logging to pipe it to any data science and visualization method of your choosing. You'd extract the information about the Operating System from the protoPayload.userAgent field whenever possible.

Just experiment with Cloud SDK, for example, like the following:

$ project_id= #FILL
$ module_id=default #EDIT
$ version_id= #FILL
$ gcloud logging read "resource.type=gae_app AND resource.labels.module_id=$module_id AND resource.labels.version_id=$version_id AND logName=(projects/$project_id/logs/stderr OR projects/$project_id/logs/appengine.googleapis.com%2Frequest_log)" --format "json(receiveTimestamp, protoPayload.userAgent, protoPayload.ip, protoPayload.resource)"

You'd get entries like:

[
   {
            "protoPayload": {
                    "ip": "....",
                    "resource": "/",
                    "userAgent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36"
            },
            "receiveTimestamp": "2019-09-19T15:39:42.236439758Z"
   },
   {
            "protoPayload": {
                    "ip": "...",
                    "resource": "/",
                    "userAgent": "Mozilla/5.0 (Linux; Android 8.0.0; SM-G930F Build/R16NW; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/74.0.3729.157 Mobile Safari/537.36"
            },
            "receiveTimestamp": "2019-09-19T15:39:41.153786772Z"
    },
    {
            "protoPayload": {
                    "ip": "...",
                    "resource": "/",
                    "userAgent": "Mozilla/5.0 (Windows NT 5.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2486.0 Safari/537.36 Edge/13.10586"
            },
            "receiveTimestamp": "2019-09-19T15:39:33.286861169Z"
   },
   {
            "protoPayload": {
                    "ip": "...",
                    "resource": "/",
                    "userAgent": "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:21.0) Gecko/20130331 Firefox/21.0"
            },
            "receiveTimestamp": "2019-09-19T15:39:31.259811179Z"
    },
    {
            "protoPayload": {
                    "ip": "...",
                    "resource": "/",
                    "userAgent": "curl/7.66.0"
            },
            "receiveTimestamp": "2019-09-19T15:39:01.134762065Z"
    },
    {
            "protoPayload": {
                    "ip": "...",
                    "resource": "/",
                    "userAgent": "Wget/1.17 (linux-gnu)"
            },
            "receiveTimestamp": "2019-09-19T15:38:54.488718412Z"
    }
]
fbraga
  • 213
  • 1
  • 8