<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Grafana Alloy on Grafana Labs</title><link>https://grafana.com/docs/pyroscope/v1.18.x/configure-client/grafana-alloy/</link><description>Recent content in Grafana Alloy on Grafana Labs</description><generator>Hugo -- gohugo.io</generator><language>en</language><atom:link href="/docs/pyroscope/v1.18.x/configure-client/grafana-alloy/index.xml" rel="self" type="application/rss+xml"/><item><title>Receive profiles from Pyroscope SDKs</title><link>https://grafana.com/docs/pyroscope/v1.18.x/configure-client/grafana-alloy/receive_profiles/</link><pubDate>Wed, 08 Apr 2026 14:38:28 +0000</pubDate><guid>https://grafana.com/docs/pyroscope/v1.18.x/configure-client/grafana-alloy/receive_profiles/</guid><content><![CDATA[&lt;h1 id=&#34;receive-profiles-from-pyroscope-sdks&#34;&gt;Receive profiles from Pyroscope SDKs&lt;/h1&gt;
&lt;p&gt;The &lt;code&gt;pyroscope.receive_http&lt;/code&gt; component in Alloy receives profiles from applications instrumented with Pyroscope SDKs. This approach provides several benefits:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Lower latency by sending profiles to a local Alloy instance instead of over internet&lt;/li&gt;
&lt;li&gt;Separation of infrastructure concerns (auth, routing) from application code&lt;/li&gt;
&lt;li&gt;Centralized management of authentication and metadata enrichment&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;For more information about this component, refer to the 
    &lt;a href=&#34;/docs/alloy/v1.18.x/reference/components/pyroscope/pyroscope.receive_http/&#34;&gt;pyroscope.receive_http component&lt;/a&gt; documentation.&lt;/p&gt;


&lt;div class=&#34;admonition admonition-note&#34;&gt;&lt;blockquote&gt;&lt;p class=&#34;title text-uppercase&#34;&gt;Note&lt;/p&gt;&lt;p&gt;The &lt;code&gt;pyroscope.receive_http&lt;/code&gt; component is currently in public preview. To use this component, set the &lt;code&gt;--stability.level&lt;/code&gt; flag to &lt;code&gt;public-preview&lt;/code&gt;. For more information about Alloy&amp;rsquo;s run usage, refer to the &lt;a href=&#34;/docs/grafana-cloud/send-data/alloy/reference/cli/run/#the-run-command&#34;&gt;run command documentation&lt;/a&gt; documentation.&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;

&lt;p&gt;To set up profile receiving, you need to:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Configure Alloy components&lt;/li&gt;
&lt;li&gt;Configure your application&amp;rsquo;s SDK&lt;/li&gt;
&lt;li&gt;Start Alloy&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&#34;configure-alloy-components&#34;&gt;Configure Alloy components&lt;/h2&gt;
&lt;p&gt;The configuration requires at least two components:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
    &lt;a href=&#34;/docs/alloy/v1.18.x/reference/components/pyroscope/pyroscope.receive_http/&#34;&gt;&lt;code&gt;pyroscope.receive_http&lt;/code&gt;&lt;/a&gt; to receive profiles via HTTP&lt;/li&gt;
&lt;li&gt;
    &lt;a href=&#34;/docs/alloy/v1.18.x/reference/components/pyroscope/pyroscope.write/&#34;&gt;&lt;code&gt;pyroscope.write&lt;/code&gt;&lt;/a&gt; to forward profiles to Pyroscope&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Here&amp;rsquo;s a basic configuration that sets up a simple profile collection pipeline.
It creates a receiver to collect profiles from your applications and forwards them through a writer component to send them to the Pyroscope backend:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;Alloy&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-alloy&#34;&gt;// Receives profiles over HTTP
pyroscope.receive_http &amp;#34;default&amp;#34; {
   http {
       listen_address = &amp;#34;0.0.0.0&amp;#34;
       listen_port = 9999
   }
   forward_to = [pyroscope.write.backend.receiver]
}

// Forwards profiles to Pyroscope
pyroscope.write &amp;#34;backend&amp;#34; {
   endpoint {
       url = &amp;#34;http://pyroscope:4040&amp;#34;
   }
}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h2 id=&#34;configure-application-sdk&#34;&gt;Configure application SDK&lt;/h2&gt;
&lt;p&gt;Update your application&amp;rsquo;s SDK configuration to point to Alloy&amp;rsquo;s receive endpoint instead of Pyroscope directly. For example, in Go:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;Go&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-go&#34;&gt;config := pyroscope.Config{
    ApplicationName: &amp;#34;my.service.cpu&amp;#34;,
    ServerAddress:   &amp;#34;http://localhost:9999&amp;#34;, // Alloy&amp;#39;s receive endpoint
}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Check your specific language SDK documentation for the exact configuration options.&lt;/p&gt;
&lt;h2 id=&#34;examples&#34;&gt;Examples&lt;/h2&gt;
&lt;p&gt;The examples in this section provide samples you can use as a starting point for your own configurations.&lt;/p&gt;
&lt;p&gt;Explore the &lt;a href=&#34;https://github.com/grafana/pyroscope/tree/main/examples/language-sdk-instrumentation/golang-push/rideshare-alloy&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;example&lt;/a&gt; in the Pyroscope GitHub repository to learn how to configure Grafana Alloy to receive profiles from a Golang application instrumented with Pyroscope.&lt;/p&gt;
&lt;h3 id=&#34;basic-receiving-setup&#34;&gt;Basic receiving setup&lt;/h3&gt;
&lt;p&gt;This example shows a basic setup receiving profiles on port 9090 and forwarding them to a local Pyroscope instance:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;Alloy&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-alloy&#34;&gt;pyroscope.receive_http &amp;#34;default&amp;#34; {
    http {
        listen_address = &amp;#34;0.0.0.0&amp;#34;
        listen_port = 9090
    }
    forward_to = [pyroscope.write.production.receiver]
}

pyroscope.write &amp;#34;production&amp;#34; {
    endpoint {
        url = &amp;#34;http://localhost:4040&amp;#34;
    }
}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h3 id=&#34;authentication&#34;&gt;Authentication&lt;/h3&gt;
&lt;p&gt;To send profiles to an authenticated Pyroscope endpoint:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;Alloy&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-alloy&#34;&gt;pyroscope.write &amp;#34;production&amp;#34; {
    endpoint {
        url = &amp;#34;http://pyroscope:4040&amp;#34;
        basic_auth {
            username = env(&amp;#34;PYROSCOPE_USERNAME&amp;#34;)
            password = env(&amp;#34;PYROSCOPE_PASSWORD&amp;#34;)
        }
    }
}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h3 id=&#34;adding-external-labels&#34;&gt;Adding external labels&lt;/h3&gt;
&lt;p&gt;External labels are added to all profiles forwarded through the write component. This is useful for adding infrastructure metadata:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;Alloy&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-alloy&#34;&gt;pyroscope.receive_http &amp;#34;default&amp;#34; {
    http {
        listen_address = &amp;#34;0.0.0.0&amp;#34;
        listen_port = 9999
    }
    forward_to = [pyroscope.write.backend.receiver]
}

