{"componentChunkName":"component---src-components-mark-down-block-js","path":"/docs/library-using/","result":{"data":{"markdownRemark":{"html":"<h2 id=\"using-the-library-libscopeso\" style=\"position:relative;\"><a href=\"#using-the-library-libscopeso\" aria-label=\"using the library libscopeso 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>Using the Library (libscope.so)</h2>\n<p>To use the library for the first time in a given environment, complete this quick procedure:</p>\n<ol>\n<li><a href=\"/docs/downloading\">Download</a> AppScope. </li>\n<li>Decide on a <code>SCOPE_HOME</code> directory, i.e., the <a href=\"/docs/downloading#where-from\">directory from which AppScope should run</a> in your environment.</li>\n<li>\n<p>Set <code>SCOPE_HOME</code> to the desired directory.</p>\n<pre><code>ubuntu@my_hostname:~/someuser/temp$ export SCOPE_HOME=/opt/appscope\n</code></pre>\n</li>\n<li>\n<p>Create the <code>SCOPE_HOME</code> directory. (Here, <code>sudo</code> is required because <code>opt</code> is owned by root.)</p>\n<pre><code>ubuntu@my_hostname:~/someuser/temp$ sudo mkdir $SCOPE_HOME\n</code></pre>\n</li>\n<li>\n<p>Extract (<code>scope extract</code>) the contents of the AppScope binary into the <code>SCOPE_HOME</code> directory.</p>\n<pre><code>ubuntu@my_hostname:~/someuser/temp$ sudo ./scope extract $SCOPE_HOME\nSuccessfully extracted to /opt/appscope.\n</code></pre>\n</li>\n<li>\n<p>Verify that <code>SCOPE_HOME</code> contains the AppScope library (<code>libscope.so</code>) and the config file (<code>scope.yml</code>). </p>\n<pre><code>ubuntu@my_hostname:~/someuser/temp$ ls -al $SCOPE_HOME\ntotal 20528\ndrwxr-xr-x 2 root root     4096 Jul 11 22:51 .\ndrwxr-xr-x 5 root root     4096 Jul 11 22:51 ..\n-rwxr-xr-x 1 root root  9663240 Jul 11 22:51 libscope.so\n-rw-r--r-- 1 root root    35755 Jul 11 22:51 scope.yml\nubuntu@my_hostname:~/someuser/temp$ \n</code></pre>\n</li>\n</ol>\n<p>Now you are ready to configure AppScope to instrument any application and output data to any existing tool via simple TCP protocols.</p>\n<p>Depending on your use case and preferred way of working, this usually entails editing <code>scope.yml</code>, and then setting environment variables while invoking the library.</p>\n<p>How the library is loaded depends on the type of executable. A dynamic loader can preload the library (where supported), while AppScope can load static executables. Regardless of how the library is loaded, you get full control of the data source, formats, and transports.</p>\n<p><span id=\"env-vars\"> </span></p>\n<h3 id=\"the-config-file\" style=\"position:relative;\"><a href=\"#the-config-file\" aria-label=\"the config file 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 Config File</h3>\n<p>For the default settings in the sample <code>scope.yml</code> configuration file, see <a href=\"/docs/config-file\">Config File</a>, or inspect the most-recent file on <a href=\"https://github.com/criblio/appscope/blob/master/conf/scope.yml\">GitHub</a>.</p>\n<p>To see the config file with comments omitted, run the following command:</p>\n<pre><code>egrep -v '^ *#.*$' scope.yml | sed '/^$/d' >scope-minimal.yml\n</code></pre>\n<p>This can help you get a clear idea of exactly how AppScope is configured, assuming you have previously read and understood the comments.</p>\n<h3 id=\"using-the-library-directly\" style=\"position:relative;\"><a href=\"#using-the-library-directly\" aria-label=\"using the library directly 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>Using the Library Directly</h3>\n<p>To use the library directly, you rely on the <code>LD_PRELOAD</code> environment variable. </p>\n<p>The following examples provide an overview of this way of working with the library. All the examples call the system-level <code>ps</code> command, just to show how the syntax works.</p>\n<p>For more, check out the <a href=\"/docs/examples-use-cases\">Further Examples</a>, which include both CLI and library use cases.</p>\n<h4 id=\"ld_preload-with-a-single-command\" style=\"position:relative;\"><a href=\"#ld_preload-with-a-single-command\" aria-label=\"ld_preload with a single command 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><code>LD_PRELOAD</code> with a Single Command</h4>\n<p>Start with this basic example:</p>\n<pre><code>LD_PRELOAD=./libscope.so ps -ef\n</code></pre>\n<p>This executes the command <code>ps -ef</code>. But first, the OS's loader loads the AppScope library, as part of loading and linking the <code>ps</code> executable.</p>\n<p>Details of the <code>ps</code> application's execution are emitted to the configured transport, in the configured format. For configuration details, see <a href=\"#env-vars\">Env Vars and the Config File</a> above.</p>\n<h4 id=\"ld_preload-with-verbosity-specified\" style=\"position:relative;\"><a href=\"#ld_preload-with-verbosity-specified\" aria-label=\"ld_preload with verbosity specified 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><code>LD_PRELOAD</code> with Verbosity Specified</h4>\n<pre><code>LD_PRELOAD=./libscope.so SCOPE_METRIC_VERBOSITY=5 ps -ef\n</code></pre>\n<p>This again executes the <code>ps</code> command using the AppScope library. But it also defines the <a href=\"/docs/events-and-metrics#metrics\">verbosity</a> for metric extraction as level <code>5</code>. (This verbosity setting overrides any config-file setting, as well as the default value.)</p>\n<h4 id=\"ld_preload-with-a-config-file\" style=\"position:relative;\"><a href=\"#ld_preload-with-a-config-file\" aria-label=\"ld_preload with a config file 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><code>LD_PRELOAD</code> with a Config File</h4>\n<pre><code>LD_PRELOAD=./libscope.so SCOPE_HOME=/etc/scope ps -ef\n</code></pre>\n<p>This again executes the <code>ps</code> command using the AppScope library. But it also directs the library to use the config file <code>/etc/scope/scope.yml</code>.</p>\n<h4 id=\"ld_preload-with-a-tcp-connection\" style=\"position:relative;\"><a href=\"#ld_preload-with-a-tcp-connection\" aria-label=\"ld_preload with a tcp connection 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><code>LD_PRELOAD</code> with a TCP Connection</h4>\n<pre><code>LD_PRELOAD=./libscope.so SCOPE_EVENT_DEST=tcp://localhost:9999 SCOPE_CRIBL_ENABLE=false ps -ef\n</code></pre>\n<p>This again executes the <code>ps</code> command using the AppScope library. But here, we also specify that events (as opposed to metrics) will be sent over a TCP connection to localhost, using port <code>9999</code>. (This event destination setting overrides any config-file setting, as well as the default value.)</p>\n<h3 id=\"adding-appscope-to-a-systemd-boot-time-service\" style=\"position:relative;\"><a href=\"#adding-appscope-to-a-systemd-boot-time-service\" aria-label=\"adding appscope to a systemd boot time service 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>Adding AppScope to a <code>systemd</code> (boot-time) Service</h3>\n<p>In this example, we'll add AppScope to the <code>httpd</code> service, described by an <code>httpd.service</code> file which contains an <code>EnvironmentFile=/etc/sysconfig/httpd</code> entry.</p>\n<ol>\n<li>Extract the library to a new directory (<code>/opt/appscope</code> in this example):</li>\n</ol>\n<pre><code>mkdir /opt/appscope &#x26;&#x26; cd /opt/appscope\ncurl -Lo scope https://cdn.cribl.io/dl/scope/\\\n $(curl -L https://cdn.cribl.io/dl/scope/latest)/linux/scope &#x26;&#x26; \\\n chmod 755 ./scope\n./scope extract .\n</code></pre>\n<p>The result will be that the system uses <code>/opt/appscope/scope.yml</code> to configure <code>libscope.so</code>.</p>\n<ol start=\"2\">\n<li>Add an <code>LD_PRELOAD</code> environment variable to the <code>systemd</code> config file.</li>\n</ol>\n<p>In the <code>httpd.service</code> file, edit the <code>/etc/sysconfig/httpd</code> entry to include the following environment variables:</p>\n<pre><code>SCOPE_HOME=/opt/appscope\nLD_PRELOAD=/opt/appscope/libscope.so\n</code></pre>\n<p><span id=\"lambda\"> </span></p>\n<h3 id=\"deploying-the-library-in-an-aws-lambda-function\" style=\"position:relative;\"><a href=\"#deploying-the-library-in-an-aws-lambda-function\" aria-label=\"deploying the library in an aws lambda function 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>Deploying the Library in an AWS Lambda Function</h3>\n<p>You can interpose the <code>libscope.so</code> library into an AWS Lambda function as a <a href=\"https://docs.aws.amazon.com/lambda/latest/dg/configuration-layers.html\">Lambda layer</a>. By default, Lambda functions use <code>lib</code> as their <code>LD_LIBRARY_PATH</code>, which makes loading AppScope easy.</p>\n<p>Assuming that you have <a href=\"https://aws.amazon.com/lambda/getting-started/\">created</a> one or more AWS Lambda functions, all you need to do is add the Lambda layer, then set environment variables for the Lambda function.</p>\n<h4 id=\"adding-an-appscope-aws-lambda-layer\" style=\"position:relative;\"><a href=\"#adding-an-appscope-aws-lambda-layer\" aria-label=\"adding an appscope aws lambda layer 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>Adding an AppScope AWS Lambda Layer</h4>\n<ol>\n<li>\n<p>Start with one of the AWS Lambda Layers for AppScope that Cribl provides. You can obtain the AWS Lambda Layers and their MD5 checksums from the Cribl CDN.</p>\n<ul>\n<li><code>AWS Lambda Layer for x86</code>: <a href=\"https://cdn.cribl.io/dl/scope/1.2.2/linux/x86_64/aws-lambda-layer.zip\">https://cdn.cribl.io/dl/scope/1.2.2/linux/x86_64/aws-lambda-layer.zip</a></li>\n<li><code>AWS Lambda Layer for ARM</code>: <a href=\"https://cdn.cribl.io/dl/scope/1.2.2/linux/aarch64/aws-lambda-layer.zip\">https://cdn.cribl.io/dl/scope/1.2.2/linux/aarch64/aws-lambda-layer.zip</a></li>\n<li>To obtain the MD5 checksum for either file above, add <code>.md5</code> to the file path.</li>\n</ul>\n</li>\n<li>Complete the procedure for creating a layer described in the <a href=\"https://docs.aws.amazon.com/lambda/latest/dg/configuration-layers.html#configuration-layers-create\">AWS docs</a>, uploading your AppScope AWS Lambda Layer ZIP file in the <strong>upload your layer code</strong> step, and choosing <code>x86_64</code> or <code>ARM64</code>, as appropriate, for <strong>Compatible architectures</strong>.</li>\n<li>After you click <strong>Create</strong>, note the <strong>Version ARN</strong> shown for your newly-created layer.</li>\n<li>Navigate to <strong>Lambda</strong> > <strong>Layers</strong> > <strong>Add layer</strong>, and in the <strong>Choose a layer</strong> section, select <strong>Specify an ARN</strong>. </li>\n<li>Enter your layer's ARN, click <strong>Verify</strong>, and then click <strong>Add</strong>.  </li>\n</ol>\n<h4 id=\"setting-the-lambda-functions-environment-variables\" style=\"position:relative;\"><a href=\"#setting-the-lambda-functions-environment-variables\" aria-label=\"setting the lambda functions environment variables 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>Setting the Lambda Function's Environment Variables</h4>\n<p>The AWS docs <a href=\"https://docs.aws.amazon.com/lambda/latest/dg/configuration-envvars.html\">explain</a> how to set environmental variables for Lambda functions. You'll need to enter the following AppScope environment variable settings in the AWS UI.</p>\n<ol>\n<li>\n<p><code>LD_PRELOAD</code> gets your Lambda function working with AppScope.</p>\n<ul>\n<li><code>LD_PRELOAD=libscope.so</code></li>\n</ul>\n</li>\n<li>\n<p><code>SCOPE_EXEC_PATH</code> is required for static executables (like the Go runtime).</p>\n<ul>\n<li><code>SCOPE_EXEC_PATH=/opt/appscope/scope</code></li>\n</ul>\n</li>\n<li>\n<p>To tell AppScope where to deliver events, the required environment variable depends on your desired <a href=\"/docs/data-routing\">Data Routing</a>.</p>\n<ul>\n<li>For example, <code>SCOPE_CRIBL_CLOUD</code> is required for an <a href=\"https://docs.cribl.io/stream/sources-appscope\">AppScope Source</a> in a Cribl.Cloud-managed instance of Cribl Stream. (Substitute your host and port values for the placeholders.)</li>\n<li><code>SCOPE_CRIBL_CLOUD=tcp://&#x3C;host>:&#x3C;port></code></li>\n</ul>\n</li>\n<li>\n<p>Optionally, set additional environment variables as desired. </p>\n<ul>\n<li>For example, <code>SCOPE_CONF_PATH</code> ensures that your Lambda function uses AppScope with the correct config file. (Edit the path if yours is different.)</li>\n<li><code>SCOPE_CONF_PATH=/opt/appscope/scope.yml</code></li>\n</ul>\n</li>\n</ol>","frontmatter":{"title":"Using the Library"}}},"pageContext":{"slug":"/library-using/","id":"57133b2b-5ede-5e15-817c-1466475dedb7"}},"staticQueryHashes":["2787008656","306729481","625673991","640077088"]}