InfluxDB添加新服务
操作系统 : CentOS7.3.1611_x64
go语言版本:1.8.3 linux/amd64
InfluxDB版本:1.1.0
这里以添加 syncd 服务为例记录下InfluxDB添加新服务的流程。
添加主服务代码
在 influxdata/influxdb/services 目录建立 syncd 文件夹,用于存放 syncd 服务相关代码。
1、添加服务配置相关内容
添加 config.go 文件,示例内容如下:
package syncd
// E-Mail : Mike_Zhang@live.com
type Config struct {
Enabled bool `toml:"enabled"`
LogEnabled bool `toml:"log-enabled"`
RemoteTSDBHost string `toml:"remote-host"`
DefaultDB string `toml:"defaultDB"`
} func NewConfig() Config {
return Config{
Enabled: true,
LogEnabled: true,
RemoteTSDBHost: "http://127.0.0.1:8086",
DefaultDB: "Monitor",
}
}
解释如下:
- 定义 Config 用于存放具体配置;
- 添加 NewConfig 函数,用于创建 Config 对象;
2、添加 syncd 服务的具体内容
添加 syncd.go 文件,示例内容如下:
package syncd
// E-Mail : Mike_Zhang@live.com
import (
"log"
"os"
"time"
) type Service struct {
Logger *log.Logger
remote_host string
DefaultDB string
username string
password string
} func NewService(c Config) *Service {
return &Service{
remote_host: c.RemoteTSDBHost,
DefaultDB: c.DefaultDB,
username: "root",
password: "root",
Logger: log.New(os.Stderr, "[syncd] ", log.LstdFlags),
}
} func (s *Service) Run() {
for {
cur_time := time.Now().Unix()
s.Logger.Printf("current timestamp : %d\n", cur_time)
time.Sleep( * time.Second)
}
}
解释如下: * 定义Service结构;
- 添加 NewService 函数,用于创建具体服务;
- 添加 Run 函数,实现具体服务
该函数作为入口实现具体的服务,这里以在日志中定时打印时间戳作为具体的服务内容。
在服务器主程序中启动服务
1、添加配置相关代码
进入 influxdata/influxdb/cmd/influxd 目录,修改 run/config.go 文件。
- 引入 syncd 服务
在 import 中加入如下代码:
"github.com/influxdata/influxdb/services/syncd"
- 定义配置
在 Config 结构中加入如下变量:
SyncdConfig syncd.Config `toml:"syncd"`
- 初始化配置
在 NewConfig 函数中加入如下代码:
c.SyncdConfig = syncd.NewConfig()
使用 git diff 命令查看如下 :
[root@localhost run]# git diff config.go
diff --git a/cmd/influxd/run/config.go b/cmd/influxd/run/config.go
index 36e4f14..01df0cc
--- a/cmd/influxd/run/config.go
+++ b/cmd/influxd/run/config.go
@@ -, +, @@ import (
"github.com/influxdata/influxdb/services/precreator"
"github.com/influxdata/influxdb/services/retention"
"github.com/influxdata/influxdb/services/subscriber"
+ "github.com/influxdata/influxdb/services/syncd"
"github.com/influxdata/influxdb/services/udp"
"github.com/influxdata/influxdb/tsdb"
)
@@ -, +, @@ type Config struct {
Monitor monitor.Config `toml:"monitor"`
Subscriber subscriber.Config `toml:"subscriber"`
HTTPD httpd.Config `toml:"http"`
+ SyncdConfig syncd.Config `toml:"syncd"`
GraphiteInputs []graphite.Config `toml:"graphite"`
CollectdInputs []collectd.Config `toml:"collectd"`
OpenTSDBInputs []opentsdb.Config `toml:"opentsdb"`
@@ -, +, @@ func NewConfig() *Config {
c.Retention = retention.NewConfig()
c.BindAddress = DefaultBindAddress + c.SyncdConfig = syncd.NewConfig()
return c
} [root@localhost run]#
2、添加启动服务代码
进入 influxdata/influxdb/cmd/influxd 目录,修改 run/command.go 文件
- 引入 syncd 服务
在 import 中加入如下代码:
"github.com/influxdata/influxdb/services/syncd"
- 添加启动代码
在 Command->Run 函数中加入如下代码(go cmd.monitorServerErrors() 之前):
// start syncd
syncdInstance := syncd.NewService(config.SyncdConfig)
go syncdInstance.Run()
在 Config 结构中加入如下变量:
使用 git diff 命令查看如下 :
[root@localhost run]# git diff command.go
diff --git a/cmd/influxd/run/command.go b/cmd/influxd/run/command.go
index 51036f1..8743f04
--- a/cmd/influxd/run/command.go
+++ b/cmd/influxd/run/command.go
@@ -, +, @@
package run import (
+ "github.com/influxdata/influxdb/services/syncd"
"flag"
"fmt"
"io"
@@ -, +, @@ func (cmd *Command) Run(args ...string) error {
}
cmd.Server = s + // start syncd
+ syncdInstance := syncd.NewService(config.SyncdConfig)
+ go syncdInstance.Run()
+
+
// Begin monitoring the server's error channel.
go cmd.monitorServerErrors() [root@localhost run]#
测试服务
进入 influxdata/influxdb/cmd/influxd 目录,执行 go build 命令,并将编译好的二进制文件copy到bin目录,具体如下:
[root@localhost influxd]# go build
[root@localhost influxd]# cp influxd /usr/bin/
cp: overwrite ‘/usr/bin/influxd’? y
[root@localhost influxd]#
启动InfluxDB服务器,在控制台可以看到如下内容:
[root@localhost influxdb]# influxd
.d888 8888888b. 888888b.
d88P" 888 888 "Y88b "88b
.88P
88888b. 8888888K.
"88b 888 888 888 888 Y8bd8P' 888 888 888 "Y88b
X88K
Y88b .d8""8b. .d88P d88P
"Y88888 888 888 8888888P" 8888888P"
[run] // :: InfluxDB starting, version unknown, branch unknown, commit unknown
[run] // :: Go version go1.8.3, GOMAXPROCS set to
[run] // :: Using configuration at: /etc/influxdb/influxdb.conf
[store] // :: Using data dir: /var/lib/influxdb/data
...
[syncd] // :: current timestamp :
[syncd] // :: current timestamp :
[syncd] // :: current timestamp :
生成新的配置文件:
influxd config > new.conf
可以看到 syncd 服务默认配置如下:
[syncd]
enabled = true
log-enabled = true
remote-host = "http://127.0.0.1:8086"
defaultDB = "Monitor"
好,就这些了,希望对你有帮助。
本文github地址:
https://github.com/mike-zhang/mikeBlogEssays/blob/master/2018/20180210_InfluxDB添加新服务.rst
欢迎补充
InfluxDB添加新服务的更多相关文章
- Ambari中添加新服务
官网: https://cwiki.apache.org/confluence/pages/viewpage.action?pageId=38571133 一.背景 栈的定义可以在源代码树中找到/am ...
- Dos命令删除添加新服务
安装服务sc create Svnservice binpath= "d:\subversion\bin\svnserve.exe --service -r E:\projectversio ...
- 添加ssh服务构建新镜像-docker commit 方式01
添加ssh服务构建新镜像-docker commit 方式 1:docker commit构建自定义镜像---一般不推荐使用这种方式构建新镜像 1:ubuntu基础镜像下载 ubuntu@ubuntu ...
- 【PostgreSQL】PostgreSQL添加新服务器连接时,报错“Server doesn't listen ”,已解决。
PostgreSQL添加新的服务器连接时,报错:
- 如何手动添加Windows服务和如何把一个服务删除
windows 手动添加服务方法一:修改注册表 在注册表编辑器,展开分支"HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services" ...
- 向CDH5集群中添加新的主机节点
向CDH5集群中添加新的主机节点 步骤一:首先得在新的主机环境中安装JDK,关闭防火墙.修改selinux.NTP时钟与主机同步.修改hosts.与主机配置ssh免密码登录.保证安装好了perl和py ...
- WebKit JavaScript Binding添加新DOM对象的三种方式
一.基础知识 首先WebKit IDL并非完全遵循Web IDL,只是借鉴使用.WebKit官网提供了一份说明(WebKitIDL),比如Web IDL称"operation”(操作), 而 ...
- TIA Portal V12不能添加新的CPU
4核AMD 740,10G内存,Win7 X64,打开TIA Portal V12,依旧慢如牛,鼠标指针转啊转,TIA窗口写着 无响应... 真没志气,STM32要是玩转了,坚决不用这老牛. 上图为正 ...
- 为镜像添加SSH服务
操作Docker容器介绍了一些进入容器的办法,比如attach.exec等命令,但是这些命令都无法解决远程管理容器的问题.因此,当需要远程登录到容器内进行一些操作的时候,就需要SSH的支持了. 如何自 ...
随机推荐
- LeetCode 20. 有效的括号( 括号配对 )
给定一个只包括 '(',')','{','}','[',']' 的字符串,判断字符串是否有效. 有效字符串需满足: 左括号必须用相同类型的右括号闭合. 左括号必须以正确的顺序闭合. 注意空字符串可被认 ...
- 无法启动 Maya 集成的 qt designer 的解决方法和原因 以及 中英文切换
无法启动 Maya 集成的 qt designer 的解决方法和原因 以及 中英文切换 前言: Maya 集成了 PySide,同时集成了qt designer,在 Maya 的安装目录下的 bin ...
- 进程用manager 和Queue 实现进程消费者生产者
注意 : mgr = multiprocessing.Manager() 生成了一个守护进程,如果主进程完毕,mgr这个实例也没有了,所以在结尾加了mgr.join()才能运行 代码: import ...
- JAVA基础中的注意点(一)
1.标识符 标识符:标识某些事物用于区分的符号. (即区分某些事物的符号) 四条硬性规定: a.不能是 关键字.true.false.null. b.可以包含 字母.数字(0-9).下划线(_)或美 ...
- Strange Towers of Hanoi POJ - 1958(递推)
题意:就是让你求出4个塔的汉诺塔的最小移动步数,(1 <= n <= 12) 那么我们知道3个塔的汉诺塔问题的解为:d[n] = 2*d[n-1] + 1 ,可以解释为把n-1个圆盘移动到 ...
- a标签下划线
页面中有一处box中的a标签都被加上了下划线,查找元素却没有找到css中的underline. 原因是 <a>标签默认是有下划线的,而一般看到的<a>标签链接中的下划线都被覆盖 ...
- MD5_Util工具类代码
package com.yby.mall.utils; import java.math.BigInteger; import java.security.MessageDigest; public ...
- shell编程第五天
- O(1) long long a*b%p
inline ll muc(ll n,ll m){n%=p,m%=p;return (n*m-(ll)((long double)n*m/p)*p+p)%p;}
- 英语口语练习系列-C27-艺术品-辨别物体-黄昏的歌
艺术品 a work of art Theory talent art gallery draw the sketch motivate students' interest full of imag ...