【笔记】macos上部署thanos_receiver + thanos_query
- 为了方便起见,在mac笔记本上进行了测试
1.写一个发送数据的客户端
package main
import (
"fmt"
"io/ioutil"
"log"
"math/rand"
"net/http"
"os"
"strconv"
"strings"
"time"
"github.com/golang/protobuf/proto"
"github.com/prometheus/prometheus/prompb"
"github.com/golang/snappy"
)
var client = &http.Client{
Transport: &http.Transport{
Proxy: nil,
DialContext: nil,
Dial: nil,
DialTLSContext: nil,
DialTLS: nil,
TLSClientConfig: nil,
TLSHandshakeTimeout: 0,
DisableKeepAlives: false,
DisableCompression: false,
MaxIdleConns: 100,
MaxIdleConnsPerHost: 0,
MaxConnsPerHost: 0,
IdleConnTimeout: 0,
ResponseHeaderTimeout: 0,
ExpectContinueTimeout: 0,
TLSNextProto: nil,
ProxyConnectHeader: nil,
MaxResponseHeaderBytes: 0,
WriteBufferSize: 0,
ReadBufferSize: 0,
ForceAttemptHTTP2: false,
},
CheckRedirect: nil,
Jar: nil,
Timeout: time.Duration(1000) * time.Millisecond,
}
//Post POST数据
func Post(c *http.Client, url string, postData string, timeoutMs int, headers map[string]string) (int, []byte, error) {
req, err := http.NewRequest("POST", url, strings.NewReader(postData))
if err != nil {
return 0, nil, err
}
for k, v := range headers {
req.Header.Set(k, v)
}
c.Timeout = time.Duration(timeoutMs) * time.Millisecond
rsp, err := c.Do(req)
if err != nil {
return 0, nil, err
}
respData, err := ioutil.ReadAll(rsp.Body)
rsp.Body.Close()
if err != nil {
return rsp.StatusCode, nil, err
}
return rsp.StatusCode, respData, nil
}
func getReq(cnt int) *prompb.WriteRequest {
req := &prompb.WriteRequest{
Timeseries: []prompb.TimeSeries{
prompb.TimeSeries{
Labels: []prompb.Label{
prompb.Label{
Name: "__name__",
Value: "metric_of_ahfu_1",
},
prompb.Label{
Name: "container",
Value: "cls-xxxxx-111",
},
{Name: "instance", Value: "localhost:9090"},
{Name: "job", Value: "prometheus"},
},
Samples: []prompb.Sample{
prompb.Sample{
Value: float64(1002),
Timestamp: time.Now().UnixNano() / 1000000,
},
},
Exemplars: nil,
},
},
Metadata: []prompb.MetricMetadata{},
}
if cnt > 1 {
for i := 1; i < cnt; i++ {
req.Timeseries = append(req.Timeseries, prompb.TimeSeries{
Labels: []prompb.Label{
prompb.Label{
Name: "__name__",
Value: fmt.Sprintf("metric_of_ahfu_%d", i+1),
},
prompb.Label{
Name: "container",
Value: "cls-xxxxx-111",
},
{Name: "instance", Value: "localhost:9090"},
{Name: "job", Value: "prometheus"},
},
Samples: []prompb.Sample{
prompb.Sample{
Value: float64(rand.Intn(2000)),
Timestamp: time.Now().UnixNano() / 1000000,
},
},
Exemplars: nil,
})
}
}
return req
}
func main() {
log.SetFlags(log.LstdFlags | log.Lshortfile)
runtimes := 1
if len(os.Args) >= 4 {
runtimes, _ = strconv.Atoi(os.Args[3])
}
for r := 0; r < runtimes; r++ {
cnt := 1
if len(os.Args) >= 3 {
cnt, _ = strconv.Atoi(os.Args[2])
}
req := getReq(cnt)
log.Println(req)
buf, _ := proto.Marshal(req)
dst := make([]byte, 0, len(buf))
dst = snappy.Encode(dst, buf)
//
url := fmt.Sprintf("http://%s/api/v1/receive", os.Args[1])
_, rsp, err := Post(client, url, string(dst), 1000,
map[string]string{
"Content-Encoding": "snappy",
"Content-Type": "application/x-protobuf",
"User-Agent": "ahfu-test-client",
"X-Prometheus-Remote-Write-Version": "0.1.0",
})
if err != nil {
log.Println("Post error:", err.Error())
return
}
log.Println("url:", url)
log.Println("rsp:", string(rsp))
time.Sleep(time.Duration(10) * time.Second)
}
}
- 执行命令行:
./remote_write_client_macos 127.0.0.1:10908 30 1000- 每次发送30个监控项
- 连续发送1000次,中间间隔10秒
- instance和job这两个label一定要加,否则thanos receiver会丢弃。
2.部署thanos receiver:
thanos receive \
--tsdb.path "./ahfu_dir/" \
--grpc-address 0.0.0.0:10907 \
--http-address 0.0.0.0:10909 \
--receive.replication-factor 1 \
--label "receive_replica=\"0\"" \
--label "receive_cluster=\"eu1\"" \
--remote-write.address 0.0.0.0:10908 \
--log.level=debug \
--log.format=logfmt
- 10908端口是http协议,用于post监控数据到receiver上
- 10907端口是grpc协议,用于给thanos query来查询
- 10909端口是自身的监控数据的expoter
- 浏览器输入:http://127.0.0.1:10909/metrics可以看见thanos receiver自身的监控数据
- 搜索:
http_requests_total{code="200",handler="receive",method="post"}可以看见推送的请求量
- 到TSDB目录:
- 执行:
promtool tsdb list ./ - 启动后两分钟以后,可以看见如下信息:
- 执行:
promtool tsdb list ./
BLOCK ULID MIN TIME MAX TIME DURATION NUM SAMPLES NUM CHUNKS NUM SERIES SIZE
01FD7J9QW40GF1YSSZR8BTBJV6 1629115842635 1629116635334 13m12.699s 2370 30 30 13931
3.部署thanos query
thanos query \
--http-address "127.0.0.1:9091" \
--store "127.0.0.1:10907"
- 浏览器访问:127.0.0.1:9091 可以看见查询界面
- 注意:
神坑——- 发送的数据要足够多
- 发送的时间要足够长
- 我的客户端发送了约两分钟后,才看见数据
- 输入:
metric_of_ahfu_1, 可以看见客户端工具上报的数据。
【笔记】macos上部署thanos_receiver + thanos_query的更多相关文章
- Solr学习笔记-在Tomcat上部署执行Solr
上一篇我们初识了Solr而且学习了Jetty的启动方式.查看了Solr的管理界面,这一篇我们来实如今Tomcat上部署执行Solr. 部署环境: window7 jdk1.6.0_14 Solr-4. ...
- Dubbo入门到精通学习笔记(二):Dubbo管理控制台、使用Maven构建Dubbo的jar包、在Linux上部署Dubbo privider服务(shell脚本)、部署consumer服务
文章目录 Dubbo管理控制台 1.Dubbo管理控制台的主要作用: 2.管理控制台主要包含: 3.管理控制台版本: 安装 Dubbo 管理控制台 使用Maven构建Dubbo服务的可执行jar包 D ...
- docker4dotnet #3 在macOS上使用Visual Studio Code和Docker开发asp.net core和mysql应用
.net猿遇到了小鲸鱼,觉得越来越兴奋.本来.net猿只是在透过家里那田子窗看外面的世界,但是看着海峡对岸的苹果园越来越茂盛,实在不想再去做一只宅猿了.于是,.net猿决定搭上小鲸鱼的渡轮到苹果园去看 ...
- ASP.NET Core 中文文档 第二章 指南(1)用 Visual Studio Code 在 macOS 上创建首个 ASP.NET Core 应用程序
原文:Your First ASP.NET Core Application on a Mac Using Visual Studio Code 作者:Daniel Roth.Steve Smith ...
- (转)ZooKeeper 笔记(1) 安装部署及hello world
ZooKeeper 笔记(1) 安装部署及hello world 先给一堆学习文档,方便以后查看 官网文档地址大全: OverView(概述) http://zookeeper.apache.or ...
- ActionBarSherlock学习笔记 第一篇——部署
ActionBarSherlock学习笔记 第一篇--部署 ActionBarSherlock是JakeWharton编写的一个开源框架,使用这个框架,可以实现在所有的Android ...
- OGG学习笔记04-OGG复制部署快速参考
OGG学习笔记04-OGG复制部署快速参考 源端:Oracle 10.2.0.5 RAC + ASM 节点1 Public IP地址:192.168.1.27 目标端:Oracle 10.2.0.5 ...
- 《Maven实战》笔记-8-构建部署Web项目
一.Web项目结构 1.显式指定Web项目打包方式为war: 2.默认目录 根据“约定大于配置”的规则,Web项目的类及资源文件默认位置为src/main/java和src/main/reso ...
- 在Nginx上部署ThinkPHP,解决Pathinfo问题
在Nginx上部署ThinkPHP,解决Pathinfo问题 事实上.要解决nginx不支持pathinfo的问题.有两个解决思路,一是不使用pathinfo模式,二是改动nginx的配置文件,使它支 ...
随机推荐
- Tornado.web.Application之-settings
应用程序配置 class tornado.web.Application(handlers:List [Union [Rule,Tuple]] = None,default_host:str = N ...
- 使用mysql查询语句统计数据,如果是null值则赋值为0
select IFNULL(sum(total_view),0) from 如果统计total_view这列为null ,则返回默认值0
- tomcat startup.bat 启动中文显示乱码
打开tomcat文件夹到conf目录下 修改logging.properties 找到 java.util.logging.ConsoleHandler.encoding = utf-8这行 更改为 ...
- 【LeetCode】1432. 改变一个整数能得到的最大差值 Max Difference You Can Get From Changing an Integer
作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 暴力 日期 题目地址:https://leetcode ...
- 【LeetCode】933. Number of Recent Calls 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 二分查找 队列 相似题目 参考资料 日期 题目地址: ...
- 【LeetCode】771. Jewels and Stones 解题报告
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述: 题目大意 解题方法 数组count 字典Counter 日期 题目地址 ...
- 【LeetCode】537. Complex Number Multiplication 解题报告(Python & C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 解题方法 日期 题目地址:https://leetcode.com/pr ...
- Interesting Fibonacci(hdu 2814)
Interesting Fibonacci Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Ot ...
- idea使用教程-idea简介
集成开发环境(IDE,Integrated Development Environment )是用于提供程序开发环境的应用程序,一般包括代码编辑器.编译器.调试器和图形用户界面等工具.集成了代码编写功 ...
- Git reflog 引用日志使用详解
本章节主要介绍 git reflog 命令. Git 使用一种称为引用日志或"reflogs"的机制来跟踪分支顶端的更新. 许多 Git 命令接受用于指定引用或"ref& ...