mirror of
https://github.com/taigrr/wtf
synced 2025-01-18 04:03:14 -08:00
Basic New Relic deploy info
This commit is contained in:
committed by
Chris Cummer
parent
a82db2bea8
commit
6303acc9a4
30
newrelic/client.go
Normal file
30
newrelic/client.go
Normal file
@@ -0,0 +1,30 @@
|
||||
package newrelic
|
||||
|
||||
import (
|
||||
"os"
|
||||
|
||||
nr "github.com/yfronto/newrelic"
|
||||
)
|
||||
|
||||
func Application() (*nr.Application, error) {
|
||||
client := nr.NewClient(os.Getenv("WTF_NEW_RELIC_API_KEY"))
|
||||
|
||||
application, err := client.GetApplication(Config.UInt("wtf.newrelic.applicationId"))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return application, nil
|
||||
}
|
||||
|
||||
func Deployments() ([]nr.ApplicationDeployment, error) {
|
||||
client := nr.NewClient(os.Getenv("WTF_NEW_RELIC_API_KEY"))
|
||||
|
||||
opts := &nr.ApplicationDeploymentOptions{Page: 1}
|
||||
deployments, err := client.GetApplicationDeployments(Config.UInt("wtf.newrelic.applicationId"), opts)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return deployments, nil
|
||||
}
|
||||
87
newrelic/widget.go
Normal file
87
newrelic/widget.go
Normal file
@@ -0,0 +1,87 @@
|
||||
package newrelic
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/gdamore/tcell"
|
||||
"github.com/olebedev/config"
|
||||
"github.com/rivo/tview"
|
||||
"github.com/senorprogrammer/wtf/wtf"
|
||||
nr "github.com/yfronto/newrelic"
|
||||
)
|
||||
|
||||
var Config *config.Config
|
||||
|
||||
type Widget struct {
|
||||
wtf.BaseWidget
|
||||
|
||||
View *tview.TextView
|
||||
}
|
||||
|
||||
func NewWidget() *Widget {
|
||||
widget := Widget{
|
||||
BaseWidget: wtf.BaseWidget{
|
||||
Name: "New Relic",
|
||||
RefreshedAt: time.Now(),
|
||||
RefreshInt: Config.UInt("wtf.newrelic.refreshInterval", 900),
|
||||
},
|
||||
}
|
||||
|
||||
widget.addView()
|
||||
|
||||
return &widget
|
||||
}
|
||||
|
||||
/* -------------------- Exported Functions -------------------- */
|
||||
|
||||
func (widget *Widget) Refresh() {
|
||||
app, _ := Application()
|
||||
deploys, _ := Deployments()
|
||||
|
||||
widget.View.SetTitle(fmt.Sprintf(" New Relic: [green]%s[white] ", app.Name))
|
||||
widget.RefreshedAt = time.Now()
|
||||
|
||||
widget.View.Clear()
|
||||
fmt.Fprintf(widget.View, "%s", widget.contentFrom(deploys))
|
||||
}
|
||||
|
||||
/* -------------------- Unexported Functions -------------------- */
|
||||
|
||||
func (widget *Widget) addView() {
|
||||
view := tview.NewTextView()
|
||||
|
||||
view.SetBorder(true)
|
||||
view.SetBorderColor(tcell.ColorGray)
|
||||
view.SetDynamicColors(true)
|
||||
view.SetTitle(widget.Name)
|
||||
view.SetWrap(false)
|
||||
|
||||
widget.View = view
|
||||
}
|
||||
|
||||
func (widget *Widget) contentFrom(deploys []nr.ApplicationDeployment) string {
|
||||
str := "\n"
|
||||
str = str + " [red]Latest Deploys[white]\n"
|
||||
|
||||
revisions := []string{}
|
||||
|
||||
for _, deploy := range deploys {
|
||||
if (deploy.Revision != "") && wtf.Exclude(revisions, deploy.Revision) {
|
||||
str = str + fmt.Sprintf(
|
||||
" [green]%4s[white] %s %s\n",
|
||||
deploy.Revision[len(deploy.Revision)-4:],
|
||||
deploy.Timestamp.Format("Jan 2 15:04"),
|
||||
wtf.NameFromEmail(deploy.User),
|
||||
)
|
||||
|
||||
revisions = append(revisions, deploy.Revision)
|
||||
|
||||
if len(revisions) == Config.UInt("wtf.newrelic.deployCount", 5) {
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return str
|
||||
}
|
||||
Reference in New Issue
Block a user