{"_id":"57dbad19b68b500e00d3736d","project":"56a1f77442dfda0d00046285","__v":2,"parentDoc":null,"user":"5720801f5be73c170096021a","version":{"_id":"56a1f77542dfda0d00046288","__v":9,"project":"56a1f77442dfda0d00046285","createdAt":"2016-01-22T09:33:41.397Z","releaseDate":"2016-01-22T09:33:41.397Z","categories":["56a1f77542dfda0d00046289","56a1fdf442dfda0d00046294","56a2079f0067c00d00a2f955","56a20bdf8b2e6f0d0018ea84","56a3e78a94ec0a0d00b39fed","56af19929d32e30d0006d2ce","5721f4e9dcfa860e005bef98","574e870be892bf0e004fde0d","5832fdcdb32d820f0072e12f"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":true,"codename":"","version_clean":"1.0.0","version":"1.0"},"category":{"_id":"56a20bdf8b2e6f0d0018ea84","pages":["56a20e302255370d00ad5ecb"],"project":"56a1f77442dfda0d00046285","__v":1,"version":"56a1f77542dfda0d00046288","sync":{"url":"","isSync":false},"reference":false,"createdAt":"2016-01-22T11:00:47.207Z","from_sync":false,"order":3,"slug":"features","title":"Features"},"updates":["57e4fc65f3d7fc0e009c5097"],"next":{"pages":[],"description":""},"createdAt":"2016-09-16T08:28:09.850Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"settings":"","results":{"codes":[]},"auth":"required","params":[],"url":""},"isReference":false,"order":4,"body":"Custom metrics show you the arbitrary metrics reported by your services. Trace helps you to gather any metrics in your application.\nYou can name and group your metrics as you wish and record a single or a bunch of values to check the fluctuations of your measured data.\n[block:callout]\n{\n  \"type\": \"warning\",\n  \"title\": \"Availability\",\n  \"body\": \"Custom metrics is available since collector version v2.22.0.\"\n}\n[/block]\nWe have 2 kinds of interfaces for sending your custom metric data, but both of their output will look like the following:\n[block:image]\n{\n  \"images\": [\n    {\n      \"image\": [\n        \"https://files.readme.io/4cb040a-trace-custom-metrics.png\",\n        \"trace-custom-metrics.png\",\n        1134,\n        757,\n        \"#e4e7e9\"\n      ]\n    }\n  ]\n}\n[/block]\nOn the bottom of the chart, you can choose which aggregation method you would like to use.\n\nTo start using custom metrics, first, you have to include Trace into the module where you want to measure something. Trace exposes two different kinds of custom metrics, one being the incremental metrics, the other being the recorded metrics.\n\n# Record Metrics\n\nRecord metrics is useful when you **have multiple events** that have a discrete value at a given point of time. \nIt can be used to collect the element count of a queue, the number of open connections or if you are building IoT devices then to collect temperature values.\n\n- Application health metrics\n  - Current messages in a messaging queue\n  - Database pool status\n\n- Business metrics\n  - User's current assets in your app\n  - Number of items in a web shop cart checkout\n  - Money spent upon cart checkout\n\n- Domain specific metrics\nAgain it could be anything you can think of, and is not an incremented value. If you have discrete values as time passes you can report them to trace with the following lines.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"const trace = require(':::at:::risingstack/trace')\\n\\ntrace.recordMetric('order/orderAmount', 412 /* $ */)\\n\\n// ...\\n\\ntrace.recordMetric('order/orderAmount', 110 /* $ */)\\n\\n// ...\\n\\ntrace.recordMetric('order/orderAmount', 110 /* $ */)\\n\\n/* This will be reported to trace services \\n * as distinct values.\\n */\",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]\nThis comes handy when we'd like to see minimum or maximum values at a given point of time. With record metrics, you can see more precise values at any given time. With record metrics, you can build a histogram with the reported values.\n\n# Incremental Metrics\n\nBy using increment metrics you don't have to keep track of a value over time as you would in record metric, you simply have to call a function and everything will be done automatically. This comes handy when you would like to keep track of occurrences of events.\n\n- Application health metrics\n  - Queue/dequeue in a messaging queue\n  - Database query runs\n  - Specific endpoint calls\n  - Calls to a specific external service ( eg. amazon s3 )\n\n- Business metrics\n  - User signup\n  - Page visit\n  - Webshop total amount\n\n- Domain specific metrics\nThey can be anything you'd like to track and is specific to your service. In a context of a webshop you can track orders of specific items, as they are removed from the database, before your database call you can add the following lines to your app:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"const trace = require([email protected]/trace')\\ntrace.incrementMetric('order/gpu')\",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]\nYou can also increment it by a specified amount like this:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"const trace = require([email protected]/trace')\\n\\ntrace.incrementMetric('order/gpu', 5)\\ntrace.incrementMetric('order/gpu')\\ntrace.incrementMetric('order/gpu', 123)\\n// this will be reported to the trace services as one value: 129 (5 + 1 + 123)\",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]\nIf you'd wish you can also decrement a the counter like this:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"const trace = require([email protected]/trace')\\n\\ntrace.incrementMetric('order/gpu', -5)\",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]\nWith increment metrics on the chart, ​you'll be able to see how the values are changing over time.","excerpt":"Performance metrics of your services like system load, memory, response time...","slug":"custom-metrics","type":"basic","title":"Custom metrics"}

Custom metrics

Performance metrics of your services like system load, memory, response time...

Custom metrics show you the arbitrary metrics reported by your services. Trace helps you to gather any metrics in your application. You can name and group your metrics as you wish and record a single or a bunch of values to check the fluctuations of your measured data. [block:callout] { "type": "warning", "title": "Availability", "body": "Custom metrics is available since collector version v2.22.0." } [/block] We have 2 kinds of interfaces for sending your custom metric data, but both of their output will look like the following: [block:image] { "images": [ { "image": [ "https://files.readme.io/4cb040a-trace-custom-metrics.png", "trace-custom-metrics.png", 1134, 757, "#e4e7e9" ] } ] } [/block] On the bottom of the chart, you can choose which aggregation method you would like to use. To start using custom metrics, first, you have to include Trace into the module where you want to measure something. Trace exposes two different kinds of custom metrics, one being the incremental metrics, the other being the recorded metrics. # Record Metrics Record metrics is useful when you **have multiple events** that have a discrete value at a given point of time. It can be used to collect the element count of a queue, the number of open connections or if you are building IoT devices then to collect temperature values. - Application health metrics - Current messages in a messaging queue - Database pool status - Business metrics - User's current assets in your app - Number of items in a web shop cart checkout - Money spent upon cart checkout - Domain specific metrics Again it could be anything you can think of, and is not an incremented value. If you have discrete values as time passes you can report them to trace with the following lines. [block:code] { "codes": [ { "code": "const trace = require([email protected]/trace')\n\ntrace.recordMetric('order/orderAmount', 412 /* $ */)\n\n// ...\n\ntrace.recordMetric('order/orderAmount', 110 /* $ */)\n\n// ...\n\ntrace.recordMetric('order/orderAmount', 110 /* $ */)\n\n/* This will be reported to trace services \n * as distinct values.\n */", "language": "javascript" } ] } [/block] This comes handy when we'd like to see minimum or maximum values at a given point of time. With record metrics, you can see more precise values at any given time. With record metrics, you can build a histogram with the reported values. # Incremental Metrics By using increment metrics you don't have to keep track of a value over time as you would in record metric, you simply have to call a function and everything will be done automatically. This comes handy when you would like to keep track of occurrences of events. - Application health metrics - Queue/dequeue in a messaging queue - Database query runs - Specific endpoint calls - Calls to a specific external service ( eg. amazon s3 ) - Business metrics - User signup - Page visit - Webshop total amount - Domain specific metrics They can be anything you'd like to track and is specific to your service. In a context of a webshop you can track orders of specific items, as they are removed from the database, before your database call you can add the following lines to your app: [block:code] { "codes": [ { "code": "const trace = require([email protected]/trace')\ntrace.incrementMetric('order/gpu')", "language": "javascript" } ] } [/block] You can also increment it by a specified amount like this: [block:code] { "codes": [ { "code": "const trace = require([email protected]/trace')\n\ntrace.incrementMetric('order/gpu', 5)\ntrace.incrementMetric('order/gpu')\ntrace.incrementMetric('order/gpu', 123)\n// this will be reported to the trace services as one value: 129 (5 + 1 + 123)", "language": "javascript" } ] } [/block] If you'd wish you can also decrement a the counter like this: [block:code] { "codes": [ { "code": "const trace = require([email protected]/trace')\n\ntrace.incrementMetric('order/gpu', -5)", "language": "javascript" } ] } [/block] With increment metrics on the chart, ​you'll be able to see how the values are changing over time.