SOFALookout Documentation
repository·master·Indexed 18 days ago
https://github.com/sofastack/sofa-lookoutA multi-dimensional metrics monitoring system based on the Metrics2.0 standard. It consists of a Java SDK for application-level metric collection and a server-side infrastructure for processing, storing, and visualizing metrics via Grafana and Elasticsearch. The system supports various metric types (Counter, Timer, DistributionSummary, Gauge, MixinMetric, TopGauger) and provides registry modules for Prometheus, Dropwizard, and Spring Boot Actuator integration.
What's inside SOFALookout
- SOFALookout Client is a Java development library that provides multi-dimensional metrics measurement services for your engineering projects. Unlike traditional hierarchical metrics, it follows the metrics 2.0 standard, allowing for more granular and multi-dimensional data collection.
Overview of SOFALookout
masterSOFALookout is a multi-dimensional metrics monitoring and measurement project. It utilizes the Metrics2.0 standard to provide rich monitoring dimensions via tags.
The project is divided into two main components:
- Client: A Java library that can be embedded into your application code to collect metrics.
- Server: Handles the collection, processing, storage, and querying of metrics data. It integrates with Grafana for data visualization and uses databases like Elasticsearch (ES) for storage.
Key advantages include:
- Multi-dimensional metrics: Adds a set of tags to traditional metric names, providing richer analysis than standard Spring Boot Actuator or Dropwizard.
- Lightweight: Metrics-based monitoring is more resource-efficient and predictable than log-based monitoring.
- Broad Support: Supports both the native Java SDK client and industry-standard collection agents (e.g., Metricbeat).
- Flexible Discovery: Data sources can be located via configuration files or service discovery mechanisms.
Overview of Lookout Client
masterLookout client is a Java library designed to expose project metrics. Unlike traditional hierarchical metrics systems, Lookout provides multi-dimensional metrics via its API, adhering to the metrics2.0 standard. It is compatible with Java 6 and above.Understand configuration priority and isolation in all-in-one-bootstrap
masterBecause multiple Spring Boot applications run within the same
sofa-arkenvironment, configuration isolation is handled via prefixes. To prevent conflicts (e.g., two apps trying to bind to the sameserver.port), configuration keys must be prefixed with the application name.Configuration Priority
For a
sofa-ark-bizapplication, the priority (from highest to lowest) is:- [New] Prefixed System Properties (e.g.,
-Dlookoutgateway.foo=bar) - [New] Prefixed Environment Variables (e.g.,
lookoutgateway.foo=bar) - System Properties (Standard Spring Boot)
- Environment Variables (Standard Spring Boot)
- [New] Files in
app-configs/<appName>(High priority files provided in the project resources) - Original Classpath Configuration Files (Standard Spring Boot)
How to pass application-specific configuration
Using
lookoutgatewayas an example, you can pass configuration in these ways (ordered by priority):- System Property:
-Dlookoutgateway.foo=bar(Affects onlylookoutgateway) - Environment Variable:
lookoutgateway.foo=bar(Affects onlylookoutgateway) - External Properties File: Set
-Dlookoutall.config-file=abc.properties. Inside this file, any key starting withlookoutgateway.will apply to that app. - Standard System Properties: (e.g.,
-Dserver.port=8080- note this may conflict if not prefixed) - Standard Environment Variables
- Additional Location:
-Dlookoutgateway.config-additional-location=<dir>(Points to a directory that Spring Boot will parse forlookoutgateway) - Classpath: The
application.propertiesinside thelookoutgatewayclasspath.
- [New] Prefixed System Properties (e.g.,
Extend SOFALookout using SPI
masterThe client provides an SPI (Service Provider Interface) mechanism to allow developers to extend public metrics collection modules. To implement a custom metrics collector, you must implement the
com.alipay.lookout.spi.MetricsImporterinterface.Default extensions provided by the project include:
lookout-ext-jvm: JVM metricslookout-ext-os: OS metrics
Configure metric priority and tags
masterPriority Tags
Priority levels determine the data collection interval. Higher priority metrics are collected more frequently. The default level is
NORMAL.LookoutConstants.HIGH_PRIORITY_TAGLookoutConstants.NORMAL_PRIORITY_TAG(Default)LookoutConstants.LOW_PRIORITY_TAG
Example:
id.withTag(LookoutConstants.LOW_PRIORITY_TAG);Tag Best Practices
- Common Tags: Use tags for machine IP, cluster name, or datacenter name. You can customize common tags via the
com.alipay.lookout.client.LookoutClientinterface. Always include the application name tag (e.g.,tag:app=xx). - Naming: Tag keys must be lowercase. Use letters, numbers, and underscores.
- Optimization: Keep the number of tags as small as possible and ensure tag values are enumerable.
Ways to use Lookout Client
masterDepending on your project requirements, you can integrate Lookout in three ways:
- Standalone Metric Collection: Use
lookout-apito manually collect and manage metrics within any Java project. - Prometheus Integration: Add the
lookout-reg-prometheusdependency. This starts a nested HTTP server within your project that provides metrics query services, allowing Prometheus to scrape metrics directly. - Spring Boot Integration: Add the
lookout-sofa-boot-starterdependency to use the client within a Spring Boot application.
- Standalone Metric Collection: Use
Run SOFALookout via Docker on Linux
masterOn Linux systems, you can run the all-in-one image directly without additional network configuration, as it can access the local Elasticsearch instance via
localhost.docker run -it --name allinone lookout/allinone:1.0.0Build the all-in-one-bootstrap project
masterTo package the project, run the provided build script from the root of the bootstrap directory.
Note: You must package the project into a JAR file before running it. You cannot run the
mainmethod directly in an IDE (like IntelliJ IDEA) becausegateway-bootstrapandmetrics-server-bootstrapare in the same project. Running via IDE causes IDEA to reference source code directly, which interferes with howsofa-arkmodifies the package during runtime../boot/all-in-one-bootstrap/build.shBuild the all-in-one Docker image
masterTo build the
all-in-one-bootstrapDocker image, execute the build command from the project root directory. The build process uses the Aliyun Maven repository to improve build speeds in China.docker build -t lookout/allinone:1.0.0 .Run the all-in-one-bootstrap executable
masterBefore running, ensure an Elasticsearch instance is running (e.g., via Docker).
To run the packaged JAR, use the
java -jarcommand. You must include the system property-Dcom.alipay.sofa.ark.master.biz=lookoutallto set thesofa-arkmaster biz.Required and common flags:
-Dcom.alipay.sofa.ark.master.biz=lookoutall: Mandatory for setting the master biz.-Dlookoutall.config-file=<path>: Points to a.propertiesfile on the file system. Configuration keys in this file must be prefixed with the application name to ensure isolation.-D<appName>.<key>=<value>: Sets a configuration value specific to a sub-application.-D<appName>.config-additional-location=<dir>: Specifies a directory for additional configuration files specific to that sub-application.
# 1. Start Elasticsearch docker run -d --name es -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" elasticsearch:5.6 # 2. Run the JAR java -Dcom.alipay.sofa.ark.master.biz=lookoutall \ -Dlookoutgateway.config-additional-location=config-dir-for-lookoutgateway \ -Dlookkoutserver.config-additional-location=config-dir-for-lookoutserver \ -Dlookoutall.config-file=abc.properties \ -Dlookoutgateway.foo=bar \ -Dlookoutserver.bar=baz \ -jar allinone-executable.jarImport the Lookout API dependency
masterTo use the Lookout API in your Java project, add the following dependency to your
pom.xml. Ensure you define the${lookout.version}property with the appropriate version.<dependency> <groupId>com.alipay.lookout</groupId> <artifactId>lookout-api</artifactId> <version>${lookout.version}</version> </dependency>