mirror of https://github.com/prometheus/prometheus
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
69 lines
1.7 KiB
69 lines
1.7 KiB
8 years ago
|
// Copyright 2016 The Prometheus Authors
|
||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||
|
// you may not use this file except in compliance with the License.
|
||
|
// You may obtain a copy of the License at
|
||
|
//
|
||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||
|
//
|
||
|
// Unless required by applicable law or agreed to in writing, software
|
||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||
|
// See the License for the specific language governing permissions and
|
||
|
// limitations under the License.
|
||
|
|
||
|
package main
|
||
|
|
||
|
import (
|
||
|
"fmt"
|
||
8 years ago
|
"io"
|
||
|
"io/ioutil"
|
||
8 years ago
|
"log"
|
||
|
"net"
|
||
|
|
||
|
"golang.org/x/net/context"
|
||
|
"google.golang.org/grpc"
|
||
|
|
||
8 years ago
|
"github.com/golang/snappy"
|
||
|
"github.com/prometheus/common/model"
|
||
|
"github.com/prometheus/prometheus/storage/remote"
|
||
8 years ago
|
)
|
||
|
|
||
|
type server struct{}
|
||
|
|
||
8 years ago
|
func (server *server) Write(ctx context.Context, req *remote.WriteRequest) (*remote.WriteResponse, error) {
|
||
8 years ago
|
for _, ts := range req.Timeseries {
|
||
8 years ago
|
m := make(model.Metric, len(ts.Labels))
|
||
8 years ago
|
for _, l := range ts.Labels {
|
||
8 years ago
|
m[model.LabelName(l.Name)] = model.LabelValue(l.Value)
|
||
8 years ago
|
}
|
||
8 years ago
|
fmt.Println(m)
|
||
8 years ago
|
|
||
|
for _, s := range ts.Samples {
|
||
|
fmt.Printf(" %f %d\n", s.Value, s.TimestampMs)
|
||
|
}
|
||
|
}
|
||
|
|
||
8 years ago
|
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"
|
||
8 years ago
|
}
|
||
|
|
||
|
func main() {
|
||
|
lis, err := net.Listen("tcp", ":1234")
|
||
|
if err != nil {
|
||
8 years ago
|
log.Fatalf("Failed to listen: %v", err)
|
||
8 years ago
|
}
|
||
8 years ago
|
s := grpc.NewServer(grpc.RPCDecompressor(&snappyDecompressor{}))
|
||
|
remote.RegisterWriteServer(s, &server{})
|
||
8 years ago
|
s.Serve(lis)
|
||
|
}
|