Backend Development 7 min read

How to Set Up SkyWalking APM with Spring Boot and Elasticsearch for Real‑Time Monitoring

This step‑by‑step guide shows how to download, configure, and launch SkyWalking with Spring Boot, connect it to Elasticsearch, instrument a sample service and Redis calls, and view real‑time monitoring data through the SkyWalking UI and Kibana.

Spring Full-Stack Practical Cases
Spring Full-Stack Practical Cases
Spring Full-Stack Practical Cases
How to Set Up SkyWalking APM with Spring Boot and Elasticsearch for Real‑Time Monitoring

Download SkyWalking

Environment: spring boot 2.4.12 + SkyWalking‑apm‑es7‑8.5.0 + ES7.8.0

Directory description after extraction:

bin directory contains startup scripts such as oapService.bat, webappService.bat, startup.bat.

config holds the OAP service configuration, including an application.yml file.

agent is the SkyWalking agent used to collect business system logs.

webapp directory provides the UI service configuration for SkyWalking.

Elasticsearch configuration

Refer to the "Springboot integration ELK log collection detailed steps" article for ES setup. Modify elasticsearch.yml to set the cluster name:

<code>cluster.name: myes</code>

Start SkyWalking services

Run oapService.bat and webappService.bat separately, or use startup.bat to start both.

The OAP service collects monitoring data from SkyWalking agents; by default it stores data in H2 (an in‑memory database), but Elasticsearch7, MySQL, etc., can be used. Configure persistence in %SKYWALKING_HOME%\config\application.yml :

<code>storage:
  selector: ${SW_STORAGE:elasticsearch7}
  elasticsearch:
    nameSpace: ${SW_NAMESPACE:"myes"}
    clusterNodes: ${SW_STORAGE_ES_CLUSTER_NODES:localhost:9200}
    protocol: ${SW_STORAGE_ES_HTTP_PROTOCOL:"http"}
    user: ${SW_ES_USER:""}
    password: ${SW_ES_PASSWORD:""}
    trustStorePath: ${SW_STORAGE_ES_SSL_JKS_PATH:""}
    trustStorePass: ${SW_STORAGE_ES_SSL_JKS_PASS:""}
    secretsManagementFile: ${SW_ES_SECRETS_MANAGEMENT_FILE:""}
    dayStep: ${SW_STORAGE_DAY_STEP:1}
    indexShardsNumber: ${SW_STORAGE_ES_INDEX_SHARDS_NUMBER:1}
    indexReplicasNumber: ${SW_STORAGE_ES_INDEX_REPLICAS_NUMBER:1}
    superDatasetDayStep: ${SW_SUPERDATASET_STORAGE_DAY_STEP:-1}
    superDatasetIndexShardsFactor: ${SW_STORAGE_ES_SUPER_DATASET_INDEX_SHARDS_FACTOR:5}
    superDatasetIndexReplicasNumber: ${SW_STORAGE_ES_SUPER_DATASET_INDEX_REPLICAS_NUMBER:0}
    bulkActions: ${SW_STORAGE_ES_BULK_ACTIONS:1000}
    flushInterval: ${SW_STORAGE_ES_FLUSH_INTERVAL:10}
    concurrentRequests: ${SW_STORAGE_ES_CONCURRENT_REQUESTS:2}
    resultWindowMaxSize: ${SW_STORAGE_ES_QUERY_MAX_WINDOW_SIZE:10000}
    metadataQueryMaxSize: ${SW_STORAGE_ES_QUERY_MAX_SIZE:5000}
    segmentQueryMaxSize: ${SW_STORAGE_ES_QUERY_SEGMENT_SIZE:200}
    profileTaskQueryMaxSize: ${SW_STORAGE_ES_QUERY_PROFILE_TASK_SIZE:200}
    oapAnalyzer: ${SW_STORAGE_ES_OAP_ANALYZER:"{\"analyzer\":{\"oap_analyzer\":{\"type\":\"stop\"}}}"}
    oapLogAnalyzer: ${SW_STORAGE_ES_OAP_LOG_ANALYZER:"{\"analyzer\":{\"oap_log_analyzer\":{\"type\":\"standard\"}}}"}
    advanced: ${SW_STORAGE_ES_ADVANCED:""}
</code>

Run startup.bat ; if no errors, two command windows will open.

Access the SkyWalking UI (image):

Initially the UI shows no data; after starting the Spring Boot project and invoking its APIs, monitoring data appears.

Spring Boot project

Sample controller:

<code>@RestController
@RequestMapping("/commons")
public class CommonController {
  @GetMapping("/index/{time}")
  public String index(@PathVariable("time") Long time) throws Exception {
    TimeUnit.MILLISECONDS.sleep(time);
    return "success";
  }
}
</code>

Start the application with the SkyWalking agent:

<code>java -javaagent:E:\all\opensource\springcloud\apache-skywalking-apm-bin-es7\agent\skywalking-agent.jar -Dskywalking.agent.service_name=sbsky -jar spring-boot-skywalking-1.0.0.jar</code>

The -javaagent option points to the agent JAR; skywalking.agent.service_name sets a unique service name, which can also be changed in %SKYWALKING_HOME%\agent\config\agent.config :

<code>agent.service_name=${SW_AGENT_NAME:xxxx}</code>

After calling the endpoints several times, refresh the SkyWalking page to see the call information (images).

View Elasticsearch data

Use Kibana to view the indices created by SkyWalking:

The relevant indices are created automatically; you can explore them via the Discover view.

Monitor other services (Redis)

SkyWalking can also monitor Redis and database calls. Example Redis endpoint:

<code>@Resource
private StringRedisTemplate stringRedisTemplate;
@GetMapping("/redis/{id}")
public Object redis(@PathVariable("id") Integer id) {
  stringRedisTemplate.opsForValue().set("users:" + id, String.valueOf(id));
  return "success";
}
</code>

Calling this endpoint reveals the Redis call chain in SkyWalking's topology and trace views (images).

The full Redis call chain is displayed, demonstrating SkyWalking's superiority over tools like Zipkin.

End of tutorial.

JavaMonitoringAPMElasticsearchRedisSpring BootSkyWalking
Spring Full-Stack Practical Cases
Written by

Spring Full-Stack Practical Cases

Full-stack Java development with Vue 2/3 front-end suite; hands-on examples and source code analysis for Spring, Spring Boot 2/3, and Spring Cloud.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.