pyroscope.write &amp;#34;backend&amp;#34; {
    endpoint {
        url = &amp;#34;http://pyroscope:4040&amp;#34;
    }
    external_labels = {
        &amp;#34;env&amp;#34;      = &amp;#34;production&amp;#34;,
        &amp;#34;region&amp;#34;   = &amp;#34;us-west-1&amp;#34;,
        &amp;#34;instance&amp;#34; = env(&amp;#34;HOSTNAME&amp;#34;),
        &amp;#34;cluster&amp;#34;  = &amp;#34;main&amp;#34;,
    }
}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h3 id=&#34;multiple-destinations&#34;&gt;Multiple destinations&lt;/h3&gt;
&lt;p&gt;Forward received profiles to multiple destinations - useful for testing or migration scenarios:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;Alloy&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-alloy&#34;&gt;pyroscope.receive_http &amp;#34;default&amp;#34; {
    http {
        listen_address = &amp;#34;0.0.0.0&amp;#34;
        listen_port = 9999
    }
    forward_to = [pyroscope.write.staging.receiver, pyroscope.write.production.receiver]
}

// Send profiles to staging
pyroscope.write &amp;#34;staging&amp;#34; {
    endpoint {
        url = &amp;#34;http://pyroscope-staging:4040&amp;#34;
    }
    external_labels = {
        &amp;#34;env&amp;#34; = &amp;#34;staging&amp;#34;,
    }
}

// Send profiles to production
pyroscope.write &amp;#34;production&amp;#34; {
    endpoint {
        url = &amp;#34;http://pyroscope-production:4041&amp;#34;
    }
    external_labels = {
        &amp;#34;env&amp;#34; = &amp;#34;production&amp;#34;,
    }
}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;


&lt;div class=&#34;admonition admonition-note&#34;&gt;&lt;blockquote&gt;&lt;p class=&#34;title text-uppercase&#34;&gt;Note&lt;/p&gt;&lt;p&gt;This configuration will duplicate the received profiles and send a copy to each configured &lt;code&gt;pyroscope.write&lt;/code&gt; component.&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;

&lt;p&gt;Another approach is to configure multiple receivers with multiple destinations:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;Alloy&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-alloy&#34;&gt;pyroscope.receive_http &amp;#34;staging&amp;#34; {
    http {
        listen_address = &amp;#34;0.0.0.0&amp;#34;
        listen_port = 9998
    }
    forward_to = [pyroscope.write.staging.receiver]
}

pyroscope.receive_http &amp;#34;production&amp;#34; {
    http {
        listen_address = &amp;#34;0.0.0.0&amp;#34;
        listen_port = 9999
    }
    forward_to = [pyroscope.write.production.receiver]
}

// Send profiles to staging
pyroscope.write &amp;#34;staging&amp;#34; {
    endpoint {
        url = &amp;#34;http://pyroscope-staging:4040&amp;#34;
    }
    external_labels = {
        &amp;#34;env&amp;#34; = &amp;#34;staging&amp;#34;,
    }
}

