Java-style Microservices

Application Performance Management (APM)

It refers to the monitoring and optimization of key business applications of the enterprise, improving the reliability and quality of enterprise applications, ensuring that users receive good services, reducing the total IT operation and maintenance costs, and bringing more business benefits to the enterprise .

Pinpoint Introduction

Pinpoint is an APM (Application Performance Management) tool suitable for large distributed systems written in Java/PHP. Try to be simple and efficient in use. By installing the agent at startup, there is no need to modify even one line of code to minimize performance loss (3%).

  • Advantage:

    1. Distributed transaction tracking, tracking messages across distributed applications;
    2. Automatically detect application topology to help you figure out application architecture;
    3. Horizontal expansion to support large-scale server clusters;
    4. Provide code-level visibility to easily locate failure points and bottlenecks;
    5. Use bytecode enhancement technology to add new functions without modifying the code.
  • Main components

ComponentsComponent Functions
Pinpoint-CollectorCollect various performance data
Pinpoint-AgentThe probe is associated with an application server (such as tomcat) and deployed on the same server
HBase StorageStore the collected data in HBase
Pinpoint-WebThe collected data layer is now displayed on the web

2. Quickly Deploy Pinpoint on Kato

One-click installation based on Kato application market.

This deployment method minimizes the difficulty and workload of deployment for complex applications with multiple components like pinpoint.

Enter pinpoint’s UI interface through pinpoint-web application

In the default settings, the pinpoint application has monitored its own collector and web components. After entering the UI interface, you can find that the two already exist in the application list

3. Add Monitored Objects

Insert agent during war startup

  1. Put pinpoint-agent resources into the mirror in advance;
  2. Insert the startup key code:
#pinpoint-agent.sh
#Specify pinpoint-agent resources
CATALINA_OPTS="$CATALINA_OPTS -javaagent:$PINPOINT_AGENT_PATH/pinpoint-bootstrap-${PINPOINT_AGETN_VERSION}-SNAPSHOT.jar" 
#Specify pinpoint-agent ID
CATALINA_OPTS="$CATALINA_OPTS -Dpinpoint.agentId=${AGENT_ID}" 
#Specify the application name
CATALINA_OPTS="$CATALINA_OPTS -Dpinpoint.applicationName=${APP_NAME}" 
#docker-entrypoint.sh  
#Judge whether to open pinpoint-agent
if [ "$ENABLE_APM" == "true" ];then 
#collectorAddress
 COLLECTOR_TCP_HOST=${COLLECTOR_TCP_HOST:-127.0.0.1} 
#TCP port 
 COLLECTOR_TCP_PORT=${COLLECTOR_TCP_PORT:-9994} 
 COLLECTOR_UDP_SPAN_LISTEN_HOST=${COLLECTOR_UDP_SPAN_LISTEN_HOST:-127.0.0.1}
 COLLECTOR_UDP_SPAN_LISTEN_PORT=$
#UDP port
{COLLECTOR_UDP_SPAN_LISTEN_PORT:-9996} 
 COLLECTOR_UDP_STAT_LISTEN_HOST=${COLLECTOR_UDP_STAT_LISTEN_HOST:-127.0.0.1}
 COLLECTOR_UDP_STAT_LISTEN_PORT=$
#UDP port
 {COLLECTOR_UDP_STAT_LISTEN_PORT:-9995} 
#Load agent at startup
 sed -i "2 a. /usr/local/tomcat/bin/pinpoint-agent.sh" /usr/local/tomcat/bin/catalina.sh 
#Import to pinpoint-agent configuration file
  sed -i -r -e "s/(profiler.collector.ip)=.*/\1=${COLLECTOR_TCP_HOST}/" \ 
 -e "s/(profiler.collector.tcp.port)=.*/\1=${COLLECTOR_TCP_PORT}/" \
 -e "s/(profiler.collector.span.port)=.*/\1=${COLLECTOR_UDP_SPAN_LISTEN_PORT}/" \
 -e "s/(profiler.collector.stat.port)=.*/\1=${COLLECTOR_UDP_STAT_LISTEN_PORT}/" /usr/local/pinpoint-agent/pinpoint.config
#Default value, every application on the platform will be generated
export APP_NAME=${APP_NAME:-${SERVICE_NAME:-${HOSTNAME}}}
#Distinguish the Agent-ID of each instance under a service through APP_NAME and POD_IP
export AGENT_ID=${APP_NAME}-${POD_IP} 
be

Insert the agent during jar startup

  1. Put the pinpoint-agent resource into the source code repository in advance;

  2. Start script content:

#!/bin/bash
#Judging whether to start pinpoint agent through specific environment variables
if [[ $ENABLE_APM == "true" ]];then 
 AGENT_ID=${SERVICE_ID:0:10}
 PINPOINT_AGETN_VERSION=1.7.2
 PINPOINT_AGENT_PATH=/app/pinpoint
#Add pinpoint agent startup parameters to $JAVA_OPTS 
export JAVA_OPTS="$JAVA_OPTS -javaagent:$ 
{PINPOINT_AGENT_PATH}/pinpoint-bootstrap-${PINPOINT_AGETN_VERSION}-
SNAPSHOT.jar -Dpinpoint.agentId=${AGENT_ID:-${SERVICE_ID:0:10}} -Dpinpoint.applicationName=${APP_NAME:-${SERVICE_NAME:-
$HOSTNAME}}"
be
PORT = $ {PORT: -5000}
sleep ${PAUSE:-0}
#Final start command
exec java -Dserver.port=$PORT $JAVA_OPTS -jar target/*.jar

Pinpoint under the traditional architecture needs to attach an Agent to the monitored object and make it effective by modifying the configuration file. On the cloud help platform, we have simplified these two steps accordingly.

The cloud help platform uses the method of setting environment variables instead of configuration files. Environment variables in the form of key-value pairs are very simple and easy to use.

Add Pinpoint Monitoring Object Practice

Method One

Let’s take todoapi as an example to introduce the method of adding monitored objects

  1. Connect with Pinpoint-Collector
  1. Click Dependency on the todoapi application interface to view the connection information with pinpoint-collector**
  1. Visit Pinpoint-Web to view:

For deployed applications, you can also configure the corresponding service dependencies and environment variables through the Dependency and Settings tabs in the application management interface.

Method Two

  1. After enabling Pinpoint-Collector external services, the platform gateway will define a layer of port mapping relationships
  1. View the todoshow variable value, check whether the port number is correct, and activate the agent switch
  1. Visit Pinpoint-Web to view, todoshow has appeared on the interface

The real-time push in Pinpoint-Web uses the Websocket protocol, but we use the http protocol when accessing the Pinpoint-Web application; therefore, the push cannot be received in real time, so you need to application gateway –> in the platform, find Pinpoint-Web application in Access Control, click Parameter Configuration to open Websocket protocol support.