mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Fixed png rending
This commit is contained in:
parent
ff6a2d014a
commit
90ae59ccaf
@ -9,6 +9,6 @@ watch_dirs = [
|
|||||||
watch_exts = [".go", ".ini"]
|
watch_exts = [".go", ".ini"]
|
||||||
build_delay = 1500
|
build_delay = 1500
|
||||||
cmds = [
|
cmds = [
|
||||||
["go", "build", "./pkg/cmd/grafana-pro"],
|
["go", "build"],
|
||||||
["./grafana-pro", "web"]
|
["./grafana-pro", "web"]
|
||||||
]
|
]
|
||||||
|
3
main.go
3
main.go
@ -4,7 +4,6 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
|
||||||
"github.com/torkelo/grafana-pro/pkg/bus"
|
|
||||||
"github.com/torkelo/grafana-pro/pkg/cmd"
|
"github.com/torkelo/grafana-pro/pkg/cmd"
|
||||||
|
|
||||||
"github.com/codegangsta/cli"
|
"github.com/codegangsta/cli"
|
||||||
@ -17,8 +16,6 @@ func init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
bus.InitBus()
|
|
||||||
|
|
||||||
app := cli.NewApp()
|
app := cli.NewApp()
|
||||||
app.Name = "Grafana Pro"
|
app.Name = "Grafana Pro"
|
||||||
app.Usage = "Grafana Pro Service"
|
app.Usage = "Grafana Pro Service"
|
||||||
|
@ -67,9 +67,10 @@ func runWeb(*cli.Context) {
|
|||||||
|
|
||||||
setting.NewConfigContext()
|
setting.NewConfigContext()
|
||||||
setting.InitServices()
|
setting.InitServices()
|
||||||
sqlstore.Init()
|
|
||||||
social.NewOAuthService()
|
social.NewOAuthService()
|
||||||
|
|
||||||
|
sqlstore.Init()
|
||||||
|
|
||||||
// init database
|
// init database
|
||||||
sqlstore.LoadModelsConfig()
|
sqlstore.LoadModelsConfig()
|
||||||
if err := sqlstore.NewEngine(); err != nil {
|
if err := sqlstore.NewEngine(); err != nil {
|
||||||
|
@ -1,73 +0,0 @@
|
|||||||
package components
|
|
||||||
|
|
||||||
import (
|
|
||||||
"crypto/md5"
|
|
||||||
"encoding/hex"
|
|
||||||
"io"
|
|
||||||
"os"
|
|
||||||
"os/exec"
|
|
||||||
"path/filepath"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
log "github.com/alecthomas/log4go"
|
|
||||||
)
|
|
||||||
|
|
||||||
type PhantomRenderer struct {
|
|
||||||
ImagesDir string
|
|
||||||
PhantomDir string
|
|
||||||
}
|
|
||||||
|
|
||||||
type RenderOpts struct {
|
|
||||||
Url string
|
|
||||||
Width string
|
|
||||||
Height string
|
|
||||||
}
|
|
||||||
|
|
||||||
func (self *PhantomRenderer) RenderToPng(params *RenderOpts) (string, error) {
|
|
||||||
log.Info("PhantomRenderer::renderToPng url %v", params.Url)
|
|
||||||
binPath, _ := filepath.Abs(filepath.Join(self.PhantomDir, "phantomjs"))
|
|
||||||
scriptPath, _ := filepath.Abs(filepath.Join(self.PhantomDir, "render.js"))
|
|
||||||
pngPath, _ := filepath.Abs(filepath.Join(self.ImagesDir, getHash(params.Url)))
|
|
||||||
pngPath = pngPath + ".png"
|
|
||||||
|
|
||||||
cmd := exec.Command(binPath, scriptPath, "url="+params.Url, "width="+params.Width, "height="+params.Height, "png="+pngPath)
|
|
||||||
stdout, err := cmd.StdoutPipe()
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
stderr, err := cmd.StderrPipe()
|
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
|
|
||||||
err = cmd.Start()
|
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
|
|
||||||
go io.Copy(os.Stdout, stdout)
|
|
||||||
go io.Copy(os.Stdout, stderr)
|
|
||||||
|
|
||||||
done := make(chan error)
|
|
||||||
go func() {
|
|
||||||
cmd.Wait()
|
|
||||||
close(done)
|
|
||||||
}()
|
|
||||||
|
|
||||||
select {
|
|
||||||
case <-time.After(10 * time.Second):
|
|
||||||
if err := cmd.Process.Kill(); err != nil {
|
|
||||||
log.Error("failed to kill: %v", err)
|
|
||||||
}
|
|
||||||
case <-done:
|
|
||||||
}
|
|
||||||
|
|
||||||
return pngPath, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func getHash(text string) string {
|
|
||||||
hasher := md5.New()
|
|
||||||
hasher.Write([]byte(text))
|
|
||||||
return hex.EncodeToString(hasher.Sum(nil))
|
|
||||||
}
|
|
9
pkg/dto/queries.go
Normal file
9
pkg/dto/queries.go
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
package dto
|
||||||
|
|
||||||
|
type GetDashboardQuery struct {
|
||||||
|
Id int64
|
||||||
|
Resp GetDashboardQueryResp
|
||||||
|
}
|
||||||
|
|
||||||
|
type GetDashboardQueryResp struct {
|
||||||
|
}
|
@ -15,7 +15,7 @@ func authGetRequestAccountId(c *Context, sess session.Store) (int64, error) {
|
|||||||
|
|
||||||
urlQuery := c.Req.URL.Query()
|
urlQuery := c.Req.URL.Query()
|
||||||
if len(urlQuery["render"]) > 0 {
|
if len(urlQuery["render"]) > 0 {
|
||||||
accId, _ := strconv.Atoi(urlQuery["accountId"][0])
|
accId, _ := strconv.ParseInt(urlQuery["accountId"][0], 10, 64)
|
||||||
sess.Set("accountId", accId)
|
sess.Set("accountId", accId)
|
||||||
accountId = accId
|
accountId = accId
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
package sqlstore
|
package sqlstore
|
||||||
|
|
||||||
import (
|
import "github.com/torkelo/grafana-pro/pkg/models"
|
||||||
"github.com/torkelo/grafana-pro/pkg/models"
|
|
||||||
)
|
|
||||||
|
|
||||||
func SaveDashboard(dash *models.Dashboard) error {
|
func SaveDashboard(dash *models.Dashboard) error {
|
||||||
var err error
|
var err error
|
||||||
|
Loading…
Reference in New Issue
Block a user