// Send profiles to production
pyroscope.write &amp;#34;production&amp;#34; {
    endpoint {
        url = &amp;#34;http://pyroscope-production:4041&amp;#34;
    }
    external_labels = {
        &amp;#34;env&amp;#34; = &amp;#34;production&amp;#34;,
    }
}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;For more information about component configuration options, refer to:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;pyroscope.receive_http &lt;a href=&#34;/docs/alloy/latest/reference/components/pyroscope/pyroscope.write/&#34;&gt;documentation&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;pyroscope.write &lt;a href=&#34;/docs/alloy/latest/reference/components/pyroscope/pyroscope.receive_http/&#34;&gt;documentation&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
]]></content><description>&lt;h1 id="receive-profiles-from-pyroscope-sdks">Receive profiles from Pyroscope SDKs&lt;/h1>
&lt;p>The &lt;code>pyroscope.receive_http&lt;/code> component in Alloy receives profiles from applications instrumented with Pyroscope SDKs. This approach provides several benefits:&lt;/p>
&lt;ul>
&lt;li>Lower latency by sending profiles to a local Alloy instance instead of over internet&lt;/li>
&lt;li>Separation of infrastructure concerns (auth, routing) from application code&lt;/li>
&lt;li>Centralized management of authentication and metadata enrichment&lt;/li>
&lt;/ul>
&lt;p>For more information about this component, refer to the
&lt;a href="/docs/alloy/v1.18.x/reference/components/pyroscope/pyroscope.receive_http/">pyroscope.receive_http component&lt;/a> documentation.&lt;/p></description></item><item><title>Set up Go profiling in pull mode</title><link>https://grafana.com/docs/pyroscope/v1.18.x/configure-client/grafana-alloy/go_pull/</link><pubDate>Wed, 08 Apr 2026 14:38:28 +0000</pubDate><guid>https://grafana.com/docs/pyroscope/v1.18.x/configure-client/grafana-alloy/go_pull/</guid><content><![CDATA[&lt;h1 id=&#34;set-up-go-profiling-in-pull-mode&#34;&gt;Set up Go profiling in pull mode&lt;/h1&gt;
&lt;p&gt;In pull mode, the collector, Grafana Alloy, periodically retrieves profiles from Golang applications, specifically targeting the
&lt;code&gt;/debug/pprof/*&lt;/code&gt; endpoints.&lt;/p&gt;
&lt;p&gt;To set up Golang profiling in pull mode, you need to:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Expose pprof endpoints.&lt;/li&gt;
&lt;li&gt;Install a collector, such as Grafana Alloy.&lt;/li&gt;
&lt;li&gt;Prepare the collector&amp;rsquo;s configuration file.&lt;/li&gt;
&lt;li&gt;Start the collector.&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&#34;expose-pprof-endpoints&#34;&gt;Expose pprof endpoints&lt;/h2&gt;
&lt;p&gt;Ensure your Golang application exposes pprof endpoints.&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Get &lt;code&gt;godeltaprof&lt;/code&gt; package&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;Bash&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-bash&#34;&gt;go get github.com/grafana/pyroscope-go/godeltaprof@latest&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Import &lt;code&gt;net/http/pprof&lt;/code&gt; and &lt;code&gt;godeltaprof/http/pprof&lt;/code&gt; packages at the start of your application.&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;Go&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-go&#34;&gt;import _ &amp;#34;net/http/pprof&amp;#34;
import _ &amp;#34;github.com/grafana/pyroscope-go/godeltaprof/http/pprof&amp;#34;&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&#34;install-the-collector&#34;&gt;Install the collector&lt;/h2&gt;
&lt;p&gt;You can use the sample Alloy collector configuration file to send data to Pyroscope.&lt;/p&gt;
&lt;p&gt;To install Alloy, refer to 
    &lt;a href=&#34;/docs/alloy/v1.18.x/get-started/install/&#34;&gt;Grafana Alloy installation&lt;/a&gt;.&lt;/p&gt;
&lt;h3 id=&#34;prepare-the-collector-configuration-file&#34;&gt;Prepare the collector configuration file&lt;/h3&gt;
&lt;p&gt;In the Alloy configuration file, you need to add at least two blocks: &lt;code&gt;pyroscope.write&lt;/code&gt; and &lt;code&gt;pyroscope.scrape&lt;/code&gt;.&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Add &lt;code&gt;pyroscope.write&lt;/code&gt; block.&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;Alloy&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-alloy&#34;&gt;pyroscope.write &amp;#34;write_job_name&amp;#34; {
        endpoint {
                url = &amp;#34;http://localhost:4040&amp;#34;
        }
}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Add &lt;code&gt;pyroscope.scrape&lt;/code&gt; block.&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;Alloy&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-alloy&#34;&gt;pyroscope.scrape &amp;#34;scrape_job_name&amp;#34; {
        targets    = [{&amp;#34;__address__&amp;#34; = &amp;#34;localhost:4040&amp;#34;, &amp;#34;service_name&amp;#34; = &amp;#34;example_service&amp;#34;}]
        forward_to = [pyroscope.write.write_job_name.receiver]

        profiling_config {
                profile.process_cpu {
                        enabled = true
                }

                profile.godeltaprof_memory {
                        enabled = true
                }

                profile.memory { // disable memory, use godeltaprof_memory instead
                        enabled = false
                }

                profile.godeltaprof_mutex {
                        enabled = true
                }

                profile.mutex { // disable mutex, use godeltaprof_mutex instead
                        enabled = false
                }

                profile.godeltaprof_block {
                        enabled = true
                }

                profile.block { // disable block, use godeltaprof_block instead
                        enabled = false
                }

                profile.goroutine {
                        enabled = true
                }
        }
}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Save the changes to the file.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id=&#34;start-the-collector&#34;&gt;Start the collector&lt;/h3&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Start a local Pyroscope instance for testing purposes:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;Bash&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-bash&#34;&gt;docker run -p 4040:4040 grafana/pyroscope&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;To start Alloy v1.2 and later: Replace &lt;code&gt;configuration.alloy&lt;/code&gt; with your configuration filename: &lt;br&gt; &lt;code&gt;alloy run configuration.alloy&lt;/code&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Open a browser to &lt;code&gt;http://localhost:4040&lt;/code&gt;. The page should list profiles.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&#34;examples&#34;&gt;Examples&lt;/h2&gt;
&lt;h3 id=&#34;send-data-to-grafana-cloud&#34;&gt;Send data to Grafana Cloud&lt;/h3&gt;
&lt;p&gt;Your Grafana Cloud URL, username, and password can be found on the &amp;ldquo;Details Page&amp;rdquo; for Pyroscope from your stack on
grafana.com.
On this same page, create a token and use it as the Basic authentication password.&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;Alloy&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-alloy&#34;&gt;pyroscope.write &amp;#34;write_job_name&amp;#34; {
        endpoint {
                url = &amp;#34;&amp;lt;Grafana Cloud URL&amp;gt;&amp;#34;

                basic_auth {
                        username = &amp;#34;&amp;lt;Grafana Cloud User&amp;gt;&amp;#34;
                        password = &amp;#34;&amp;lt;Grafana Cloud Password&amp;gt;&amp;#34;
                }
        }

}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h3 id=&#34;discover-kubernetes-targets&#34;&gt;Discover Kubernetes targets&lt;/h3&gt;
&lt;ol&gt;
&lt;li&gt;Select all pods&lt;/li&gt;
&lt;/ol&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;Alloy&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-alloy&#34;&gt;discovery.kubernetes &amp;#34;all_pods&amp;#34; {
        role = &amp;#34;pod&amp;#34;
}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Drop not running pods, create &lt;code&gt;namespace&lt;/code&gt;, &lt;code&gt;pod&lt;/code&gt;, &lt;code&gt;node&lt;/code&gt; and &lt;code&gt;container&lt;/code&gt; labels.
Compose &lt;code&gt;service_name&lt;/code&gt; label based on &lt;code&gt;namespace&lt;/code&gt; and &lt;code&gt;container&lt;/code&gt; labels.
Select only services matching regex pattern &lt;code&gt;(ns1/.*)|(ns2/container-.*0)&lt;/code&gt;.&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;Alloy&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-alloy&#34;&gt;
discovery.relabel &amp;#34;specific_pods&amp;#34; {
        targets = discovery.kubernetes.all_pods.targets

        rule {
                action        = &amp;#34;drop&amp;#34;
                regex         = &amp;#34;Succeeded|Failed|Completed&amp;#34;
                source_labels = [&amp;#34;__meta_kubernetes_pod_phase&amp;#34;]
        }

        rule {
                action        = &amp;#34;replace&amp;#34;
                source_labels = [&amp;#34;__meta_kubernetes_namespace&amp;#34;]
                target_label  = &amp;#34;namespace&amp;#34;
        }

        rule {
                action        = &amp;#34;replace&amp;#34;
                source_labels = [&amp;#34;__meta_kubernetes_pod_name&amp;#34;]
                target_label  = &amp;#34;pod&amp;#34;
        }

        rule {
                action        = &amp;#34;replace&amp;#34;
                source_labels = [&amp;#34;__meta_kubernetes_node_name&amp;#34;]
                target_label  = &amp;#34;node&amp;#34;
        }

        rule {
                action        = &amp;#34;replace&amp;#34;
                source_labels = [&amp;#34;__meta_kubernetes_pod_container_name&amp;#34;]
                target_label  = &amp;#34;container&amp;#34;
        }

        rule {
                action        = &amp;#34;replace&amp;#34;
                regex         = &amp;#34;(.*)@(.*)&amp;#34;
                replacement   = &amp;#34;${1}/${2}&amp;#34;
                separator     = &amp;#34;@&amp;#34;
                source_labels = [&amp;#34;__meta_kubernetes_namespace&amp;#34;, &amp;#34;__meta_kubernetes_pod_container_name&amp;#34;]
                target_label  = &amp;#34;service_name&amp;#34;
        }

        rule {
                action        = &amp;#34;keep&amp;#34;
                regex         = &amp;#34;(ns1/.*)|(ns2/container-.*0)&amp;#34;
                source_labels = [&amp;#34;service_name&amp;#34;]
        }
}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Use &lt;code&gt;discovery.relabel.specific_pods.output&lt;/code&gt; as a target for &lt;code&gt;pyroscope.scrape&lt;/code&gt; block.&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;Alloy&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-alloy&#34;&gt;    pyroscope.scrape &amp;#34;scrape_job_name&amp;#34; {
            targets    = discovery.relabel.specific_pods.output
            ...
    }&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id=&#34;exposing-pprof-endpoints&#34;&gt;Exposing pprof endpoints&lt;/h3&gt;
&lt;p&gt;If you don&amp;rsquo;t use &lt;code&gt;http.DefaultServeMux&lt;/code&gt;, you can register &lt;code&gt;/debug/pprof/*&lt;/code&gt; handlers to your own &lt;code&gt;http.ServeMux&lt;/code&gt;:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;Go&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-go&#34;&gt;var mux *http.ServeMux
mux.Handle(&amp;#34;/debug/pprof/&amp;#34;, http.DefaultServeMux)&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Or, if you use gorilla/mux:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;Go&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-go&#34;&gt;var router *mux.Router
router.PathPrefix(&amp;#34;/debug/pprof&amp;#34;).Handler(http.DefaultServeMux)&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h2 id=&#34;references&#34;&gt;References&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;
    &lt;a href=&#34;/docs/alloy/v1.18.x/&#34;&gt;Grafana Alloy&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;
    &lt;a href=&#34;/docs/alloy/v1.18.x/reference/components/pyroscope/pyroscope.scrape/&#34;&gt;pyroscope.scrape&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;
    &lt;a href=&#34;/docs/alloy/v1.18.x/reference/components/pyroscope/pyroscope.write/&#34;&gt;pyroscope.write&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;
    &lt;a href=&#34;/docs/alloy/v1.18.x/reference/components/discovery/discovery.kubernetes/&#34;&gt;discovery.kubernetes&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;
    &lt;a href=&#34;/docs/alloy/v1.18.x/reference/components/discovery/discovery.docker/&#34;&gt;discovery.docker&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;
    &lt;a href=&#34;/docs/alloy/v1.18.x/reference/components/discovery/discovery.relabel/&#34;&gt;discovery.relabel&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
]]></content><description>&lt;h1 id="set-up-go-profiling-in-pull-mode">Set up Go profiling in pull mode&lt;/h1>
&lt;p>In pull mode, the collector, Grafana Alloy, periodically retrieves profiles from Golang applications, specifically targeting the
&lt;code>/debug/pprof/*&lt;/code> endpoints.&lt;/p></description></item><item><title>Set up Java profiling using Grafana Alloy</title><link>https://grafana.com/docs/pyroscope/v1.18.x/configure-client/grafana-alloy/java/</link><pubDate>Wed, 08 Apr 2026 14:38:28 +0000</pubDate><guid>https://grafana.com/docs/pyroscope/v1.18.x/configure-client/grafana-alloy/java/</guid><content><![CDATA[&lt;h1 id=&#34;set-up-java-profiling-using-grafana-alloy&#34;&gt;Set up Java profiling using Grafana Alloy&lt;/h1&gt;
&lt;p&gt;Grafana Alloy supports Java profiling.
The collector configuration file is composed of components that are used to collect,
transform, and send data.
The Alloy configuration files use the Alloy 
    &lt;a href=&#34;/docs/alloy/v1.18.x/concepts/configuration-syntax/&#34;&gt;configuration syntax&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&#34;configure-the-components&#34;&gt;Configure the components&lt;/h2&gt;
&lt;p&gt;The 
    &lt;a href=&#34;/docs/alloy/v1.18.x/reference/components/pyroscope/pyroscope.java/&#34;&gt;&lt;code&gt;pyroscope.java&lt;/code&gt; component&lt;/a&gt; is used to continuously profile Java processes running on the local Linux OS
using &lt;a href=&#34;https://github.com/async-profiler/async-profiler&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;async-profiler&lt;/a&gt;.&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;Alloy&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-alloy&#34;&gt;pyroscope.java &amp;#34;java&amp;#34; {
  profiling_config {
    interval = &amp;#34;15s&amp;#34;
    alloc = &amp;#34;512k&amp;#34;
    cpu = true
    event = &amp;#34;wall&amp;#34;
    per_thread = true
    lock = &amp;#34;10ms&amp;#34;
    sample_rate = 100
  }
  forward_to = [pyroscope.write.endpoint.receiver]
  targets = discovery.relabel.java.output
}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Using the &lt;code&gt;targets&lt;/code&gt; argument, you can specify which processes and containers to profile on the machine.&lt;/p&gt;
&lt;p&gt;The &lt;code&gt;targets&lt;/code&gt; can be from &lt;code&gt;discovery.process&lt;/code&gt; component.
You can use &lt;code&gt;discovery.process&lt;/code&gt; join argument to join process targets with extra discoveries such as 
    &lt;a href=&#34;/docs/alloy/v1.18.x/reference/components/discovery/discovery.kubernetes/&#34;&gt;&lt;code&gt;discovery.kubernetes&lt;/code&gt;&lt;/a&gt;, 
    &lt;a href=&#34;/docs/alloy/v1.18.x/reference/components/discovery/discovery.docker/&#34;&gt;&lt;code&gt;discovery.docker&lt;/code&gt;&lt;/a&gt;, and 
    &lt;a href=&#34;/docs/alloy/v1.18.x/reference/components/discovery/discovery.dockerswarm/&#34;&gt;&lt;code&gt;discovery.dockerswarm&lt;/code&gt;&lt;/a&gt;.
You can use the 
    &lt;a href=&#34;/docs/alloy/v1.18.x/reference/components/discovery/discovery.relabel/&#34;&gt;&lt;code&gt;discovery.relabel&lt;/code&gt;&lt;/a&gt; component to relabel discovered targets and set your own labels.
For more information, refer to the 
    &lt;a href=&#34;/docs/alloy/v1.18.x/reference/components/&#34;&gt;Components&lt;/a&gt; documentation.&lt;/p&gt;
&lt;p&gt;The &lt;code&gt;forward_to&lt;/code&gt; parameter should point to a 
    &lt;a href=&#34;/docs/alloy/v1.18.x/reference/components/pyroscope/pyroscope.write/&#34;&gt;&lt;code&gt;pyroscope.write&lt;/code&gt;&lt;/a&gt; component to send the collected profiles to your
Pyroscope Server or &lt;a href=&#34;/products/cloud/&#34;&gt;Grafana Cloud&lt;/a&gt;.&lt;/p&gt;
&lt;section class=&#34;expand-table-wrapper&#34;&gt;&lt;div class=&#34;button-div&#34;&gt;
      &lt;button class=&#34;expand-table-btn&#34;&gt;Expand table&lt;/button&gt;
    &lt;/div&gt;&lt;div class=&#34;responsive-table-wrapper&#34;&gt;
    &lt;table&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th&gt;Name&lt;/th&gt;
              &lt;th&gt;Type&lt;/th&gt;
              &lt;th&gt;Description&lt;/th&gt;
              &lt;th&gt;Default&lt;/th&gt;
              &lt;th&gt;Required&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;targets&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;&lt;code&gt;list(map(string))&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;List of java process targets to profile.&lt;/td&gt;
              &lt;td&gt;&lt;/td&gt;
              &lt;td&gt;yes&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;forward_to&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;&lt;code&gt;list(ProfilesReceiver)&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;List of receivers to send collected profiles to.&lt;/td&gt;
              &lt;td&gt;&lt;/td&gt;
              &lt;td&gt;yes&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;tmp_dir&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;&lt;code&gt;string&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;Temporary directory to store async-profiler.&lt;/td&gt;
              &lt;td&gt;&lt;code&gt;/tmp&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;no&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&gt;&lt;p&gt;The special label &lt;code&gt;__process_pid__&lt;/code&gt; &lt;em&gt;must always&lt;/em&gt; be present in each target of &lt;code&gt;targets&lt;/code&gt; and corresponds to the &lt;code&gt;PID&lt;/code&gt; of
the process to profile.&lt;/p&gt;
&lt;p&gt;The special label &lt;code&gt;service_name&lt;/code&gt; is required and must always be present.
If &lt;code&gt;service_name&lt;/code&gt; isn&amp;rsquo;t specified, &lt;code&gt;pyroscope.java&lt;/code&gt; attempts to infer it from discovery meta labels.
If &lt;code&gt;service_name&lt;/code&gt; isn&amp;rsquo;t specified and couldn&amp;rsquo;t be inferred, then it&amp;rsquo;s set to &lt;code&gt;unspecified&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;The &lt;code&gt;profiling_config&lt;/code&gt; block describes how async-profiler is invoked.&lt;/p&gt;
&lt;p&gt;It supports the following arguments:&lt;/p&gt;
&lt;section class=&#34;expand-table-wrapper&#34;&gt;&lt;div class=&#34;button-div&#34;&gt;
      &lt;button class=&#34;expand-table-btn&#34;&gt;Expand table&lt;/button&gt;
    &lt;/div&gt;&lt;div class=&#34;responsive-table-wrapper&#34;&gt;
    &lt;table&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th&gt;Name&lt;/th&gt;
              &lt;th&gt;Type&lt;/th&gt;
              &lt;th&gt;Description&lt;/th&gt;
              &lt;th&gt;Default&lt;/th&gt;
              &lt;th&gt;Required&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;interval&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;&lt;code&gt;duration&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;How frequently to collect profiles from the targets.&lt;/td&gt;
              &lt;td&gt;&amp;ldquo;60s&amp;rdquo;&lt;/td&gt;
              &lt;td&gt;no&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;cpu&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;&lt;code&gt;bool&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;A flag to enable CPU profiling, using &lt;code&gt;itimer&lt;/code&gt; async-profiler event.&lt;/td&gt;
              &lt;td&gt;true&lt;/td&gt;
              &lt;td&gt;no&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;event&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;&lt;code&gt;string&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;Sets the CPU profiling event. Can be one of &lt;code&gt;itimer&lt;/code&gt;, &lt;code&gt;cpu&lt;/code&gt;, or &lt;code&gt;wall&lt;/code&gt;.&lt;/td&gt;
              &lt;td&gt;&amp;ldquo;itimer&amp;rdquo;&lt;/td&gt;
              &lt;td&gt;no&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;sample_rate&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;&lt;code&gt;int&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;CPU profiling sample rate. It&amp;rsquo;s converted from Hz to interval and passed as &lt;code&gt;-i&lt;/code&gt; arg to async-profiler.&lt;/td&gt;
              &lt;td&gt;100&lt;/td&gt;
              &lt;td&gt;no&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;alloc&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;&lt;code&gt;string&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;Allocation profiling sampling configuration  It&amp;rsquo;s passed as &lt;code&gt;--alloc&lt;/code&gt; arg to async-profiler.&lt;/td&gt;
              &lt;td&gt;&amp;ldquo;512k&amp;rdquo;&lt;/td&gt;
              &lt;td&gt;no&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;lock&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;&lt;code&gt;string&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;Lock profiling sampling configuration. It&amp;rsquo;s passed as &lt;code&gt;--lock&lt;/code&gt; arg to async-profiler.&lt;/td&gt;
              &lt;td&gt;&amp;ldquo;10ms&amp;rdquo;&lt;/td&gt;
              &lt;td&gt;no&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;per_thread&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;&lt;code&gt;bool&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;Enables async-profiler per-thread mode (&lt;code&gt;-t&lt;/code&gt;). Recommended when using wall event profiling.&lt;/td&gt;
              &lt;td&gt;false&lt;/td&gt;
              &lt;td&gt;no&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&gt;&lt;p&gt;For more information on async-profiler configuration,
see &lt;a href=&#34;https://github.com/async-profiler/async-profiler?tab=readme-ov-file#profiler-options&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;profiler-options&lt;/a&gt;.&lt;/p&gt;
&lt;h3 id=&#34;set-privileges-for-the-collector&#34;&gt;Set privileges for the collector&lt;/h3&gt;
&lt;p&gt;You must run the collector, such Alloy, as root and inside host &lt;code&gt;pid&lt;/code&gt; namespace for the &lt;code&gt;pyroscope.java&lt;/code&gt; and &lt;code&gt;discover.process&lt;/code&gt; components to work.&lt;/p&gt;
&lt;h3 id=&#34;start-the-collector&#34;&gt;Start the collector&lt;/h3&gt;
&lt;p&gt;To start Grafana Alloy v1.2 and later, replace &lt;code&gt;configuration.alloy&lt;/code&gt; with your configuration filename:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;Bash&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-bash&#34;&gt;alloy run configuration.alloy&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;To start Grafana Alloy v1.0 or 1.1, replace &lt;code&gt;configuration.alloy&lt;/code&gt; with your configuration file name:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;Bash&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-bash&#34;&gt;alloy run --stability.level=public-preview configuration.alloy&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;The &lt;code&gt;stability.level&lt;/code&gt; option is required for &lt;code&gt;pyroscope.scrape&lt;/code&gt; with Alloy v1.0 or v1.1. For more information about &lt;code&gt;stability.level&lt;/code&gt;, refer to 
    &lt;a href=&#34;/docs/alloy/v1.18.x/reference/cli/run/#permitted-stability-levels&#34;&gt;the run command&lt;/a&gt; documentation.&lt;/p&gt;
&lt;h3 id=&#34;send-data-to-grafana-cloud-profiles&#34;&gt;Send data to Grafana Cloud Profiles&lt;/h3&gt;
&lt;p&gt;When sending to Grafana Cloud Profiles, you can use the following &lt;code&gt;pyroscope.write&lt;/code&gt; component configuration which uses environment variables.&lt;/p&gt;
&lt;p&gt;Ensure that you have appropriately configured the &lt;code&gt;GC_URL&lt;/code&gt;, &lt;code&gt;GC_USER&lt;/code&gt;, and &lt;code&gt;GC_PASSWORD&lt;/code&gt; environment variables.&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;Alloy&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-alloy&#34;&gt;pyroscope.write &amp;#34;endpoint&amp;#34; {
    endpoint {
        basic_auth {
            password = env(&amp;#34;GC_PASSWORD&amp;#34;)
            username = env(&amp;#34;GC_USER&amp;#34;)
        }
        url = env(&amp;#34;GC_URL&amp;#34;)
    }
}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h2 id=&#34;examples&#34;&gt;Examples&lt;/h2&gt;
&lt;p&gt;For more robust examples, refer to the &lt;a href=&#34;https://github.com/grafana/pyroscope/tree/main/examples/grafana-alloy-auto-instrumentation&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;Grafana Alloy and Agent Auto-instrumentation&lt;/a&gt; examples in the Pyroscope repository.&lt;/p&gt;
&lt;h3 id=&#34;profiling-local-process&#34;&gt;Profiling local process&lt;/h3&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;Alloy&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-alloy&#34;&gt;discovery.process &amp;#34;all&amp;#34; {
}

discovery.relabel &amp;#34;java&amp;#34; {
    targets = discovery.process.all.targets
    // Filter only java processes
    rule {
        source_labels = [&amp;#34;__meta_process_exe&amp;#34;]
        action = &amp;#34;keep&amp;#34;
        regex = &amp;#34;.*/java$&amp;#34;
    }
    // Filter processes. For example: only processes with command line containing &amp;#34;FastSlow&amp;#34;
    rule {
        source_labels = [&amp;#34;__meta_process_commandline&amp;#34;]
        regex = &amp;#34;java FastSlow&amp;#34;
        action = &amp;#34;keep&amp;#34;
    }
    // Provide a service name for the process, otherwise it will be unspecified.
    rule {
        action = &amp;#34;replace&amp;#34;
        target_label = &amp;#34;service_name&amp;#34;
        replacement = &amp;#34;java-fast-slow&amp;#34;
    }
}

