-
Notifications
You must be signed in to change notification settings - Fork 31
Monitoring Web Server API
This API was implemented using Spring Boot and provides a simple way to monitor the health and status of a web server.
Endpoints The API includes the following endpoints: GET /health This endpoint returns a JSON response indicating the health of the server. The response has the following format:
{
"status": "DOWN",
"reportsArchiver": {
"status": "UP"
},
"ESController": {
"status": "UP"
},
"diskSpace": {
"status": "UP",
"total": 1023551787008,
"free": 569404145664,
"threshold": 10485760
},
"db": {
"status": "UP",
"database": "H2",
"hello": 1
},
"elasticsearch": {
"status": "DOWN",
"error": "io.searchbox.client.config.exception.CouldNotConnectException: Could not connect to http://localhost:9200"
}
}Where "status" is either "UP" or "DOWN", indicating the health of the server.
GET /metrics
This endpoint returns a JSON response indicating different hardware and softeare metrics. The response has the following format:
{
"mem": 651066,
"mem.free": 418117,
"processors": 8,
"instance.uptime": 1040643,
"uptime": 1070569,
"systemload.average": -1,
"heap.committed": 546816,
"heap.init": 262144,
"heap.used": 128698,
"heap": 932352,
"nonheap.committed": 105920,
"nonheap.init": 2496,
"nonheap.used": 104252,
"nonheap": 0,
"threads.peak": 25,
"threads.daemon": 22,
"threads.totalStarted": 30,
"threads": 25,
"classes": 12985,
"classes.loaded": 12985,
"classes.unloaded": 0,
"gc.ps_scavenge.count": 20,
"gc.ps_scavenge.time": 295,
"gc.ps_marksweep.count": 3,
"gc.ps_marksweep.time": 589,
"httpsessions.max": -1,
"httpsessions.active": 0,
"datasource.primary.active": 0,
"datasource.primary.usage": 0,
"gauge.response.health": 5191,
"gauge.response.api.settings": 10,
"gauge.response.api.reports": 49,
"gauge.response.star-star": 5,
"gauge.response.star-star.favicon.ico": 34,
"counter.status.200.star-star.favicon.ico": 1,
"counter.status.200.api.reports": 10,
"counter.status.200.star-star": 20,
"counter.status.404.star-star": 2,
"counter.status.503.health": 1,
"counter.status.200.api.settings": 2
}GET /env
This endpoint returns a JSON response indicating the environment properties. The response has the following format:
{
"profiles": [],
"server.ports": {
"local.server.port": 8090
},
"servletContextInitParams": {},
"systemProperties": {
"java.runtime.name": "Java(TM) SE Runtime Environment",
"logging.level.org.springframework.web": "ERROR",
"java.protocol.handler.pkgs": "org.springframework.boot.loader",
"sun.boot.library.path": "c:\\Program Files\\Java\\jdk1.8.0_301\\jre\\bin",
"java.vm.version": "25.301-b09",
"user.country.format": "IL",
"java.vm.vendor": "Oracle Corporation",
"java.vendor.url": "http://java.oracle.com/",
"path.separator": ";",
"java.vm.name": "Java HotSpot(TM) 64-Bit Server VM",
"file.encoding.pkg": "sun.io",
"user.country": "US",
"user.script": "",
"sun.java.launcher": "SUN_STANDARD",
"sun.os.patch.level": "",
"PID": "14996",
"server.port": "8090",
"java.vm.specification.name": "Java Virtual Machine Specification",
"user.dir": "C:\\Users\\itaiag\\auto\\difido-server",
"java.runtime.version": "1.8.0_301-b09",
"java.awt.graphicsenv": "sun.awt.Win32GraphicsEnvironment",
"org.jboss.logging.provider": "slf4j",
"java.endorsed.dirs": "c:\\Program Files\\Java\\jdk1.8.0_301\\jre\\lib\\endorsed",
"os.arch": "amd64"
}
}GET /logfile
This endpoint returns a TEXT response with the log file. The response has the following format:
2022-07-12 16:11:10.313 INFO 28528 --- [main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@6d21714c: startup date [Tue Jul 12 16:11:10 IDT 2022]; root of context hierarchy
2022-07-12 16:11:11.199 INFO 28528 --- [main] o.s.core.annotation.AnnotationUtils : Failed to introspect annotations on [class org.springframework.boot.actuate.autoconfigure.EndpointWebMvcHypermediaManagementContextConfiguration]: java.lang.ArrayStoreException: sun.reflect.annotation.TypeNotPresentExceptionProxy
2022-07-12 16:11:11.200 INFO 28528 --- [main] o.s.core.annotation.AnnotationUtils : Failed to introspect annotations on [class org.springframework.boot.actuate.autoconfigure.EndpointWebMvcHypermediaManagementContextConfiguration]: java.lang.ArrayStoreException: sun.reflect.annotation.TypeNotPresentExceptionProxy
2022-07-12 16:11:11.605 INFO 28528 --- [main] o.s.b.f.s.DefaultListableBeanFactory : Overriding bean definition for bean 'requestContextFilter' with a different definition: replacing [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=org.springframework.boot.autoconfigure.jersey.JerseyAutoConfiguration; factoryMethodName=requestContextFilter; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [org/springframework/boot/autoconfigure/jersey/JerseyAutoConfiguration.class]] with [Root bean: class [org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration$WebMvcAutoConfigurationAdapter]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=requestContextFilter; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [org/springframework/boot/autoconfigure/web/WebMvcAutoConfiguration$WebMvcAutoConfigurationAdapter.class]]
Usage To use the API, make a request to the appropriate endpoint using a tool such as curl, HTTPie, or a browser. For example:
curl http://localhost:8080/health
curl http://localhost:8080/status
Conclusion This API provides a simple way to monitor the health and status of a web server implemented using Spring Boot. With its two endpoints, you can easily determine the health and status of the server at any time.
The Difido project is maintained by Top-Q and friends
- Overview
- Binders
- The Difido Server
- Developers
- Building the Server
- High Level Architecture
- Server API
- H2 Server
- Developing Plugins
- Elastic Mapping Definitions
- Contributing Code