Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/zensum/ktor-health-check
Simple, opinionated health checks Kubernetes-style health checks for ktor
https://github.com/zensum/ktor-health-check
kotlin ktor kubernetes monitoring
Last synced: 29 days ago
JSON representation
Simple, opinionated health checks Kubernetes-style health checks for ktor
- Host: GitHub
- URL: https://github.com/zensum/ktor-health-check
- Owner: zensum
- License: mit
- Created: 2017-08-17T17:25:11.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2022-04-19T09:00:46.000Z (over 2 years ago)
- Last Synced: 2023-08-21T13:21:40.982Z (over 1 year ago)
- Topics: kotlin, ktor, kubernetes, monitoring
- Language: Kotlin
- Homepage:
- Size: 126 KB
- Stars: 29
- Watchers: 12
- Forks: 4
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-ktor - ktor-health-check
- awesome-ktor - ktor-health-check
README
# ktor-health-check
[![license](https://img.shields.io/github/license/zensum/ktor-health-check.svg)]() [![](https://jitpack.io/v/zensum/ktor-health-check.svg)](https://jitpack.io/#zensum/ktor-health-check)Simple, opinionated ktor health and readiness checks made for Kubernetes.
**Installation**: https://jitpack.io/#zensum/ktor-health-check
```kotlin
import ktor_health_check.Healthfun main(args: Array) {
embeddedServer(Netty, 80) {
// Install the middleware...
install(Health)
}.start(wait = true)
}
```... and boom, the your application now exposes a /healthz and /readyz
endpoint for use with for example Kubernetes. For a simple application
this is all you configuration you will ever need. In a more
complicated application we might want to our readycheck to start
failing if the database goes down.```kotlin
fun main(args: Array) {
embeddedServer(Netty, 80) {
install(Health) {
readyCheck("database") { myDatabase.ping() }
}
}.start(wait = true)
}
```And now getting `/readyz` returns:
```
HTTP/1.1 200 OK
Content-Type: application/json; charset=UTF-8
Content-Length: 17{"database":true}
```Lets add another check
```kotlin
install(Health) {
readyCheck("database") { myDatabase.ping() }
readyCheck("redis") { redis.ping() }
}
```Now lets say someone tripped on the cord for our Redis server.
```
HTTP/1.1 500 Internal Server Error
Content-Type: application/json; charset=UTF-8
Content-Length: 31{"database":true,"redis":false}
```The database check is still returning true, but redis has turned
false. If any single check is down, as is the case here, the result of
the entire request becomes 500, indicating that the service isn't
operational.For some use-cases you may want to expose checks on URLs other than
`/healthz` and `/readyz`. In that case we need to use `customCheck````kotlin
customCheck("/smoketest", "database") { database.test() }
```
And the smoketest should now be avaliable on `/smoketest`