Skip to content
This repository has been archived by the owner on Jul 3, 2021. It is now read-only.

Commit

Permalink
Merge pull request #26 from yabetsu93/enh0002
Browse files Browse the repository at this point in the history
Enh0002
  • Loading branch information
jorinvo authored Jan 3, 2021
2 parents 5ed9c7c + bc3b190 commit 4473498
Show file tree
Hide file tree
Showing 247 changed files with 515 additions and 51,494 deletions.
10 changes: 10 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module qvl.io/promplot

go 1.15

require (
github.com/prometheus/client_golang v1.9.0 // indirect
github.com/prometheus/common v0.15.0
github.com/slack-go/slack v0.7.4 // indirect
gonum.org/v1/plot v0.8.1
)
477 changes: 477 additions & 0 deletions go.sum

Large diffs are not rendered by default.

149 changes: 0 additions & 149 deletions lock.json

This file was deleted.

16 changes: 0 additions & 16 deletions manifest.json

This file was deleted.

14 changes: 8 additions & 6 deletions promplot/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,27 @@ import (
"fmt"
"time"

"github.com/prometheus/client_golang/api/prometheus"
"github.com/prometheus/client_golang/api"
v1 "github.com/prometheus/client_golang/api/prometheus/v1"
"github.com/prometheus/common/model"
)

// Metrics fetches data from Prometheus.
func Metrics(server, query string, queryTime time.Time, duration, step time.Duration) (model.Matrix, error) {
client, err := prometheus.New(prometheus.Config{Address: server})
client, err := api.NewClient(api.Config{Address: server})
if err != nil {
return nil, fmt.Errorf("failed to create Prometheus client: %v", err)
return nil, fmt.Errorf("failed to create prometheus api client: %v", err)
}

api := prometheus.NewQueryAPI(client)
value, err := api.QueryRange(context.Background(), query, prometheus.Range{
promAPI := v1.NewAPI(client)

value, _, err := promAPI.QueryRange(context.Background(), query, v1.Range{
Start: queryTime.Add(-duration),
End: queryTime,
Step: duration / step,
})
if err != nil {
return nil, fmt.Errorf("failed to query Prometheus: %v", err)
return nil, fmt.Errorf("failed to query prometheus api: %v", err)
}

metrics, ok := value.(model.Matrix)
Expand Down
10 changes: 5 additions & 5 deletions promplot/plot.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import (
"regexp"
"strconv"

"github.com/gonum/plot"
"github.com/gonum/plot/palette/brewer"
"github.com/gonum/plot/plotter"
"github.com/gonum/plot/vg"
"github.com/gonum/plot/vg/draw"
"github.com/prometheus/common/model"
"gonum.org/v1/plot"
"gonum.org/v1/plot/palette/brewer"
"gonum.org/v1/plot/plotter"
"gonum.org/v1/plot/vg"
"gonum.org/v1/plot/vg/draw"
)

// Only show important part of metric name
Expand Down
30 changes: 15 additions & 15 deletions promplot/slack.go
Original file line number Diff line number Diff line change
@@ -1,51 +1,51 @@
package promplot

import (
"context"
"fmt"
"io"
"io/ioutil"
"os"

"github.com/nlopes/slack"
"github.com/slack-go/slack"
)

// Slack posts a file to a Slack channel.
func Slack(token, channel, title string, plot io.WriterTo) error {
api := slack.New(token)

_, _, err := api.PostMessage(channel, title, slack.PostMessageParameters{
Username: "Promplot",
IconEmoji: ":chart_with_upwards_trend:",
})
if err != nil {
if _, _, err := api.PostMessageContext(context.Background(), channel, slack.MsgOptionPostMessageParameters(
slack.PostMessageParameters{
Username: "Promplot",
IconEmoji: ":chart_with_upwards_trend:",
},
)); err != nil {
return fmt.Errorf("failed to post message: %v", err)
}

f, err := ioutil.TempFile("", "promplot-")
if err != nil {
return fmt.Errorf("failed to create tmp file: %v", err)
}

defer func() {
err = f.Close()
if err != nil {
if err = f.Close(); err != nil {
panic(fmt.Errorf("failed to close tmp file: %v", err))
}
err := os.Remove(f.Name())
if err != nil {
if err = os.Remove(f.Name()); err != nil {
panic(fmt.Errorf("failed to delete tmp file: %v", err))
}
}()
_, err = plot.WriteTo(f)
if err != nil {

if _, err = plot.WriteTo(f); err != nil {
return fmt.Errorf("failed to write plot to file: %v", err)
}

_, err = api.UploadFile(slack.FileUploadParameters{
if _, err = api.UploadFile(slack.FileUploadParameters{
Title: title,
File: f.Name(),
Channels: []string{channel},
})
if err != nil {
}); err != nil {
return fmt.Errorf("failed to upload file: %v", err)
}

Expand Down
13 changes: 0 additions & 13 deletions vendor/bitbucket.org/zombiezen/gopdf/AUTHORS

This file was deleted.

14 changes: 0 additions & 14 deletions vendor/bitbucket.org/zombiezen/gopdf/CONTRIBUTORS

This file was deleted.

23 changes: 0 additions & 23 deletions vendor/bitbucket.org/zombiezen/gopdf/LICENSE

This file was deleted.

16 changes: 0 additions & 16 deletions vendor/bitbucket.org/zombiezen/gopdf/pdf/Makefile

This file was deleted.

Loading

0 comments on commit 4473498

Please sign in to comment.