运维八一 运维八一
首页
运维杂记
编程浅尝
周积跬步
专栏
生活
关于
收藏
  • 分类
  • 标签
  • 归档
Source (opens new window)

运维八一

运维,运维!
首页
运维杂记
编程浅尝
周积跬步
专栏
生活
关于
收藏
  • 分类
  • 标签
  • 归档
Source (opens new window)
  • Devops笔记

  • Kubernetes

  • 运维监控系统

  • go分布式爬虫

  • Linux性能优化

  • 夜莺(nightingale)开源观测平台

    • 夜莺(nightingale)介绍
    • n9e 部署
    • Categraf 采集器部署
      • 1. 安装Categraf
      • 2. Categraf 主配置说明
    • VictoriaMetrics 时序库部署
    • 夜莺功能介绍
  • kubernetes-network-policy-recipes

  • 专栏
  • 夜莺(nightingale)开源观测平台
lyndon
2023-05-06
目录

Categraf 采集器部署

# 1. 安装Categraf

cd /opt
wget https://download.flashcat.cloud/categraf-v0.3.1-linux-amd64.tar.gz
tar xf categraf-v0.3.1-linux-amd64.tar.gz
mv categraf-v0.3.1-linux-amd64 categraf

cd categraf/conf/
cp categraf.service /etc/systemd/system/
systemctl daemon-reload
systemctl start categraf
1
2
3
4
5
6
7
8
9

github地址:https://github.com/flashcatcloud/categraf

categraf release包的命名规则遵循 {project}-{version}-{os}-{arch}.tar.gz (windows后缀是zip)

categraf-v0.2.36-linux-amd64.tar.gz 表示 categraf 的版本是 v0.2.36,运行在 linux 系统上,架构是 amd64。

categraf-v0.2.36-linux-amd64-with-cgo-plugin.tar.gz # 带 cgo 插件的版本,目前cgo插件有两个 oracle 和 arp 
categraf-v0.2.36-linux-amd64.tar.gz # linux + amd64  环境下运行的版本
categraf-v0.2.36-linux-arm64.tar.gz # linux + arm64  环境下运行的版本  
categraf-v0.2.36-windows-amd64.zip  # windows + amd64 环境下运行的版本
categraf-v0.2.36-windows-arm64.zip  # windows + arm64 环境下运行的版本
1
2
3
4
5

在目标机器部署,只需要 categraf 二进制、以及 conf 目录,conf 下有一个主配置文件:config.toml,定义机器名、全局采集频率、全局附加标签、remote write backend地址等;另外就是各种采集插件的配置目录,以input.打头,如果某个采集器 xx 不想启用,把 input.xx 改个其他前缀(或者删除这个目录),比如 bak.input.xx,categraf 就会忽略这个采集器。

linux systemd 托管 (推荐)

cp categraf.service /etc/systemd/system/
systemctl daemon-reload

# 以服务方式启动
systemctl start categraf

# 停止服务
systemctl stop categraf
1
2
3
4
5
6
7
8

windows 服务方式启动

# windows 安装服务
categraf.exe --win-service-install

# 启动服务
categraf.exe --win-service-start 

# 停止服务
categraf.exe --win-service-stop
1
2
3
4
5
6
7
8

windows 后台方式启动

# 后台启动
win_run.bat start   

# 停止后台进程
win_run.bat stop
1
2
3
4
5

注:以服务方式启动或者后台方式启动二选一(如果有session限制,需要以后台方式启动)

# 2. Categraf 主配置说明