pyroscope.java &amp;#34;java&amp;#34; {
  forward_to = [pyroscope.write.example.receiver]
  targets = discovery.relabel.java.output
}

pyroscope.write &amp;#34;example&amp;#34; {
  endpoint {
    url = &amp;#34;http://pyroscope:4040&amp;#34;
  }
}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h3 id=&#34;profiling-docker-containers&#34;&gt;Profiling Docker containers&lt;/h3&gt;
&lt;p&gt;For a working example, refer to &lt;a href=&#34;https://github.com/grafana/pyroscope/tree/main/examples/grafana-alloy-auto-instrumentation/java/docker&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;Java profiling via auto-instrumentation example in Docker&lt;/a&gt;.&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;Alloy&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-alloy&#34;&gt;discovery.docker &amp;#34;local_containers&amp;#34; {
  host = &amp;#34;unix:///var/run/docker.sock&amp;#34;
}

discovery.process &amp;#34;all&amp;#34; {
  join = discovery.docker.local_containers.targets
}

discovery.relabel &amp;#34;java&amp;#34; {
    targets = discovery.process.all.targets
    // Filter only java processes
    rule {
        source_labels = [&amp;#34;__meta_process_exe&amp;#34;]
        action = &amp;#34;keep&amp;#34;
        regex = &amp;#34;.*/java$&amp;#34;
    }
    // Filter only needed containers
    rule {
        source_labels = [&amp;#34;__meta_docker_container_name&amp;#34;]
        regex = &amp;#34;.*suspicious_pascal&amp;#34;
        action = &amp;#34;keep&amp;#34;
    }
    // Provide a service name for the process, otherwise it will default to the value of __meta_docker_container_name label.
    rule {
        action = &amp;#34;replace&amp;#34;
        target_label = &amp;#34;service_name&amp;#34;
        replacement = &amp;#34;java-fast-slow&amp;#34;
    }
}

pyroscope.java &amp;#34;java&amp;#34; {
  forward_to = [pyroscope.write.example.receiver]
  targets = discovery.relabel.java.output
}

