Skip to content

Commit

Permalink
- promelog 时区由utc改为local
Browse files Browse the repository at this point in the history
- 使用makefile编译
- 移动配置文件位置
- 完善readme
  • Loading branch information
ning1875 committed Mar 23, 2021
1 parent 9735ecb commit 87478ee
Show file tree
Hide file tree
Showing 7 changed files with 141 additions and 34 deletions.
11 changes: 7 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
# 架构图

![image](./images/xprober架构图.jpg)
# Xprober预览图

### 互ping 结果

![image](https://github.com/ning1875/xprober/blob/master/images/ping.jpg)
![image](./images/ping.jpg)
### http 探测结果
![image](https://github.com/ning1875/xprober/blob/master/images/http.jpg)
![image](./images/http.jpg)

### 专线延迟报警
![image](https://github.com/ning1875/xprober/blob/master/images/zhuanxian_mon.jpg)
![image](./images/zhuanxian_mon.jpg)


# 需求分析
## 网络监控工具调研
- 多region为一般公司内网架构
- 这个工具能提供网络性能数据监控
- 同时也参考调研了tor维度的[pingmesh方案](https://zdyxry.github.io/2020/03/26/%E8%AE%BA%E6%96%87%E9%98%85%E8%AF%BB-%E3%80%8APingmesh-A-Large-Scale-System-for-Data-Center-Network-Latency-Measurement-and-Analysis%E3%80%8B/)
![image](https://github.com/ning1875/xprober/blob/master/images/ping_mesh.jpg)
![image](./images/ping_mesh.jpg)

## 总结
**key1** 其实最主要能看到公有混合云内网所有region两两之间的延迟和丢包率
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ require (
github.com/shimingyah/pool v0.0.0-20190724082523-04bd98b0fbfe // indirect
golang.org/x/net v0.0.0-20190813141303-74dc4d7220e7
google.golang.org/grpc v1.28.1
gopkg.in/alecthomas/kingpin.v2 v2.2.6
gopkg.in/yaml.v2 v2.2.4
)
Binary file added images/xprober架构图.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
35 changes: 35 additions & 0 deletions makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
GOCMD=go
GOBUILD=${GOCMD} build
GOCLEAN=${GOCMD} clean
GOTEST=${GOCMD} test
GOGET=${GOCMD} get
VERSION=1.0
DATE= `date +%FT%T%z`


BINARY_NAME_SERVER="xprober-server"
BINARY_NAME_AGENT="xprober-agent"
BINARY_LINUX=${BINARY_NAME}_linux
BUILDUSER="ning1875"
LDFLAGES=" -X 'github.com/prometheus/common/version.BuildUser=${BUILDUSER}' -X 'github.com/prometheus/common/version.BuildDate=`date`' "
all: deps build
deps:
export GOPROXY=http://goproxy.io
export GO111MODULE=on
build:
${GOBUILD} -v -ldflags ${LDFLAGES} -o ${BINARY_NAME_SERVER} pkg/server/main.go
${GOBUILD} -v -ldflags ${LDFLAGES} -o ${BINARY_NAME_AGENT} pkg/agent/main.go
test:
${GOTEST} -v ./...
clean:
${GOCLEAN}
rm -f ${BINARY_NAME}
rm -f ${BINARY_LINUX}
run:
${GOBUILD} -o ${BINARY_NAME} -v ./...
./${BINARY_NAME}


build-linux:
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 ${BUILDTOOL}

55 changes: 44 additions & 11 deletions pkg/cmd/agent/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,64 @@ package main

import (
"os"
"syscall"
"os/signal"
"path/filepath"
"syscall"
"time"

"gopkg.in/alecthomas/kingpin.v2"
"github.com/go-kit/kit/log"
"github.com/go-kit/kit/log/level"
"github.com/prometheus/common/promlog"
"github.com/prometheus/common/promlog/flag"
promlogflag "github.com/prometheus/common/promlog/flag"
"github.com/prometheus/common/version"
"gopkg.in/alecthomas/kingpin.v2"

"xprober/pkg/agent"
)

var (
grpcServerAddress = kingpin.Flag("grpc.server-address", "server addr").Default(":6001").String()
app = kingpin.New(filepath.Base(os.Args[0]), "The xprober-agent")
grpcServerAddress = app.Flag("grpc.server-address", "server addr").Default(":6001").String()
)

func main() {

// init logger
promlogConfig := &promlog.Config{}
flag.AddFlags(kingpin.CommandLine, promlogConfig)
kingpin.Version(version.Print("xprober-agent"))
kingpin.HelpFlag.Short('h')
kingpin.Parse()
logger := promlog.New(promlogConfig)
promlogConfig := promlog.Config{}

app.Version(version.Print("xprober-agent"))
app.HelpFlag.Short('h')
promlogflag.AddFlags(app, &promlogConfig)
kingpin.MustParse(app.Parse(os.Args[1:]))

var logger log.Logger
logger = func(config *promlog.Config) log.Logger {
var (
l log.Logger
le level.Option
)
if config.Format.String() == "logfmt" {
l = log.NewLogfmtLogger(log.NewSyncWriter(os.Stderr))
} else {
l = log.NewJSONLogger(log.NewSyncWriter(os.Stderr))
}

switch config.Level.String() {
case "debug":
le = level.AllowDebug()
case "info":
le = level.AllowInfo()
case "warn":
le = level.AllowWarn()
case "error":
le = level.AllowError()
}
l = level.NewFilter(l, le)
l = log.With(l, "ts", log.TimestampFormat(
func() time.Time { return time.Now().Local() },
"2006-01-02T15:04:05.000Z07:00",
), "caller", log.DefaultCaller)
return l
}(&promlogConfig)

//init local region and get ip
if regionSucc := agent.GetLocalRegionByEc2(logger); regionSucc == false {
Expand Down
73 changes: 54 additions & 19 deletions pkg/cmd/server/main.go
Original file line number Diff line number Diff line change
@@ -1,44 +1,79 @@
package main

import (
"context"

"net/http"
"os"
"os/signal"
"path/filepath"
"syscall"
"context"
"net/http"
"time"

"github.com/oklog/run"
"gopkg.in/alecthomas/kingpin.v2"
"github.com/go-kit/kit/log"
"github.com/go-kit/kit/log/level"
"github.com/prometheus/common/version"
"github.com/prometheus/common/promlog"
"github.com/prometheus/common/promlog/flag"
"github.com/oklog/run"
"github.com/prometheus/client_golang/prometheus/promhttp"
"github.com/prometheus/common/promlog"
promlogflag "github.com/prometheus/common/promlog/flag"
"github.com/prometheus/common/version"
"gopkg.in/alecthomas/kingpin.v2"

rc "xprober/pkg/server"
)

func main() {

var (
//app = kingpin.New(filepath.Base(os.Args[0]), "The Xprober")
configFile = kingpin.Flag("config.file", "xprober configuration file path.").Default("xprober.yml").String()
//grpcListenAddress = kingpin.Flag("grpc.listen-address", "Address to listen on for the grpc interface, API, and telemetry.").Default(":6001").String()
//webListenAddr = kingpin.Flag("web.listen-address", "Address to listen on for the web interface, API, and telemetry.").Default(":6002").String()
app = kingpin.New(filepath.Base(os.Args[0]), "The xprober-server")
configFile = app.Flag("config.file", "xprober configuration file path.").Default("xprober.yml").String()
)

// init logger
promlogConfig := &promlog.Config{}
flag.AddFlags(kingpin.CommandLine, promlogConfig)
kingpin.Version(version.Print("xprober"))
kingpin.HelpFlag.Short('h')
kingpin.Parse()
logger := promlog.New(promlogConfig)
promlogConfig := promlog.Config{}

app.Version(version.Print("xprober-server"))
app.HelpFlag.Short('h')
promlogflag.AddFlags(app, &promlogConfig)
kingpin.MustParse(app.Parse(os.Args[1:]))

var logger log.Logger
logger = func(config *promlog.Config) log.Logger {
var (
l log.Logger
le level.Option
)
if config.Format.String() == "logfmt" {
l = log.NewLogfmtLogger(log.NewSyncWriter(os.Stderr))
} else {
l = log.NewJSONLogger(log.NewSyncWriter(os.Stderr))
}

switch config.Level.String() {
case "debug":
le = level.AllowDebug()
case "info":
le = level.AllowInfo()
case "warn":
le = level.AllowWarn()
case "error":
le = level.AllowError()
}
l = level.NewFilter(l, le)
l = log.With(l, "ts", log.TimestampFormat(
func() time.Time { return time.Now().Local() },
"2006-01-02T15:04:05.000Z07:00",
), "caller", log.DefaultCaller)
return l
}(&promlogConfig)

// new grpc manager
ctxAll, cancelAll := context.WithCancel(context.Background())

sConfig, _ := rc.LoadFile(*configFile, logger)
sConfig, err := rc.LoadFile(*configFile, logger)
if err != nil {
level.Error(logger).Log("msg", "load_config_file_error", "err", err)
return
}
grpcListenAddress := sConfig.RpcListenAddr

webListenAddr := sConfig.MetricsListenAddr
Expand Down
File renamed without changes.

0 comments on commit 87478ee

Please sign in to comment.