0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

influxdbをお試し利用

Last updated at Posted at 2020-05-10

目的

influxdbをお試し利用した際の備忘録です

準備

以下を参考にDockerをインストールする

MacBookでDockerを用いてwebサーバを立てる練習をする(Mac + Docker + PHP + Apache)
Dockerの開発環境構築 (Mac + Docker + PHP + Apache)

influxdbの起動

$ docker run -d -p 8083:8083 -p 8086:8086 -p 8090:8090 -p 8099:8099 influxdb
Unable to find image 'influxdb:latest' locally
latest: Pulling from library/influxdb
99760bc62448: Pull complete 
e3fa264a7a88: Pull complete 
a222a2af289f: Pull complete 
8765a3c7874a: Pull complete 
01e00e492310: Pull complete 
0d251e625d04: Pull complete 
d34a9a8c60e0: Pull complete 
c8a7cfaa1936: Pull complete 
Digest: sha256:42f362a7bc74e7aef7b26901f5dd37ec2ba59559a6cc629beae7497694656be6
Status: Downloaded newer image for influxdb:latest
5bf16c05b197736352a61aca2025a270bc800dee9f028680d77649df83e8ad67
$ docker ps
CONTAINER ID        IMAGE                                                 COMMAND                  CREATED             STATUS              PORTS                                                                                            NAMES
5bf16c05b197        influxdb                                              "/entrypoint.sh infl…"   8 minutes ago       Up 8 minutes        0.0.0.0:8083->8083/tcp, 0.0.0.0:8086->8086/tcp, 0.0.0.0:8090->8090/tcp, 0.0.0.0:8099->8099/tcp   tender_ride

mydb を作成

curl -G http://localhost:8086/query --data-urlencode "q=CREATE DATABASE mydb"

値をWRITEする

$ curl -i -XPOST http://localhost:8086/write?db=mydb --data-binary "temperature,machine=unit42,type=assembly external=90,internal=60"
HTTP/1.1 204 No Content
Content-Type: application/json
Request-Id: 0a60c0c4-929b-11ea-8017-0242ac110003
X-Influxdb-Build: OSS
X-Influxdb-Version: 1.8.0
X-Request-Id: 0a60c0c4-929b-11ea-8017-0242ac110003
Date: Sun, 10 May 2020 08:48:38 GMT

値をGETする

$ curl -G http://localhost:8086/query?db=mydb --data-urlencode "q=SELECT * FROM temperature"
{"results":[{"statement_id":0,"series":[{"name":"temperature","columns":["time","external","internal","machine","type"],"values":[["2020-05-10T08:40:46.2789346Z",90,60,"unit42","assembly"],["2020-05-10T08:40:58.3198991Z",90,60,"unit42","assembly"]]}]}]}

整形してみやすくできる

$ curl -G 'http://localhost:8086/query?pretty=true' --data-urlencode "db=mydb" --data-urlencode "q=SELECT * FROM temperature"
{
    "results": [
        {
            "statement_id": 0,
            "series": [
                {
                    "name": "temperature",
                    "columns": [
                        "time",
                        "external",
                        "internal",
                        "machine",
                        "type"
                    ],
                    "values": [
                        [
                            "2020-05-10T08:40:46.2789346Z",
                            90,
                            60,
                            "unit42",
                            "assembly"
                        ],
                        [
                            "2020-05-10T08:40:58.3198991Z",
                            90,
                            60,
                            "unit42",
                            "assembly"
                        ],
                        [
                            "2020-05-10T08:48:37.9922405Z",
                            90,
                            60,
                            "unit42",
                            "assembly"
                        ]
                    ]
                }
            ]
        }
    ]
}

(参考)Dockerコンテナ内からmydbを作成する場合

docker exec -it (コンテナ名) /bin/bash でコンテナ内のinfluxを直接実行する

$ docker ps
CONTAINER ID        IMAGE                                                 COMMAND                  CREATED             STATUS              PORTS                                                                                            NAMES
5bf16c05b197        influxdb                                              "/entrypoint.sh infl…"   8 minutes ago       Up 8 minutes        0.0.0.0:8083->8083/tcp, 0.0.0.0:8086->8086/tcp, 0.0.0.0:8090->8090/tcp, 0.0.0.0:8099->8099/tcp   tender_ride
$ docker exec -it tender_ride /bin/bash
# find / -name influx
/usr/bin/influx
# /usr/bin/influx
Connected to http://localhost:8086 version 1.8.0
InfluxDB shell version: 1.8.0
> SHOW DATABASES
name: databases
name
----
_internal
> CREATE DATABASE mydb
> SHOW DATABASES
name: databases
name
----
_internal
mydb
> exit

(参考)Dockerコンテナ内から値をGETする場合

以下のようにコマンドを実行する

> USE mydb
Using database mydb
> SELECT * FROM temperature
name: temperature
time                external internal machine type
----                -------- -------- ------- ----
1589100046278934600 90       60       unit42  assembly
1589100058319899100 90       60       unit42  assembly

(参考)Dockerコンテナ内からDBのユーザを作成する場合

USER/PASS=test/test のadminユーザを作成する場合

> CREATE USER test WITH PASSWORD 'test' WITH ALL PRIVILEGES
> SHOW USERS
user   admin
----   -----
test   true

InfluxDBの8083ポートにhttpアクセスできない

InfluxDBの8083ポートにhttpアクセスできない

デフォルトで8083ポートで可視化や管理等できる画面が立ち上がると聞いていたのですが、 バージョン1.3.0からなくなったようです。

参考

github.com/influxdata/influxdb
influxdbのコマンドメモ
手軽にシステムダッシュボードが作れる「Grafana」レビュー
MacBookでDockerを用いてwebサーバを立てる練習をする(Mac + Docker + PHP + Apache)
Dockerの開発環境構築 (Mac + Docker + PHP + Apache)
InfluxDB インストール - 簡単な使い方
influxdbのコマンドメモ

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?