Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
A Go script that retrieves the Varnish memory consumption and returns it via a RESTful API using GoJi
package main
import (
func usage(c web.C, w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
encoder := json.NewEncoder(w)
cmdName := "varnishstat"
cmdArgs := []string{"-f", "SMA.s0.g_bytes", "-j"}
cmd := exec.Command(cmdName, cmdArgs...)
stdout, err := cmd.Output()
if(err != nil) {
http.Error(w, err.Error(), 500)
var varnishstatInterface interface{}
err = json.Unmarshal([]byte(stdout), &varnishstatInterface)
if(err != nil) {
http.Error(w, err.Error(), 500)
varnishstatMap := varnishstatInterface.(map[string]interface{})
valueMap := varnishstatMap["SMA.s0.g_bytes"].(map[string]interface{})
encoder.Encode(strconv.FormatFloat(valueMap["value"].(float64), 'f', 0, 32))
func main() {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.