Observability

Compile source code

Download Apache ShardingSphere from GitHub,Then compile.

  1. git clone --depth 1 https://github.com/apache/shardingsphere.git
  2. cd shardingsphere
  3. mvn clean install -Dmaven.javadoc.skip=true -Dcheckstyle.skip=true -Drat.skip=true -Djacoco.skip=true -DskipITs -DskipTests -Prelease

Output directory: shardingsphere-agent/shardingsphere-agent-distribution/target/apache-shardingsphere-${latest.release.version}-shardingsphere-agent-bin.tar.gz

Agent configuration

  • Directory structure

    Create agent directory, and unzip agent distribution package to the directory.

  1. mkdir agent
  2. tar -zxvf apache-shardingsphere-${latest.release.version}-shardingsphere-agent-bin.tar.gz -C agent
  3. cd agent
  4. tree
  5. .
  6. └── apache-shardingsphere-${latest.release.version}-shardingsphere-agent-bin
  7. ├── LICENSE
  8. ├── NOTICE
  9. ├── conf
  10. ├── agent.yaml
  11. └── logback.xml
  12. ├── plugins
  13. ├── shardingsphere-agent-logging-base-${latest.release.version}.jar
  14. ├── shardingsphere-agent-metrics-prometheus-${latest.release.version}.jar
  15. ├── shardingsphere-agent-tracing-jaeger-${latest.release.version}.jar
  16. ├── shardingsphere-agent-tracing-opentelemetry-${latest.release.version}.jar
  17. ├── shardingsphere-agent-tracing-opentracing-${latest.release.version}.jar
  18. └── shardingsphere-agent-tracing-zipkin-${latest.release.version}.jar
  19. └── shardingsphere-agent.jar
  • Configuration file

conf/agent.yaml is used to manage agent configuration. Built-in plugins include Jaeger, OpenTracing, Zipkin, OpenTelemetry, BaseLogging and Prometheus. No plugin is enabled by default.

  1. plugins:
  2. # logging:
  3. # BaseLogging:
  4. # props:
  5. # level: "INFO"
  6. # metrics:
  7. # Prometheus:
  8. # host: "localhost"
  9. # port: 9090
  10. # props:
  11. # jvm-information-collector-enabled: "true"
  12. # tracing:
  13. # Jaeger:
  14. # host: "localhost"
  15. # port: 5775
  16. # props:
  17. # service-name: "shardingsphere"
  18. # jaeger-sampler-type: "const"
  19. # jaeger-sampler-param: "1"
  20. # Zipkin:
  21. # host: "localhost"
  22. # port: 9411
  23. # props:
  24. # service-name: "shardingsphere"
  25. # url-version: "/api/v2/spans"
  26. # sampler-type: "const"
  27. # sampler-param: "1"
  28. # OpenTracing:
  29. # props:
  30. # opentracing-tracer-class-name: "org.apache.skywalking.apm.toolkit.opentracing.SkywalkingTracer"
  31. # OpenTelemetry:
  32. # props:
  33. # otel-resource-attributes: "service.name=shardingsphere"
  34. # otel-traces-exporter: "zipkin"
  • Parameter description:
NameDescriptionValue rangeDefault value
jvm-information-collector-enabledStart JVM collectortrue, falsetrue
service-nameTracking service nameCustomshardingsphere-agent
jaeger-sampler-typeJaeger sample rate typeconst, probabilistic, ratelimiting, remoteconst
jaeger-sampler-paramJaeger sample rate parameterconst:0, 1, probabilistic:0.0 - 1.0, ratelimiting: > 0, Customize the number of acquisitions per second, remote:need to customize the remote service addres,JAEGER_SAMPLER_MANAGER_HOST_PORT1 (const type)
url-versionZipkin url addressCustom/api/v2/spans
sampler-typeZipkin sample rate typeconst, counting, ratelimiting, boundaryconst
sampler-paramZipkin sampling rate parameterconst:0, 1, counting:0.01 - 1.0, ratelimiting: > 0, boundary:0.0001 - 1.01 (const type)
otel-resource-attributesopentelemetry propertiesString key value pair (, split)service.name=shardingsphere-agent
otel-traces-exporterTracing expoterzipkin, jaegerzipkin
otel-traces-samplerOpentelemetry sample rate typealways_on, always_off, traceidratioalways_on
otel-traces-sampler-argOpentelemetry sample rate parametertraceidratio:0.0 - 1.01.0

