Search code examples
google-cloud-platformgoogle-cloud-logging

Analyze Number value in Different Conditions with google cloud platform logging


I'm struggling to find out how to use GCP logging to log a number value for analysis, I'm looking for a link to a tutorial or something (or a better 3rd party service to do this).

Context: I have a service that I'd like to test different conditions for the function execution time and analyze it with google-cloud-platform logging.

Example Log: { condition: 1, duration: 1000 }

Desire: Create graph using GCP logs to compare condition 1 and 2.

Is there a tutorial somewhere for this? Or maybe there is a better 3rd party service to use?

PS: I'm using the Node google cloud logging client which only talks about text logs.

PSS: I considered doing this in loggly, but ended up getting lost in their documentation and UI.


Solution

  • There are many tools that you could use to solve this problem. However, you suggest a willingness to use Google Cloud Platform services (e.g. Stackdriver monitoring), so I'll provide some guidance using it.

    NOTE Please read around the topic and understand the costs involved with using e.g. Cloud Monitoring before you commit to an approach.

    Conceptually, the data you're logging (!) more closely matches a metric. However, this approach would require you to add some form of metric library (see Open Telemetry: Node.js) to your code and instrument your code to record the values that interest you.

    You could then use e.g. Google Cloud Monitoring to graph your metric.

    Since you're already producing a log with the data you wish to analyze, you can use Log-based metrics to create a metric from your logs. You may be interested in reviewing the content for distribution metric.

    Once you've a metric (either directly or using logs-based), you can then graph the resulting data in Cloud Monitoring. For logs-based metrics, see the Monitoring documentation.

    For completeness and to provide an alternative approach to producing and analyzing metrics, see the open-source tool, Prometheus. Using a 3rd-party Prometheus client library for Node.js, you could instrument you code to produce a metric. You would then configure Prometheus to scrape your app for its metrics and graph the results for you.