鼎鼎知识库
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

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

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