categraf启动时 可以通过-configs参数指定配置目录,如果不指定,会默认读取工作目录下的conf。 conf 目录结构如下:

  • config.toml # 主配置
  • logs.toml # logs-agent 配置
  • prometheus.toml # prometheus agent 配置
  • traces.yaml # trace-agent 配置
  • conf/input.*/*.toml 插件配置文件

主配置config.toml说明

[global]
# 启动的时候是否在stdout中打印配置内容
print_configs = false

# 机器名,作为本机的唯一标识,会为时序数据自动附加一个 agent_hostname=$hostname 的标签
# hostname 配置如果为空,自动取本机的机器名
# hostname 配置如果不为空,就使用用户配置的内容作为hostname
# 用户配置的hostname字符串中,可以包含变量,目前支持两个变量,
# $hostname 和 $ip,如果字符串中出现这两个变量,就会自动替换
# $hostname 自动替换为本机机器名,$ip 自动替换为本机IP
# 建议大家使用 --test 做一下测试,看看输出的内容是否符合预期
# 这里配置的内容,再--test模式下,会显示为 agent_hostname=xxx 的标签 
hostname = ""


# 是否忽略主机名的标签,如果设置为true,时序数据中就不会自动附加agent_hostname=$hostname 的标签
omit_hostname = false

# 时序数据的时间戳使用ms还是s,默认是ms,是因为remote write协议使用ms作为时间戳的单位
precision = "ms"

# 全局采集频率,15秒采集一次
interval = 15

# 全局附加标签,一行一个,这些写的标签会自动附到时序数据上
# [global.labels]
# region = "shanghai"
# env = "localhost"

[log]
# 默认的log输出,到标准输出(stdout) 
# 如果指定为文件, 则写入到指定的文件中
file_name = "stdout"

# options below will not be work when file_name is stdout or stderr
# 如果是写入文件,最大写入大小,单位是MB
max_size = 100
# max_age is the maximum number of days to retain old log files based on the timestamp encoded in their filename.
# 保留多少天的日志文件
max_age = 1
# max_backups is the maximum number of old log files to retain.
# 保留多少个日志文件
max_backups = 1
# local_time determines if the time used for formatting the timestamps in backup files is the computer's local time.
# 是否使用本地时间
local_time = true
# Compress determines if the rotated log files should be compressed using gzip.
# 是否将老文件压缩(gzip格式)
compress = false

# 发给后端的时序数据,会先被扔到 categraf 内存队列里,每个采集插件一个队列
# chan_size 定义了队列最大长度
# batch 是每次从队列中取多少条,发送给后端backend
[writer_opt]
# default: 2000
batch = 2000
# channel(as queue) size
chan_size = 10000

# 后端backend配置,在toml中 [[]] 表示数组,所以可以配置多个writer
# 每个writer可以有不同的url,不同的basic auth信息
[[writers]]
# 注意端口号
# v5版本端口是19000
# v6版本端口是17000
url = "http://127.0.0.1:17000/prometheus/v1/write"

# Basic auth username
basic_auth_user = ""

# Basic auth password
basic_auth_pass = ""

# timeout settings, unit: ms
timeout = 5000
dial_timeout = 2500
max_idle_conns_per_host = 100

# 是否开启push gateway
[http]
enable = false
address = ":9100"
print_access = false
run_mode = "release"

# 是否启用告警自愈agent
[ibex]
enable = false
## ibex flush interval
interval = "1000ms"
## n9e ibex server rpc address
servers = ["127.0.0.1:20090"]
## temp script dir
meta_dir = "./meta"

# 心跳上报(附带资源信息,对象列表中使用)给夜莺v6
# 如果是v5版本,这里不需要保留
[heartbeat]
enable = true

# report os version cpu.util mem.util metadata
url = "http://127.0.0.1:17000/v1/n9e/heartbeat"

# interval, unit: s
interval = 10

# Basic auth username
basic_auth_user = ""

# Basic auth password
basic_auth_pass = ""

## Optional headers
# headers = ["X-From", "categraf", "X-Xyz", "abc"]

# timeout settings, unit: ms
timeout = 5000
dial_timeout = 2500
max_idle_conns_per_host = 100
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119

interval

每个插件的配置中,一开始通常都是 interval 配置,表示采集频率,如果这个配置注释掉了,就会复用 config.toml 中的采集频率,这个配置如果配置成数字,单位就是秒,如果配置成字符串,就要给出单位,比如:

interval = 60
interval = "60s"
interval = "1m"
1
2
3

上面三种写法,都表示采集频率是1分钟,如果是使用字符串,可以使用的单位有:

  • 秒:s
  • 分钟:m
  • 小时:h

instances

很多采集插件的配置中,都有 instances 配置段,用 [[]] 包住,说明是数组,即,可以出现多个 [[instances]] 配置段,比如 ping 监控的采集插件,想对4个IP做PING探测,可以按照下面的方式来配置:

[[instances]]
targets = [
    "www.baidu.com",
    "127.0.0.1",
    "10.4.5.6",
    "10.4.5.7"
]
1
2
3
4
5
6
7

也可以下面这样子配置:

[[instances]]
targets = [
    "www.baidu.com",
    "127.0.0.1"
]

[[instances]]
targets = [
    "10.4.5.6",
    "10.4.5.7"
]
1
2
3
4
5
6
7
8
9
10
11

interval_times

instances 下面如果有 interval_times 配置,表示 interval 的倍数,比如ping监控,有些地址采集频率是15秒,有些可能想采集的别太频繁,比如30秒,那就可以把interval配置成15,把不需要频繁采集的那些instances的interval_times配置成2

或者:把interval配置成5,需要15秒采集一次的那些instances的interval_times配置成3,需要30秒采集一次的那些instances的interval_times配置成6

labels

instances 下面的 labels 和 config.toml 中的 global.labels 的作用类似,只是生效范围不同,都是为时序数据附加标签,instances 下面的 labels 是附到对应的实例上,global.labels 是附到所有时序数据上

关于tls的配置

  use_tls = false
  tls_min_version = "1.2"
  tls_ca = "/etc/categraf/ca.pem"
  tls_cert = "/etc/categraf/cert.pem"
  tls_key = "/etc/categraf/key.pem"
  ## Use TLS but skip chain & host verification
  insecure_skip_verify = true
use_tls` 为true时,表示使用tls连接mysql。 如果正式是自签证书,想要避免 `X509: certificate signed by unknown authority` 错误,可以设置 `insecure_skip_verify = true
1
2
3
4
5
6
7
8

注意 目前的设计两个参数是共同起作用的,单独设置insecure_skip_verify = true无法避免 X509: certificate signed by unknown authority。

tls_min_version 表示支持的最小tls版本,可选值是1.0 1.1 1.2 1.3 分别对应 TLS1.0 到TLS1.3 。 SSLv3 不支持。

tls_ca tls_cert tls_key 分别是ca证书,客户端证书,客户端私钥。

上次更新: 2023/05/06, 15:12:23
n9e 部署
VictoriaMetrics 时序库部署

← n9e 部署 VictoriaMetrics 时序库部署→

最近更新
01
ctr和crictl显示镜像不一致
03-13
02
alpine镜像集成常用数据库客户端
03-13
03
create-cluster
02-26
更多文章>
Theme by Vdoing | Copyright © 2015-2024 op81.com
苏ICP备18041258号-2
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式