ETCD监控
2024-09-03 12:32:14
Watch key changes
Applications can watch on a key or a range of keys to monitor for any updates.
Here is the command to watch on key foo
:
$ etcdctl watch foo
# in another terminal: etcdctl put foo bar
PUT
foo
bar
Here is the command to watch on key foo
in hex format:
$ etcdctl watch foo --hex
# in another terminal: etcdctl put foo bar
PUT
\x66\x6f\x6f # Key
\x62\x61\x72 # Value
Here is the command to watch on a range key from foo
to foo9
:
$ etcdctl watch foo foo9
# in another terminal: etcdctl put foo bar
PUT
foo
bar
# in another terminal: etcdctl put foo1 bar1
PUT
foo1
bar1
Here is the command to watch on keys having prefix foo
:
$ etcdctl watch --prefix foo
# in another terminal: etcdctl put foo bar
PUT
foo
bar
# in another terminal: etcdctl put fooz1 barz1
PUT
fooz1
barz1
Here is the command to watch on multiple keys foo
and zoo
:
$ etcdctl watch -i
$ watch foo
$ watch zoo
# in another terminal: etcdctl put foo bar
PUT
foo
bar
# in another terminal: etcdctl put zoo val
PUT
zoo
val 监控历史版本变化,为了解决监控期间故障,保证数据更新不会丢失
Suppose we finished the following sequence of operations:
$ etcdctl put foo bar # revision = 2
OK
$ etcdctl put foo1 bar1 # revision = 3
OK
$ etcdctl put foo bar_new # revision = 4
OK
$ etcdctl put foo1 bar1_new # revision = 5
OK
# watch for changes on key `foo` since revision 2
$ etcdctl watch --rev=2 foo
PUT
foo
bar
PUT
foo
bar_new
# watch for changes on key `foo` since revision 3
$ etcdctl watch --rev=3 foo
PUT
foo
bar_new
$ etcdctl watch --prev-kv foo=====最近的修改前和修改后
# in another terminal: etcdctl put foo bar_latest
PUT
foo # key
bar_new # last value of foo key before modification
foo # key
bar_latest # value of foo key after modification 版本压缩
$ etcdctl compact 5
compacted revision 5 # any revisions before the compacted one are not accessible
$ etcdctl get --rev=4 foo
Error: rpc error: code = 11 desc = etcdserver: mvcc: required revision has been compacted 授予租约
# grant a lease with 10 second TTL
$ etcdctl lease grant 10
lease 32695410dcc0ca06 granted with TTL(10s) # attach key foo to lease 32695410dcc0ca06
$ etcdctl put --lease=32695410dcc0ca06 foo bar
OK
Suppose we finished the following sequence of operations:
$ etcdctl lease grant 10
lease 32695410dcc0ca06 granted with TTL(10s)
$ etcdctl put --lease=32695410dcc0ca06 foo bar
OK 取消租约会删除所有附加的KEY
Here is the command to revoke the same lease:
$ etcdctl lease revoke 32695410dcc0ca06
lease 32695410dcc0ca06 revoked $ etcdctl get foo
# empty response since foo is deleted due to lease revocation
查看租约信息
# grant a lease with 500 second TTL
$ etcdctl lease grant 500
lease 694d5765fc71500b granted with TTL(500s) # attach key zoo1 to lease 694d5765fc71500b
$ etcdctl put zoo1 val1 --lease=694d5765fc71500b
OK # attach key zoo2 to lease 694d5765fc71500b
$ etcdctl put zoo2 val2 --lease=694d5765fc71500b
OK
Here is the command to get information about the lease:
$ etcdctl lease timetolive 694d5765fc71500b
lease 694d5765fc71500b granted with TTL(500s), remaining(258s)
Here is the command to get information about the lease along with the keys attached with the lease:
$ etcdctl lease timetolive --keys 694d5765fc71500b
lease 694d5765fc71500b granted with TTL(500s), remaining(132s), attached keys([zoo2 zoo1])
最新文章
- VUE --- 给页面加点网络动态数据
- hibernate----N-N--(人与地点)
- org.eclipse.ui.menus扩展点学习
- 程序员之路:以Android证道
- 2015年第2本(英文第1本):《The Practice of Programming》
- VPS常用工具
- ServerMediaSession::generateSDPDescription分析
- 获取客户端ip并用正则表达式验证
- C++面向对象设计
- win7局域网无法ping通本机的问题解决方法
- Javascript日期处理类库Moment.js
- linux下单独安装oracle12.1客户端
- Linux C 简易聊天室
- Linux实战教学笔记10:正则表达式
- php+redis实现电商秒杀功能
- 【Markdown 语法】
- easyui的下拉框combox动态复赋值显示在前端
- 周鸿祎IOT发布会思考
- 浏览器根对象document之字符串属性
- Why provision Bare Metal
热门文章
- 使用命令行生成动态库dll
- eclipse快速创建一个Spring Boot应用
- Linux - Shell - find - 基础
- 转载:reverb
- vue工程 使用滚动组件 vue2-better-scroll 实现上拉加载 下拉刷新
- C语言随笔4:指针数组、数组指针
- Eugeny and Array(思维)
- [LeetCode]1.Two Sum 两数之和&;&;第一次刷题感想
- Docker - 周边 - Go Template
- Codeforces Round #613 (Div. 2)D(贪心,分治)