pyroscope.write &amp;#34;example&amp;#34; {
  endpoint {
    url = &amp;#34;http://pyroscope:4040&amp;#34;
  }
}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h3 id=&#34;profiling-kubernetes-pods&#34;&gt;Profiling Kubernetes pods&lt;/h3&gt;
&lt;p&gt;For a working example, refer to &lt;a href=&#34;https://github.com/grafana/pyroscope/tree/main/examples/grafana-alloy-auto-instrumentation/java/kubernetes&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;Grafana Alloy Java profiling via auto-instrumentation with Kubernetes&lt;/a&gt;.&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;Alloy&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-alloy&#34;&gt;discovery.kubernetes &amp;#34;local_pods&amp;#34; {
  selectors {
    field = &amp;#34;spec.nodeName=&amp;#34; &amp;#43; env(&amp;#34;HOSTNAME&amp;#34;)
    role = &amp;#34;pod&amp;#34;
  }
  role = &amp;#34;pod&amp;#34;
}

discovery.process &amp;#34;all&amp;#34; {
  join = discovery.kubernetes.local_pods.targets
}

discovery.relabel &amp;#34;java_pods&amp;#34; {
  targets = discovery.process.all.targets
  // Filter only java processes
  rule {
    source_labels = [&amp;#34;__meta_process_exe&amp;#34;]
    action = &amp;#34;keep&amp;#34;
    regex = &amp;#34;.*/java$&amp;#34;
  }
  rule {
    action = &amp;#34;drop&amp;#34;
    regex = &amp;#34;Succeeded|Failed|Completed&amp;#34;
    source_labels = [&amp;#34;__meta_kubernetes_pod_phase&amp;#34;]
  }
  rule {
    action = &amp;#34;replace&amp;#34;
    source_labels = [&amp;#34;__meta_kubernetes_namespace&amp;#34;]
    target_label = &amp;#34;namespace&amp;#34;
  }
  rule {
    action = &amp;#34;replace&amp;#34;
    source_labels = [&amp;#34;__meta_kubernetes_pod_name&amp;#34;]
    target_label = &amp;#34;pod&amp;#34;
  }
  rule {
    action = &amp;#34;replace&amp;#34;
    source_labels = [&amp;#34;__meta_kubernetes_pod_node_name&amp;#34;]
    target_label = &amp;#34;node&amp;#34;
  }
  rule {
    action = &amp;#34;replace&amp;#34;
    source_labels = [&amp;#34;__meta_kubernetes_pod_container_name&amp;#34;]
    target_label = &amp;#34;container&amp;#34;
  }
  // Provide arbitrary service_name label, otherwise it will be inferred from discovery labels automatically
  rule {
    action = &amp;#34;replace&amp;#34;
    regex = &amp;#34;(.*)@(.*)&amp;#34;
    replacement = &amp;#34;java/${1}/${2}&amp;#34;
    separator = &amp;#34;@&amp;#34;
    source_labels = [&amp;#34;__meta_kubernetes_namespace&amp;#34;, &amp;#34;__meta_kubernetes_pod_container_name&amp;#34;]
    target_label = &amp;#34;service_name&amp;#34;
  }
  // Filter only needed services
  rule {
    action = &amp;#34;keep&amp;#34;
    regex = &amp;#34;(java/ns1/.*)|(java/ns2/container-.*0)&amp;#34;
    source_labels = [&amp;#34;service_name&amp;#34;]
  }
}

pyroscope.java &amp;#34;java&amp;#34; {
  forward_to = [pyroscope.write.example.receiver]
  targets = discovery.relabel.java_pods.output
}

pyroscope.write &amp;#34;example&amp;#34; {
  endpoint {
    url = &amp;#34;http://pyroscope:4040&amp;#34;
  }
}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h2 id=&#34;references&#34;&gt;References&lt;/h2&gt;
&lt;p&gt;For more information:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;https://github.com/grafana/pyroscope/tree/main/examples/grafana-alloy-auto-instrumentation/java&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;Examples&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;ul&gt;
&lt;li&gt;
    &lt;a href=&#34;/docs/alloy/v1.18.x/&#34;&gt;Grafana Alloy&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;
    &lt;a href=&#34;/docs/alloy/v1.18.x/reference/components/pyroscope/pyroscope.scrape/&#34;&gt;pyroscope.scrape&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;
    &lt;a href=&#34;/docs/alloy/v1.18.x/reference/components/pyroscope/pyroscope.write/&#34;&gt;pyroscope.write&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;
    &lt;a href=&#34;/docs/alloy/v1.18.x/reference/components/discovery/discovery.kubernetes/&#34;&gt;discovery.kubernetes&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;
    &lt;a href=&#34;/docs/alloy/v1.18.x/reference/components/discovery/discovery.docker/&#34;&gt;discovery.docker&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;
    &lt;a href=&#34;/docs/alloy/v1.18.x/reference/components/discovery/discovery.relabel/&#34;&gt;discovery.relabel&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
]]></content><description>&lt;h1 id="set-up-java-profiling-using-grafana-alloy">Set up Java profiling using Grafana Alloy&lt;/h1>
&lt;p>Grafana Alloy supports Java profiling.
The collector configuration file is composed of components that are used to collect,
transform, and send data.
The Alloy configuration files use the Alloy
&lt;a href="/docs/alloy/v1.18.x/concepts/configuration-syntax/">configuration syntax&lt;/a>.&lt;/p></description></item><item><title>Set up profiling with eBPF with Grafana Alloy</title><link>https://grafana.com/docs/pyroscope/v1.18.x/configure-client/grafana-alloy/ebpf/</link><pubDate>Wed, 08 Apr 2026 14:38:28 +0000</pubDate><guid>https://grafana.com/docs/pyroscope/v1.18.x/configure-client/grafana-alloy/ebpf/</guid><content><![CDATA[&lt;h1 id=&#34;set-up-profiling-with-ebpf-with-grafana-alloy&#34;&gt;Set up profiling with eBPF with Grafana Alloy&lt;/h1&gt;
&lt;p&gt;eBPF is an advanced technology embedded into the Linux kernel. It stands for enhanced &lt;a href=&#34;https://en.wikipedia.org/wiki/EBPF&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;Berkeley Packet Filter&lt;/a&gt; and revolutionizes the capability to run sandboxed code safely within the kernel space. This technology serves multiple use cases, such as networking, security, and performance monitoring without the need to alter kernel code or load additional modules.&lt;/p&gt;
&lt;img src=&#34;/media/docs/pyroscope/ebpf_logo_color_on_white.png&#34; width=&#34;100px;&#34; alt=&#34;eBPF&#34;/&gt;
&lt;iframe width=&#34;560&#34; height=&#34;315&#34; src=&#39;https://www.youtube.com/embed/UX5aeL5KeZs&#39; title=&#34;YouTube video player&#34; frameborder=&#34;0&#34; allow=&#34;accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share&#34; referrerpolicy=&#34;strict-origin-when-cross-origin&#34; allowfullscreen&gt;&lt;/iframe&gt;
&lt;h2 id=&#34;benefits-and-tradeoffs-of-using-ebpf-for-continuous-profiling&#34;&gt;Benefits and tradeoffs of using eBPF for continuous profiling&lt;/h2&gt;
&lt;p&gt;When it comes to application profiling, eBPF offers high efficiency and minimal performance overhead.
eBPF enables the dynamic insertion of powerful monitoring code into live production systems.
By leveraging eBPF, developers can gain insights into application behavior, track resource usage, and detect bottlenecks in a way that traditional profiling tools cannot match.
eBPF&amp;rsquo;s low overhead and fine-grained data collection make it an ideal choice for continuous, real-time profiling in performance-sensitive environments.&lt;/p&gt;
&lt;p&gt;However, eBPF has some limitations that make it unsuitable for certain use cases:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;It isn&amp;rsquo;t a good fit for profiling applications that arn&amp;rsquo;t written in a supported language.&lt;/li&gt;
&lt;li&gt;It can&amp;rsquo;t be used to profile applications that aren&amp;rsquo;t running on Linux.&lt;/li&gt;
&lt;li&gt;It doesn&amp;rsquo;t support all profile types such as memory and contention/lock profiling.&lt;/li&gt;
&lt;li&gt;eBPF requires root access to the host machine, which can be a problem in some environments.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;supported-languages&#34;&gt;Supported languages&lt;/h2&gt;


&lt;div data-shared=&#34;supported-languages-ebpf.md&#34;&gt;
            &lt;p&gt;The eBPF profiler collects CPU profiles.
Natively compiled languages like C/C&#43;&#43;, Go, Rust, and Zig are supported. Frame pointers are not required — the profiler uses &lt;code&gt;.eh_frame&lt;/code&gt; data for unwinding.
Refer to &lt;a href=&#34;/docs/pyroscope/latest/configure-client/grafana-alloy/ebpf/troubleshooting/#troubleshoot-unknown-symbols&#34;&gt;Troubleshooting unknown symbols&lt;/a&gt; for additional requirements and information.&lt;/p&gt;
&lt;p&gt;The following high-level languages are also supported: Java (Hotspot JVM), .NET, Python, Ruby, PHP, Node.js, and Perl.
Each high-level language can be individually enabled or disabled in the &lt;a href=&#34;/docs/alloy/latest/reference/components/pyroscope/pyroscope.ebpf/&#34;&gt;pyroscope.ebpf&lt;/a&gt; Alloy component configuration.&lt;/p&gt;
&lt;/div&gt;

        
&lt;h2 id=&#34;ebpf-using-alloy&#34;&gt;eBPF using Alloy&lt;/h2&gt;
&lt;p&gt;Grafana Alloy is a lightweight, all-in-one collector that can collect, transform, and ship observability data.
For profiling, you can configure Alloy to collect eBPF profiles and send them to Pyroscope.&lt;/p&gt;
&lt;p&gt;This section contains instructions for installing and configuring Alloy to collect eBPF profiles.
For more information about Alloy itself, refer to the 
    &lt;a href=&#34;/docs/alloy/v1.18.x/&#34;&gt;Alloy documentation&lt;/a&gt;.&lt;/p&gt;
]]></content><description>&lt;h1 id="set-up-profiling-with-ebpf-with-grafana-alloy">Set up profiling with eBPF with Grafana Alloy&lt;/h1>
&lt;p>eBPF is an advanced technology embedded into the Linux kernel. It stands for enhanced &lt;a href="https://en.wikipedia.org/wiki/EBPF" target="_blank" rel="noopener noreferrer">Berkeley Packet Filter&lt;/a> and revolutionizes the capability to run sandboxed code safely within the kernel space. This technology serves multiple use cases, such as networking, security, and performance monitoring without the need to alter kernel code or load additional modules.&lt;/p></description></item><item><title>Sampling scrape targets</title><link>https://grafana.com/docs/pyroscope/v1.18.x/configure-client/grafana-alloy/sampling/</link><pubDate>Wed, 08 Apr 2026 14:38:28 +0000</pubDate><guid>https://grafana.com/docs/pyroscope/v1.18.x/configure-client/grafana-alloy/sampling/</guid><content><![CDATA[&lt;h1 id=&#34;sampling-scrape-targets&#34;&gt;Sampling scrape targets&lt;/h1&gt;
&lt;p&gt;Applications often have many instances deployed.
While Pyroscope is designed to handle large amounts of profiling data, you may want only a subset of the application&amp;rsquo;s instances to be scraped.&lt;/p&gt;
&lt;p&gt;For example, the volume of profiling data your application generates may make it unreasonable to profile every instance, or you might be targeting cost-reduction.&lt;/p&gt;
&lt;p&gt;Through configuration of Grafana Alloy collector, Pyroscope can sample scrape targets.&lt;/p&gt;
&lt;h2 id=&#34;before-you-begin&#34;&gt;Before you begin&lt;/h2&gt;
&lt;p&gt;Make sure you understand how to configure the collector to scrape targets and are familiar with the component configuration language.
Alloy configuration files use the Alloy &lt;a href=&#34;/docs/alloy/latest/concepts/configuration-syntax/&#34;&gt;configuration syntax&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&#34;configuration&#34;&gt;Configuration&lt;/h2&gt;
&lt;p&gt;The &lt;code&gt;hashmod&lt;/code&gt; action and the &lt;code&gt;modulus&lt;/code&gt; argument are used in conjunction to enable sampling behavior by sharding one or more labels.
To read further on these concepts, refer to 
    &lt;a href=&#34;/docs/alloy/v1.18.x/reference/components/discovery/discovery.relabel/#rule-block&#34;&gt;rule block documentation&lt;/a&gt;.
In short, &lt;code&gt;hashmod&lt;/code&gt; performs an MD5 hash on the source labels and &lt;code&gt;modulus&lt;/code&gt; performs a modulus operation on the output.&lt;/p&gt;
&lt;p&gt;The sample size can be modified by changing the value of &lt;code&gt;modulus&lt;/code&gt; in the &lt;code&gt;hashmod&lt;/code&gt; action and the &lt;code&gt;regex&lt;/code&gt; argument in the &lt;code&gt;keep&lt;/code&gt; action.
The &lt;code&gt;modulus&lt;/code&gt; value defines the number of shards, while the &lt;code&gt;regex&lt;/code&gt; value selects a subset of the shards.&lt;/p&gt;
&lt;p&gt;&lt;img
  class=&#34;lazyload d-inline-block&#34;
  data-src=&#34;../sample.svg&#34;
  alt=&#34;Workflow for sampling scrape targets&#34;/&gt;&lt;/p&gt;


&lt;div class=&#34;admonition admonition-note&#34;&gt;&lt;blockquote&gt;&lt;p class=&#34;title text-uppercase&#34;&gt;Note&lt;/p&gt;&lt;p&gt;Choose your source label(s) for the &lt;code&gt;hashmod&lt;/code&gt; action carefully. They must uniquely define each scrape target or &lt;code&gt;hashmod&lt;/code&gt; won&amp;rsquo;t be able to shard the targets uniformly.&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;

&lt;p&gt;For example, consider an application deployed on Kubernetes with 100 pod replicas, all uniquely identified by the label &lt;code&gt;pod_hash&lt;/code&gt;.
The following configuration is set to sample 15% of the pods:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;Alloy&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-alloy&#34;&gt;discovery.kubernetes &amp;#34;profile_pods&amp;#34; {
  role = &amp;#34;pod&amp;#34;
}

