//Diagnostics shows a bunch of app engine's information for the app/project
//useful for figuring out which version of an app is serving
func Diagnostics(w http.ResponseWriter, r *http.Request) {
	c := appengine.NewContext(r)

	out := map[string]interface{}{
		"App ID":                   appengine.AppID(c),
		"Instance ID":              appengine.InstanceID(),
		"Default Version Hostname": appengine.DefaultVersionHostname(c),
		"Version ID":               appengine.VersionID(c),
		"Datacenter":               appengine.Datacenter(c),
		"Module Name":              appengine.ModuleName(c),
		"Server Software":          appengine.ServerSoftware(),
	}

	templates.Load(w, "diagnostics", out)
	return
}
Example #2
0
// Status gathers a quick overview of the system state
// and dumps it in JSON format.
func Status(w http.ResponseWriter, r *http.Request) {
	if r.Method != "GET" {
		return
	}

	ctx := appengine.NewContext(r)

	m := new(runtime.MemStats)
	runtime.ReadMemStats(m)

	s := &status{
		initTime,
		appengineStatus{
			appengine.InstanceID(),
			appengine.AppID(ctx),
			appengine.Datacenter(ctx),
			appengine.DefaultVersionHostname(ctx),
			appengine.ModuleName(ctx),
			appengine.IsDevAppServer(),
		},
		runtimeStatus{
			runtime.GOMAXPROCS(0),
			runtime.GOARCH,
			runtime.GOOS,
			runtime.GOROOT(),
			runtime.NumCPU(),
			runtime.NumCgoCall(),
			runtime.Version(),
			*m,
		},
		os.Environ(),
	}

	b, err := json.Marshal(s)

	if err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}

	w.Header().Set("Content-Type", "application/json; encoding=utf-8")
	w.Write(b)
}
Example #3
0
func (l *GCLLogger) Log(res *responseLogger, r *http.Request) (err error) {
	if res.Status() == http.StatusOK {
		context := appengine.NewContext(r)
		client, err := google.DefaultClient(appengine.NewContext(r),
			logging.CloudPlatformScope)
		if err != nil {
			return err
		}
		service, err := logging.New(client)
		if err != nil {
			return err
		}

		projectId := appengine.AppID(context)

		labels := map[string]string{
			"compute.googleapis.com/resource_type": "instance",
			"compute.googleapis.com/resource_id":   appengine.InstanceID(),
		}

		meta := &logging.LogEntryMetadata{
			Severity:    l.Severity,
			ProjectId:   projectId,
			ServiceName: "compute.googleapis.com",
			Zone:        appengine.Datacenter(context),
		}
		entry := &logging.LogEntry{Metadata: meta, TextPayload: string(res.Body())}

		e := &logging.WriteLogEntriesRequest{
			CommonLabels: labels,
			Entries:      []*logging.LogEntry{entry},
		}
		_, err = service.Projects.Logs.Entries.Write(projectId, l.Target, e).Do()
	}
	return
}
Example #4
0
func (g giImpl) Datacenter() string {
	return appengine.Datacenter(g.aeCtx)
}