Pipeline as Http Handler
A pipeline can serves as a http handler with Go standard net/http.
The following example code demonstrates a simple web service that retrieves and returns the CPU usage of the system.
package main
import (
"fmt"
"net/http"
"github.com/OutOfBedlam/tine/engine"
_ "github.com/OutOfBedlam/tine/plugins/all"
)
func main() {
addr := "127.0.0.1:8080"
router := http.NewServeMux()
router.HandleFunc("GET /cpu", engine.HttpHandleFunc(cpuPipeline))
fmt.Printf("\nstart server http://%s\n\n", addr)
http.ListenAndServe(addr, router)
}
const cpuPipeline = `
[[inlets.cpu]]
interval = "3s"
totalcpu = true
percpu = false
[[flows.select]]
includes = ["#_ts", "*"]
[[outlets.file]]
format = "json"
decimal = 2
`To run the example server, execute the following command in your terminal:
Once the server is up and running, you can make a request to the /cpu endpoint by treating it as a RESTful API call. Use the appropriate HTTP method and include the endpoint URL in your request.
For example, you can use the curl command to make a GET request to the /cpu endpoint:
Last updated