{"componentChunkName":"component---src-components-mark-down-block-js","path":"/docs/events-and-metrics/","result":{"data":{"markdownRemark":{"html":"<h1 id=\"events-and-metrics\" style=\"position:relative;\"><a href=\"#events-and-metrics\" aria-label=\"events and metrics permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Events and Metrics in AppScope</h1>\n<p>When AppScope has <a href=\"/docs/how-works\">interposed a function</a>, and then the application being scoped executes that function, AppScope can emit events and metrics. Both events and metrics follow patterns that are rigorously defined in validatable <a href=\"https://json-schema.org/\">JSON Schema</a>, and documented in the <a href=\"/docs/schema-reference\">Schema Reference</a>.</p>\n<p>AppScope outputs metrics either in <a href=\"https://github.com/statsd/statsd\">StatsD</a> format or in equivalent JSON. AppScope can also watch for and intercept StatsD-formatted metrics being emitted by a scoped application.</p>\n<h2 id=\"events\" style=\"position:relative;\"><a href=\"#events\" aria-label=\"events permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>What Events Do</h2>\n<p>Events describe the action performed by the interposed function. For example, a <code>net.open</code> event could tell you that a network connection was established by Firefox, from the local IP/port <code>172.16.198.210:54388</code> to the remote IP/port <code>34.107.221.82:80</code>, using HTTP over TCP.</p>\n<h3 id=\"process-start-message\" style=\"position:relative;\"><a href=\"#process-start-message\" aria-label=\"process start message permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>The process‑start message</h3>\n<p>If <code>configevent</code> is set to <code>true</code>, AppScope sends a process‑start message upon establishing a new connection. This message – the <a href=\"schema-reference#eventstartmsg\">start.msg</a> event – reports the configs in effect at the time. The <code>start.msg.info.process.libscopever</code> element reports the version of AppScope that's being used.</p>\n<p>The process‑start message also includes four distinct identifiers:</p>\n<ul>\n<li><strong>UUID</strong> with key <code>uuid</code> and a value in <a href=\"https://en.wikipedia.org/wiki/Universally_unique_identifier\">canonical UUID form</a>. UUID is a universally-unique process identifier, meaning that no two processes will ever have the same UUID value on the same machine.</li>\n<li><strong>Machine ID</strong> with key <code>machine_id</code> and a value that AppScope obtains from <code>/etc/machine-id</code>. The machine ID uniquely identifies the host, as described in the <a href=\"https://man7.org/linux/man-pages/man5/machine-id.5.html\">man page</a>. When <code>/etc/machine-id</code> is not available (e.g., in Alpine, or in a container), AppScope generates the machine ID using a repeatable MD5 hash of the host's first MAC address. Two containers on the same host can have the same machine ID.</li>\n<li><strong>Process ID</strong>, with key <code>pid</code> and a value that is always unique at any given time, but that the machine can reuse for different processes at different times.</li>\n<li><strong>ID</strong>, with key <code>id</code> and a value that concatenates (and may truncate) the scoped app's hostname, procname, and command. This value is not guaranteed to be unique.</li>\n</ul>\n<p>By itself, the <strong>UUID</strong> process ID is unique for a given machine. In principle, <strong>UUID</strong> and <strong>Machine ID</strong> together constitute a tuple ID that is unique across all machine namespaces.</p>\n<h2 id=\"metrics\" style=\"position:relative;\"><a href=\"#metrics\" aria-label=\"metrics permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>What Metrics Do</h2>\n<p>Metrics can do any of three things:</p>\n<ul>\n<li>When verbosity is set to lower values, metrics summarize aspects of the action performed by the interposed function, for a reporting period that defaults to 10 seconds. (See the <code>Metric verbosity level</code> section of the <a href=\"/docs/config-file\">config file</a>.) For example, a <code>fs.read</code> metric could tell you that an <code>httpd</code> process has read a total of 320967 bytes from the filesystem, having performed multiple reads over a 10-second period.</li>\n<li>When verbosity is set to higher values, metrics provide details about the action performed by the interposed function in real time. For example, an <code>fs.read</code> metric could tell you that an <code>httpd</code> process has done one read of 8245 bytes from one specific file, <code>/etc/httpd/conf/httpd.conf</code>.</li>\n<li>When the metric name begins with <code>proc</code>, metrics periodically report information about resource usage at a point in time. For example, a <code>proc.mem</code> metric could tell you that <code>httpd</code> is currently using 62,123 KB of memory.</li>\n</ul>\n<p>The table below gives the gory details:</p>\n<table>\n<thead>\n<tr>\n<th>Verbosity Level</th>\n<th>Cardinality (dimensions)</th>\n<th>Aggregate Error Metrics?</th>\n<th>Aggregate DNS Metrics?</th>\n<th>Filesystem Metrics to Aggregate</th>\n<th>Network Metrics to Aggregate</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>0</td>\n<td>none</td>\n<td>yes</td>\n<td>yes</td>\n<td>all</td>\n<td>all</td>\n</tr>\n<tr>\n<td>1</td>\n<td><code>data</code> and <code>unit</code></td>\n<td>yes</td>\n<td>yes</td>\n<td>all</td>\n<td>all</td>\n</tr>\n<tr>\n<td>2</td>\n<td>same as 1, plus <code>class</code> and <code>proto</code></td>\n<td>yes</td>\n<td>yes</td>\n<td>all</td>\n<td>all</td>\n</tr>\n<tr>\n<td>3</td>\n<td>same as 2, plus <code>op</code></td>\n<td>yes</td>\n<td>yes</td>\n<td>all</td>\n<td>all</td>\n</tr>\n<tr>\n<td>4</td>\n<td>same as 3, plus <code>pid</code>, <code>host</code>, <code>proc</code>, and <code>http_status</code></td>\n<td>yes</td>\n<td>yes</td>\n<td>all</td>\n<td>all</td>\n</tr>\n<tr>\n<td>5</td>\n<td>same as 4, plus <code>domain</code> and <code>file</code></td>\n<td>no</td>\n<td>yes</td>\n<td>all</td>\n<td>all</td>\n</tr>\n<tr>\n<td>6</td>\n<td>same as 5, plus <code>localip</code>, <code>remoteip</code>, <code>localp</code>, <code>port</code>, and <code>remotep</code></td>\n<td>no</td>\n<td>no</td>\n<td>all but <code>open</code>/<code>close</code></td>\n<td>all</td>\n</tr>\n<tr>\n<td>7</td>\n<td>same as 6, plus <code>fd</code> and <code>args</code></td>\n<td>no</td>\n<td>no</td>\n<td>all but <code>open</code>/<code>close</code> and <code>stat</code></td>\n<td>all but <code>connect</code></td>\n</tr>\n<tr>\n<td>8</td>\n<td>same as 7, plus <code>duration</code>, <code>numops</code>, <code>req_per_sec</code>, <code>req</code>, <code>resp</code>, and <code>protocol</code></td>\n<td>no</td>\n<td>no</td>\n<td>all but <code>open</code>/<code>close</code>, <code>stat</code>, and <code>seek</code></td>\n<td>same as 7</td>\n</tr>\n<tr>\n<td>9</td>\n<td>same as 8</td>\n<td>no</td>\n<td>no</td>\n<td>all but <code>open</code>/<code>close</code>, <code>stat</code>, <code>seek</code>, and <code>read</code>/<code>write</code></td>\n<td>all but <code>connect</code> and <code>send</code>/<code>recv</code></td>\n</tr>\n</tbody>\n</table>\n<h3 id=\"interpret-metrics\" style=\"position:relative;\"><a href=\"#interpret-metrics\" aria-label=\"interpret metrics permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>How to Interpret Metrics</h3>\n<p>To interpret a given metric, you must consider its type. There are four possibilities:  </p>\n<table>\n<thead>\n<tr>\n<th>Metric Type</th>\n<th>Value Description</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td><code>gauge</code></td>\n<td>A numeric value that can increase or decrease over time – like a temperature or pressure gauge.</td>\n</tr>\n<tr>\n<td><code>counter</code></td>\n<td>A cumulative numeric value – it can only increase over time.</td>\n</tr>\n<tr>\n<td><code>timer</code></td>\n<td>Measures how long a given event type takes (duration).</td>\n</tr>\n<tr>\n<td><code>histogram</code></td>\n<td>A StatsD histogram distributes sampled observations into buckets. With AppScope, we encounter histograms only in the special case where AppScope intercepts StatsD-formatted metrics whose type is <code>histogram</code>. AppScope merely preserves that labeling: we assume that the scoped application has already aggregated the values into buckets.</td>\n</tr>\n</tbody>\n</table>\n<p>For example, <code>proc.fd</code> is a <code>gauge</code> that indicates how many files were open at one point in time. If we're scoping <code>top</code>, that's typically fewer than 10. By contrast, <code>fs.open</code> is a <code>count</code> that increments every time a file is opened. When scoping <code>top</code> over a reporting period of 10 seconds, you could see values in the hundreds or thousands.</p>\n<p>It's important to take into account whether the application or command you are scoping is short-lived or longer-lasting. For commands that complete very quickly, a <code>gauge</code> will report the value at the moment that AppScope exits the process.</p>\n<p>By default, all classes of events and metrics are turned on – but you can turn any class of metric or event data on or off individually. To do this, include or omit the desired watch type(s) from the <code>metric > watch[*]</code> array and/or the <code>event > watch[*]</code> array in the <a href=\"/docs/config-file\">config file</a>. Environment variables can achieve the same effect. For example, the environment variable to turn off metrics of watch type <code>statsd</code> would be <code>SCOPE_METRIC_STATSD=false</code>. To turn on events of watch type <code>logfile</code>, you'd use <code>SCOPE_EVENT_LOGFILE=true</code>.</p>","frontmatter":{"title":"Events and Metrics in AppScope"}}},"pageContext":{"slug":"/events-and-metrics/","id":"31b1e519-7204-5aa0-af8a-35e6578549d7"}},"staticQueryHashes":["2787008656","306729481","625673991","640077088"]}