Usage in ShardingSphere-Proxy

Using via a non-container environment

  • Edit the startup script

Configure the absolute path of shardingsphere-agent.jar to the start.sh startup script of shardingsphere proxy.

  1. nohup java ${JAVA_OPTS} ${JAVA_MEM_OPTS} \
  2. -javaagent:/xxxxx/agent/shardingsphere-agent.jar \
  3. -classpath ${CLASS_PATH} ${MAIN_CLASS} >> ${STDOUT_FILE} 2>&1 &
  • Start ShardingSphere-Proxy
  1. bin/start.sh

After startup, you can find the plugin info in the log of ShardingSphere-Proxy, Metric and Tracing data can be viewed through the configured monitoring address.

Use via container environment

  • Assume that the following corresponding configurations have been completed locally.

    • Folder ./custom/agent/ that contains all files after unpacking ShardingSphere-Agent binary package
    • The folder containing the configuration files of ShardingSphere-Proxy such as server.yaml is ./custom/conf/
  • At this point, the use of ShardingSphere-Agent can be configured through the environment variable JVM_OPT. Taking starting in the Docker Compose environment as an example, a reasonable docker-compose.yml example is as follows.
  1. version: "3.8"
  2. services:
  3. apache-shardingsphere-proxy:
  4. image: apache/shardingsphere-proxy:latest
  5. environment:
  6. JVM_OPTS: "-javaagent:/agent/shardingsphere-agent.jar"
  7. PORT: 3308
  8. volumes:
  9. - ./custom/agent:/agent/
  10. - ./custom/conf:/opt/shardingsphere-proxy/conf/
  11. ports:
  12. - "13308:3308"

Metrics

nametypedescription
proxy_request_totalCOUNTERproxy request total
proxy_connection_totalGAUGEproxy connection total
proxy_execute_latency_millisHISTOGRAMproxy executor latency millis
proxy_execute_error_totalCOUNTERproxy executor error total
route_sql_select_totalCOUNTERproxy executor route select sql total
route_sql_insert_totalCOUNTERproxy executor route insert sql total
route_sql_update_totalCOUNTERproxy executor route update sql total
route_sql_delete_totalCOUNTERproxy executor route delete sql total
route_datasource_totalCOUNTERnumber of datasource routed
route_table_totalCOUNTERnumber of table routed
proxy_transaction_commit_totalCOUNTERtransaction commit count total
proxy_transaction_rollback_totalCOUNTERtransaction rollback count total
parse_sql_dml_insert_totalCOUNTERproxy executor parse insert sql total
parse_sql_dml_delete_totalCOUNTERproxy executor parse delete sql total
parse_sql_dml_update_totalCOUNTERproxy executor parse update sql total
parse_sql_dml_select_totalCOUNTERproxy executor parse select sql total
parse_sql_ddl_totalCOUNTERproxy executor parse ddl sql total
parse_sql_dcl_totalCOUNTERproxy executor parse dcl sql total
parse_sql_dal_totalCOUNTERproxy executor parse dal sql total
parse_sql_tcl_totalCOUNTERproxy executor parse tcl sql total
parse_dist_sql_rql_totalCOUNTERproxy executor parse rql sql total
parse_dist_sql_rdl_totalCOUNTERproxy executor parse rdl sql total
parse_dist_sql_ral_totalCOUNTERproxy executor parse ral sql total
build_infoGAUGEbuild information
proxy_infoGAUGEproxy information, state:1 OK, state:2 CIRCUIT BREAK
meta_data_infoGAUGEmeta data information, schema_count:logic number of databases, database_count:actual number of databases