mirror of
https://github.com/prometheus/prometheus.git
synced 2025-07-03 11:03:25 +00:00
Generic write cleanups and changes.
- fold metric name into labels - return initialization errors back to main - add snappy compression - better context handling - pre-allocation of labels - remove generic naming - other cleanups
This commit is contained in:
parent
d8ce6e5849
commit
aa3f2b7216
12 changed files with 406 additions and 334 deletions
17
documentation/examples/remote_storage/README.md
Normal file
17
documentation/examples/remote_storage/README.md
Normal file
|
@ -0,0 +1,17 @@
|
|||
## Generic Remote Storage Example
|
||||
|
||||
This is a simple example of how to write a server to
|
||||
receive samples from the remote storage output.
|
||||
|
||||
To use it:
|
||||
|
||||
```
|
||||
go build
|
||||
remote_storage
|
||||
```
|
||||
|
||||
...and then run Prometheus as:
|
||||
|
||||
```
|
||||
./prometheus -storage.remote.address=localhost:1234
|
||||
```
|
|
@ -15,39 +15,54 @@ package main
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"net"
|
||||
|
||||
"golang.org/x/net/context"
|
||||
"google.golang.org/grpc"
|
||||
|
||||
"github.com/prometheus/prometheus/storage/remote/generic"
|
||||
"github.com/golang/snappy"
|
||||
"github.com/prometheus/common/model"
|
||||
"github.com/prometheus/prometheus/storage/remote"
|
||||
)
|
||||
|
||||
type server struct{}
|
||||
|
||||
func (server *server) Write(ctx context.Context, req *generic.GenericWriteRequest) (*generic.GenericWriteResponse, error) {
|
||||
func (server *server) Write(ctx context.Context, req *remote.WriteRequest) (*remote.WriteResponse, error) {
|
||||
for _, ts := range req.Timeseries {
|
||||
fmt.Printf("%s", ts.Name)
|
||||
m := make(model.Metric, len(ts.Labels))
|
||||
for _, l := range ts.Labels {
|
||||
fmt.Printf(" %s=%s", l.Name, l.Value)
|
||||
m[model.LabelName(l.Name)] = model.LabelValue(l.Value)
|
||||
}
|
||||
fmt.Printf("\n")
|
||||
fmt.Println(m)
|
||||
|
||||
for _, s := range ts.Samples {
|
||||
fmt.Printf(" %f %d\n", s.Value, s.TimestampMs)
|
||||
}
|
||||
}
|
||||
|
||||
return &generic.GenericWriteResponse{}, nil
|
||||
return &remote.WriteResponse{}, nil
|
||||
}
|
||||
|
||||
type snappyDecompressor struct{}
|
||||
|
||||
func (d *snappyDecompressor) Do(r io.Reader) ([]byte, error) {
|
||||
sr := snappy.NewReader(r)
|
||||
return ioutil.ReadAll(sr)
|
||||
}
|
||||
|
||||
func (d *snappyDecompressor) Type() string {
|
||||
return "snappy"
|
||||
}
|
||||
|
||||
func main() {
|
||||
lis, err := net.Listen("tcp", ":1234")
|
||||
if err != nil {
|
||||
log.Fatalf("failed to listen: %v", err)
|
||||
log.Fatalf("Failed to listen: %v", err)
|
||||
}
|
||||
s := grpc.NewServer()
|
||||
generic.RegisterGenericWriteServer(s, &server{})
|
||||
s := grpc.NewServer(grpc.RPCDecompressor(&snappyDecompressor{}))
|
||||
remote.RegisterWriteServer(s, &server{})
|
||||
s.Serve(lis)
|
||||
}
|
|
@ -1,17 +0,0 @@
|
|||
## Generic Remote Storage Example
|
||||
|
||||
This is a simple example of how to write a server to
|
||||
recieve samples from the generic remote storage output.
|
||||
|
||||
To use it:
|
||||
|
||||
```
|
||||
go build
|
||||
remote_storage_generic
|
||||
```
|
||||
|
||||
and then run Prometheus as:
|
||||
|
||||
```
|
||||
./prometheus -storage.remote.generic-url http://localhost:1234/remote
|
||||
```
|
Loading…
Add table
Add a link
Reference in a new issue