discovery.relabel &amp;#34;profile_pods&amp;#34; {
  targets = concat(discovery.kubernetes.profile_pods.targets)

  // Other rule blocks ...

  rule {
    action        = &amp;#34;hashmod&amp;#34;
    source_labels = [&amp;#34;pod_hash&amp;#34;]
    modulus       = 100
    target_label  = &amp;#34;__tmp_hashmod&amp;#34;
  }

  rule {
    action        = &amp;#34;keep&amp;#34;
    source_labels = [&amp;#34;__tmp_hashmod&amp;#34;]
    regex         = &amp;#34;^([0-9]|1[0-4])$&amp;#34;
  }

  // Other rule blocks ...
}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h2 id=&#34;considerations&#34;&gt;Considerations&lt;/h2&gt;
&lt;p&gt;This strategy doesn&amp;rsquo;t guarantee precise sampling.
Due to its reliance on an MD5 hash, there isn&amp;rsquo;t a perfectly uniform distribution of scrape targets into shards.
Larger numbers of scrape targets yield increasingly accurate sampling.&lt;/p&gt;
&lt;p&gt;Keep in mind, if the label hashed is deterministic, you see deterministic sharding and thereby deterministic sampling of scrape targets.
Similarly, if the label hashed is non-deterministic, you see scrape targets sampled in a non-deterministic fashion.&lt;/p&gt;
]]></content><description>&lt;h1 id="sampling-scrape-targets">Sampling scrape targets&lt;/h1>
&lt;p>Applications often have many instances deployed.
While Pyroscope is designed to handle large amounts of profiling data, you may want only a subset of the application&amp;rsquo;s instances to be scraped.&lt;/p></description></item></channel></rss>