Pyroscope

    After enable pyroscope successfully, you can execute command to expose the port for Dashboard UI.

    1. vela port-forward addon-pyroscope -n vela-system

    Use a component typed webservice to start, keep the following to pyroscope-demo.yaml, then vela up -f app-demo.yaml

    1. apiVersion: core.oam.dev/v1beta1
    2. kind: Application
    3. metadata:
    4. name: pyroscope-app
    5. namespace: fourier
    6. spec:
    7. components:
    8. - name: pyroscope-comp-01
    9. type: webservice
    10. properties:
    11. image: nginx:latest
    12. ports:
    13. - expose: true
    14. port: 80
    15. protocol: TCP
    16. imagePullPolicy: IfNotPresent
    17. traits:
    18. - type: pyroscope
    19. properties:
    20. server: "http://pyroscope-server:9084"
    21. logger: "pyroscope.StandardLogger"
    22. appName: "pyroscope-test"
    23. - type: scaler
    24. properties:
    25. replicas: 1

    And the parameter appName is a optional field, default value is the component name.

    • To start profiling a Go application, you need to include our go module in your app
    1. # make sure you also upgrade pyroscope server to version 0.3.1 or higher
    2. go get github.com/pyroscope-io/client/pyroscope
    • Then add the following code to your application:
    1. package main
    2. import "github.com/pyroscope-io/client/pyroscope"
    3. func main() {
    4. pyroscope.Start(pyroscope.Config{
    5. ApplicationName: "simple.golang.app",
    6. // replace this with the address of pyroscope server
    7. ServerAddress: "http://pyroscope-server:4040",
    8. // you can disable logging by setting this to nil
    9. Logger: pyroscope.StandardLogger,
    10. // AuthToken: os.Getenv("PYROSCOPE_AUTH_TOKEN"),
    11. // by default all profilers are enabled, but you can select the ones you want to use:
    12. ProfileTypes: []pyroscope.ProfileType{
    13. pyroscope.ProfileAllocObjects,
    14. pyroscope.ProfileAllocSpace,
    15. pyroscope.ProfileInuseObjects,
    16. pyroscope.ProfileInuseSpace,
    17. },
    18. })
    19. // your code goes here
    20. }
    • Check out the examples directory in our repository to learn more

    • To start profiling a Java application, run your application with pyroscope.jar javaagent:
    • Check out the folder in our repository to learn more

    • To start profiling a .NET application inside a container, you may wrap your application with pyroscope exec as an entrypoint of your image. The tricky part is that you need to copy pyroscope binary to your docker container. To do that, use COPY —from command in your Dockerfile. The following example Dockerfile shows how to build the image:

    1. FROM mcr.microsoft.com/dotnet/sdk:5.0
    2. WORKDIR /dotnet
    3. COPY --from=pyroscope/pyroscope:latest /usr/bin/pyroscope /usr/bin/pyroscope
    4. ADD my-app .
    5. RUN dotnet publish -o . -r $(dotnet --info | grep RID | cut -b 6- | tr -d ' ')
    6. # optionally you may set the pyroscope server address as well as the app name and other configuration options.
    7. ENV PYROSCOPE_SERVER_ADDRESS=http://pyroscope-server:4040
    8. ENV PYROSCOPE_APPLICATION_NAME=my.dotnet.app
    9. ENV PYROSCOPE_LOG_LEVEL=debug
    10. CMD ["pyroscope", "exec", "dotnet", "/dotnet/my-app.dll"]
    • If you are using Docker Compose, you can run both pyroscope server and agent with this configuration:
    1. ---
    2. version: "3.9"
    3. services:
    4. pyroscope-server:
    5. image: "pyroscope/pyroscope:latest"
    6. ports:
    7. - "4040:4040"
    8. command:
    9. - "server"
    10. app:
    11. image: "my-app:latest"
    12. environment:
    13. PYROSCOPE_APPLICATION_NAME: my.dotnet.app
    14. PYROSCOPE_LOG_LEVEL: debug
    15. ASPNETCORE_URLS: http://*:5000
    16. ports:
    17. - "5000:5000"
    18. - SYS_PTRACE
    • Check out the examples folder in our repository to learn more

    • First, install pyroscope-io pip package:

    1. pip install pyroscope-io
    • Add the following code to your application. This code will initialize pyroscope profiler and start profiling:
    1. import pyroscope
    2. pyroscope.configure(
    3. app_name = "my.python.app", # replace this with some name for your application
    4. server_address = "http://my-pyroscope-server:4040", # replace this with the address of your pyroscope server
    5. # auth_token = "{YOUR_API_KEY}", # optionally, if authentication is enabled, specify the API key
    6. )
    • To start profiling a PHP application in a container, you may wrap your application with pyroscope exec as an entrypoint of your image. The tricky part is that you need to copy pyroscope binary to your docker container. To do that, use COPY —from command in your Dockerfile. The following example Dockerfile shows how to build the image:

    • If you are using Docker Compose, you can run both pyroscope server and agent with this configuration:
    1. ---
    2. services:
    3. pyroscope-server:
    4. image: "pyroscope/pyroscope:latest"
    5. ports:
    6. - "4040:4040"
    7. command:
    8. - "server"
    9. app:
    10. image: "my-app:latest"
    11. env:
    12. PYROSCOPE_SERVER_ADDRESS: http://pyroscope-server:4040
    13. PYROSCOPE_APPLICATION_NAME: my.php.app
    14. cap_add:
    15. - SYS_PTRACE
    • Check out the folder in our repository to learn more

    • To start profiling a NodeJS application, you need to include the npm module in your app:

    1. npm install @pyroscope/nodejs
    2. # or
    3. yarn add @pyroscope/nodejs
    • Then add the following code to your application:
    1. const Pyroscope = require('@pyroscope/nodejs');
    2. Pyroscope.init({
    3. serverAddress: 'http://pyroscope:4040',
    4. appName: 'myNodeService'
    5. });
    6. Pyroscope.start()
    • Check out the examples directory in our repository to learn more