鼎鼎知识库
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

12.阿里云InfluxDB使用.md 5.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. > 连接数据库
  2. 普通连接数据库:
  3. ```
  4. ./influx -ssl -username influxuser -password user@influxDB -host ts-uf60ncdtuve8d41w3.influxdata.rds.aliyuncs.com -port 3242
  5. ```
  6. 以json展示:
  7. ```
  8. ./influx -ssl -username influxuser -password user@influxDB -host ts-uf60ncdtuve8d41w3.influxdata.rds.aliyuncs.com -port 3242 -format=json
  9. ```
  10. json以美观的方式展示
  11. ```
  12. ./influx -ssl -username influxuser -password user@influxDB -host ts-uf60ncdtuve8d41w3.influxdata.rds.aliyuncs.com -port 3242 -format=json -pretty
  13. ```
  14. > 使用数据库
  15. ```
  16. use dingding_influx
  17. show measurements
  18. ```
  19. > 新建measurement
  20. ```
  21. 创建名称是cpu的measurement:
  22. INSERT cpu,host=serverA,region=us_west value=0.64
  23. select host, region, value from cpu
  24. 创建名称是temperature的measurement:
  25. INSERT temperature,machine=unit42,type=assembly external=25,internal=37
  26. select * from temperature
  27. ```
  28. > 删除measurement
  29. 删除measurement需要管理员权限
  30. ```
  31. drop measurement cpu
  32. ```
  33. > 通过Postman请求数据
  34. 请求
  35. ```
  36. POST https://ts-uf60ncdtuve8d41w3.influxdata.rds.aliyuncs.com:3242/query?u=influxuser&p=user@influxDB
  37. Headers: Content-Type application/x-www-form-urlencoded
  38. Body:
  39. db=dingding_influx
  40. q=select host, region, value from cpu
  41. ```
  42. 请求成功返回
  43. ```
  44. {
  45. "results": [
  46. {
  47. "statement_id": 0,
  48. "series": [
  49. {
  50. "name": "cpu",
  51. "columns": [
  52. "time",
  53. "host",
  54. "region",
  55. "value"
  56. ],
  57. "values": [
  58. [
  59. "2019-07-26T08:58:21.438818256Z",
  60. "serverA",
  61. "us_west",
  62. 0.64
  63. ]
  64. ]
  65. }
  66. ]
  67. }
  68. ]
  69. }
  70. ```
  71. 如果请求没有的measurement返回
  72. ```
  73. {
  74. "results": [
  75. {
  76. "statement_id": 0
  77. }
  78. ]
  79. }
  80. ```
  81. 如果用户名错误、密码错误、用户名和密码同时错误返回
  82. ```
  83. {
  84. "error": "authorization failed"
  85. }
  86. ```
  87. 如果数据库错误
  88. ```
  89. {
  90. "error": "error authorizing query: influxuser not authorized to execute statement 'SELECT host, region, value FROM cpu', requires READ on dingding_influ"
  91. }
  92. ```
  93. 如果请求meaasurement中没有的字段,比如`select hos, region, value from cpu`返回
  94. ```
  95. {
  96. "results": [
  97. {
  98. "statement_id": 0,
  99. "series": [
  100. {
  101. "name": "cpu",
  102. "columns": [
  103. "time",
  104. "hos",
  105. "region",
  106. "value"
  107. ],
  108. "values": [
  109. [
  110. "2019-07-26T08:58:21.438818256Z",
  111. null,
  112. "us_west",
  113. 0.64
  114. ]
  115. ]
  116. }
  117. ]
  118. }
  119. ]
  120. }
  121. ```
  122. 如果q值为空返回
  123. ```
  124. {
  125. "error": "missing required parameter \"q\""
  126. }
  127. ```
  128. **时间戳格式**
  129. 默认数据的时间格式是UTC,编码是RFC3339, 例如`2015-08-04T19:05:14.318570484Z`, 如果想反悔Unix格式,使用`epoch`字段。
  130. ```
  131. epoch=h,m,s,ms,u,ns
  132. ```
  133. **分块Chunking**
  134. 默认分块的数量是10000个数据据点,如果想改变分块大小,通过`chunked`和`chunk_size`设置。
  135. ```
  136. chunked=true
  137. chunk_size=20000
  138. ```
  139. > Postman写入数据
  140. 内部是以二进制方式写入数据。阿里云时序数据库API默认的写入时间是在5秒之内,如果一次性写入过多的数据,写入时间超过5秒,就不保证所有数据都被写入。所以当数据点比较多,比如有5000个数据点,需要把数据拆分。
  141. 单点写入数据点
  142. ```
  143. POST https://ts-uf60ncdtuve8d41w3.influxdata.rds.aliyuncs.com:3242/write?db=dingding_influx&u=influxuser&p=user@influxDB
  144. Body: cpu_load_short,host=server01,region=us-west value=0.64 1434055562000000000
  145. ```
  146. 返回类型是204(No Content)。
  147. 多点写入数据点(没有成功)
  148. ```
  149. POST https://ts-uf60ncdtuve8d41w3.influxdata.rds.aliyuncs.com:3242/write?db=dingding_influx&u=influxuser&p=user@influxDB
  150. Body:
  151. cpu_load_short,host=server02,region=us-west value=0.55 1422568543702900257
  152. cpu_load_short,direction=in,host=server01,region=us-west value=2.0 1422568543702900257'
  153. ```
  154. > 故障排除
  155. 使用浏览器打开。
  156. ```
  157. 总览页:
  158. https://ts-uf60ncdtuve8d41w3.influxdata.rds.aliyuncs.com:3242/debug/pprof?u=influxuser&p=user@influxDB
  159. https://ts-uf60ncdtuve8d41w3.influxdata.rds.aliyuncs.com:3242/debug/pprof/goroutine?u=influxuser&p=user@influxDB
  160. https://ts-uf60ncdtuve8d41w3.influxdata.rds.aliyuncs.com:3242/debug/pprof/heap?u=influxuser&p=user@influxDB
  161. https://ts-uf60ncdtuve8d41w3.influxdata.rds.aliyuncs.com:3242/debug/pprof/mutex?u=influxuser&p=user@influxDB
  162. https://ts-uf60ncdtuve8d41w3.influxdata.rds.aliyuncs.com:3242/debug/pprof/threadcreate?u=influxuser&p=user@influxDB
  163. ```
  164. > 跟踪请求
  165. ```
  166. 默认跟踪10秒内的请求:
  167. https://ts-uf60ncdtuve8d41w3.influxdata.rds.aliyuncs.com:3242/debug/requests?u=influxuser&p=user@influxDB
  168. 跟踪1分钟内的请求:
  169. https://ts-uf60ncdtuve8d41w3.influxdata.rds.aliyuncs.com:3242/debug/requests?seconds=60&u=influxuser&p=user@influxDB
  170. ```
  171. > 运行时的统计信息
  172. 使用/ping检查TSDB For InfluxDB®实例的状态和TSDB For InfluxDB®的版本。使用Postman请求。
  173. ```
  174. GET https://ts-uf60ncdtuve8d41w3.influxdata.rds.aliyuncs.com:3242/ping?u=influxuser&p=user@influxDB
  175. 返回204 在Headers里面有版本信息
  176. ```