Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- # The psycopg you installed through apt-get is not visible from inside the virtual env.
- # You should install it through pip
- # pip install psycopg2
- # after sourcing your environment.
- import psycopg2
- # start docker
- #docker run --name some-postgres -e POSTGRES_PASSWORD=geslo -e POSTGRES_USERNAME=tomaz -e POSTGRES_DB=tomaz -p 5432:5432 -d postgres
- try:
- fh = open('test.conf', 'w')
- except:
- print("Can't open a file for writing")
- try:
- conn = psycopg2.connect("dbname='tomazrazvoj' user='tomaz' host='127.0.0.1' password='tomaz'")
- except:
- print("Unable to connect to database")
- cur = conn.cursor()
- cur.execute("""select datname from pg_database where datistemplate=false""")
- rows = cur.fetchall()
- document = """
- # This is the monitoring configuration for PostgreSQL.
- # Make sure the statistics collector is enabled in your PostgreSQL configuration.
- # NOTE: This configuration needs to be hand-edited in order to work.
- # Look for DATABASE_NAME, STATS_USER, STATS_PASS, POSTGRESQL_HOST and POSTGRESQL_PORT to adjust your configuration file.
- LoadPlugin postgresql
- <Plugin "postgresql">
- # Each database needs a separate Database section.
- # Replace DATABASE_NAME in the Database section with the name of the database."""
- for row in rows:
- document += """
- <Database "{name}">
- # Host and port are only used for TCP/IP connections.
- # Leaving them out indicates you wish to connect via domain sockets.
- # When using non-standard PostgreSQL configurations, replace the below with
- ##Host "POSTGRESQL_HOST"
- ##Port "POSTGRESQL_PORT"
- Host "127.0.0.1"
- Port "5432"
- User "{name}"
- Password "{name}1337"
- Query backends
- Query transactions
- Query queries
- Query table_states
- Query disk_io
- Query disk_usage
- </Database>\n""".format(name=row[0])
- document += "</Plugin>"
- fh.write(document)
- conn.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement