0

If I run the following command in InfluxDB I get a decent response :

influx -database database_metrics -execute "SELECT last("slave_slave_io_running") FROM "mysql" WHERE ("time" > now() - 60m)"

But If I try to scrape the output from the terminal using a python script I get the following error:

[‘Visit https://enterprise.influxdata.com to register for updates, InfluxDB server management, and monitoring.’, ‘Connected to http://localhost:8086 version unknown’, ‘InfluxDB shell version: unknown’, ‘standard output is not a terminal’]
Finished

The code I wrote is as follows:

 out = subprocess.Popen([‘influx’,‘-database’,‘database_metrics’,' -execute’,‘\“SELECT last(\“slave_slave_io_running\“) FROM \“mysql\” WHERE (\“time\” > now() - 60m)\“’],stdout =subprocess.PIPE,stderr=subprocess.STDOUT)
 stdout,stderr = out.communicate()

    #get the lines and remove the empty lines
 lines = stdout.decode().split("\n")
 lines = [x for x in lines if x]
bad_coder
  • 11,289
  • 20
  • 44
  • 72
External
  • 23
  • 3
  • 1
    No knowing influx, I can't give an authoritative answer, but it looks to me that `influx` wants a terminal device. Perhaps there is an option for `influx` which makes its use stdout instead? Otherwise, you may use `pexpect`, as explained in the answer to [this](https://stackoverflow.com/questions/23668544/repeatedly-interacting-with-program-using-subprocess) question. – user1934428 Mar 07 '22 at 09:51
  • Just in case you might be interested I solved it and put it as an answer. Thanks for the help anyways ! @user1934428 – External Mar 07 '22 at 12:20

1 Answers1

0

Just in case anyone faces some similiar problem I managed to solve it in the following manner :


process = subprocess.Popen(["influx", "-database", "database_metrics"], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
stdout, stderr = process.communicate(input=b"select last(slave_slave_io_running) from mysql where (time > now() - 60s)")

Apparently the way how to pipeline the command changes there.

External
  • 23
  • 3