Pyroscope

Pyroscope is an open source platform, consisting of server and agent. It allows the user to collect, store, and query the profiling data in a CPU and disk efficient way. This addon is built based Pyroscope

  1. vela addon enable pyroscope

After enable pyroscope successfully, you can execute command to expose the port 4040 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. // optionally, if authentication is enabled, specify the API key:
  11. // AuthToken: os.Getenv("PYROSCOPE_AUTH_TOKEN"),
  12. // by default all profilers are enabled, but you can select the ones you want to use:
  13. ProfileTypes: []pyroscope.ProfileType{
  14. pyroscope.ProfileCPU,
  15. pyroscope.ProfileAllocObjects,
  16. pyroscope.ProfileAllocSpace,
  17. pyroscope.ProfileInuseObjects,
  18. pyroscope.ProfileInuseSpace,
  19. },
  20. })
  21. // your code goes here
  22. }
  • Check out the examples directory in our repository to learn more

  • Java integration is distributed as a single jar file: pyroscope.jar. It contains native async-profiler libraries

  • To start profiling a Java application, run your application with pyroscope.jar javaagent:
  1. export PYROSCOPE_APPLICATION_NAME=my.java.app
  2. export PYROSCOPE_SERVER_ADDRESS=http://pyroscope-server:4040
  3. # Optionally, if authentication is enabled, specify the API key.
  4. # export PYROSCOPE_AUTH_TOKEN={YOUR_API_KEY}
  5. java -javaagent:pyroscope.jar -jar app.jar
  • Check out the examples 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_SERVER_ADDRESS: http://pyroscope-server:4040
  15. PYROSCOPE_LOG_LEVEL: debug
  16. ASPNETCORE_URLS: http://*:5000
  17. ports:
  18. - "5000:5000"
  19. cap_add:
  20. - 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. )
  • Check out the example python project in pyroscope repository for examples of how you can use these features.

  • 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:

  1. FROM php:7.3.27
  2. WORKDIR /var/www/html
  3. # this copies pyroscope binary from pyroscope image to your image:
  4. COPY --from=pyroscope/pyroscope:latest /usr/bin/pyroscope /usr/bin/pyroscope
  5. COPY main.php ./main.php
  6. # optionally you may set the pyroscope server address as well as the app name, make sure you change these:
  7. ENV PYROSCOPE_APPLICATION_NAME=my.php.app
  8. ENV PYROSCOPE_SERVER_ADDRESS=http://pyroscope:4040/
  9. # this starts your app with pyroscope profiler, make sure to change "php" and "main.php" to the actual command.
  10. CMD ["pyroscope", "exec", "php", "main.php"]
  • 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 examples 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
  1. vela addon disable pyroscope

Last updated on Feb 9, 2023 by dependabot[bot]