Comments (9)
Hi @messi655,
To integrate with fasthttp, you need to make a handler func which will do the routing of requests to our internal helper functions for each status route. It should be pretty simple. An example for the standard net/http library is in
https://github.com/hootsuite/healthchecks/blob/master/http.go.
I'm not too familiar with fasthttp, but to add another routing framework integration with healthchecks you should do something like this:
- Provide a handler function to route requests like
/status/...
to the appropriate helper function in the healthchecks framework. Ex. https://github.com/hootsuite/healthchecks/blob/master/http.go. Since you are doing this for fasthttp, I would do this in a newfasthttp
package. - Register this new handler function in your app and pass in your StatusEndpoints so that requests get routed to the right
/status/...
endpoint. Ex. https://github.com/hootsuite/healthchecks#how-to-use-it - Verify it all works as it should with tests like this for your implementation: https://github.com/hootsuite/healthchecks/blob/master/http_test.go
Send us a PR and we'll check it out. :) Thanks!
from healthchecks.
hi @HootAdam ,
thanks for your feedback.
I found another way like this:
- I create status function that implement healthcheck
`func status() {
DBdriver := GetConfigure("DB_DRIVER")
DBuser := GetConfigure("DB_USER")
DBpassword := GetConfigure("DB_PASSWORD")
DBschema := GetConfigure("DB_SCHEMA")
DBHost := GetConfigure("DB_HOST")
DBPort := GetConfigure("DB_PORT")
db, err := sql.Open(DBdriver, DBuser+":"+DBpassword+"@tcp("+DBHost+":"+DBPort+")/"+DBschema)
if err != nil {
log.Fatal(err)
}
// Define a StatusEndpoint at '/status/db' for a database dependency
dbs := healthchecks.StatusEndpoint{
Name: "The DB",
Slug: "db",
Type: "internal",
IsTraversable: false,
StatusCheck: sqlsc.SQLDBStatusChecker{DB: db},
TraverseCheck: nil,
}
org := healthchecks.StatusEndpoint{
Name: "Organization Service",
Slug: "service-organization",
Type: "http",
IsTraversable: true,
StatusCheck: httpsc.HttpStatusChecker{
BaseUrl: "http://localhost:8800",
},
TraverseCheck: httpsc.HttpStatusChecker{
BaseUrl: "http://localhost:8800",
},
}
// Add all your StatusEndpoints to a slice for your service.
// This will be used to initialize the framework in the next step.
statusEndpoints := []healthchecks.StatusEndpoint{dbs, org}
aboutFilePath := "conf/about.json"
versionFilePath := "conf/version.txt"
customData := make(map[string]interface{})
//mux := http.NewServeMux()
http.Handle("/status/", healthchecks.Handler(statusEndpoints, aboutFilePath, versionFilePath, customData))
log.Println("Listening...")
abc := http.ListenAndServe(":3333", nil)
log.Fatal(abc)
}`
and I use goroutine to integrate to our API.
But when I run our api and I access to http://localhost:3333/status/service-organization the output is ["CRIT",{"description":"Organization Service","result":"CRIT","details":"Get http://localhost:8800/status/aggregate: dial tcp: lookup localhost on 127.0.1.1:53: no such host"}]
Can you help this? why?
from healthchecks.
The org
StatusEndpoint is an example of how you would do downstream checks of another service. Since you probably don't have another service running at localhost:8080, the status check is failing as it should. I would remove this check from your service and only initialize the database one if you have a DB.
from healthchecks.
thanks @HootAdam I got it.
from healthchecks.
OK great! @vantinhuynh Are there any other code changes needed to work with fasthttp?
from healthchecks.
@HootAdam I did not change to work with fasthttp. I only start on the other port (service port 8800, healthcheck port 3333).
from healthchecks.
@vantinhuynh Thats great! One other question, did you create the about.json
file and version.txt
file in your service so when you run /status/about
you get all the meta data for your service?
about.json
is usually seeded in the project when it is created. Example: https://github.com/hootsuite/healthchecks/blob/master/test/about.jsonversion.txt
is usually generated by your build process and you can put any version in there that makes sense to you. We usually put a git commit hash. Example: https://github.com/hootsuite/healthchecks/blob/master/test/version.txt
Lastly, if you want to add a status check to a dependency, you can always check our shared status checks repository to see if one exists at https://github.com/hootsuite/healthchecks/tree/master/checks. If you create any status checks that you think the community would benefit from, you can always submit them.
Thanks!
from healthchecks.
@HootAdam One other question, did you create the about.json file and version.txt file in your service so when you run /status/about you get all the meta data for your service?
=> Yes, I did. It work perfect.
Thank @HootAdam I will.
from healthchecks.
@vantinhuynh Great. Closing this Issue. If you have any more questions let us know
from healthchecks.
Related Issues (3)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from healthchecks.