-
I need to run different queries against different databases. The databases are all running on the same server (MS SQL Server). I know I could explicitly include the DB name right in my raw SQL query (as a prefix to the table name that follows FROM), but that means I have to repeat it for every query. Not ideal if somebody else has the same databases, but they use different names--this is something the user can customize when installing the third-party product that creates the DBs. So what I'm trying to do, to keep things clean, is to create 3 config files: One for the common items (sql_exporter.yml), one defining all the queries that will run against DB1 (db1.yml) and the other defining the queries that will run against DB2 (db2.yml). These queries aren't interchangeable, meaning, DB1 and DB2 don't have the same schema; for all intents and purposes, they're completely separate databases. I thought I'd be able to define my sql_exporter.yml so it looks something like: global:
Then my DB1.yml should contain: collector_name: db1
And finally, DB2.yml should be very similar to DB1.yml, except for data_source_name having /?database set to the second DB, collector_name: being set to db2, and then the individual metrics. Couple of observations: It looks like the primary .yml file has to have a target: defined, it can't wait until it's defined in db1.yml or db2.yml. So I tried to define multiple target: entries, each with its unique name:, data_source_name: and collectors: values. But I'm then told there can only be a single target:. That's when I tried to move each target: to the secondary config files (one per DB), but no matter what I try, I always end up getting errors suggesting I'm not allowed to define some things like target: in DB1.yml and/or DB2.yml, or if I skip "target:" altogether, it doesn't know what data_source_name is (makes sense), etc. Surely this is feasible, and I tried everything I thought was intuitive...but I can't get this to work. And surely the solution is NOT to have two completely separate instances/copies of sql_exporter.exe each running in its own folder with a single target. Could I see sample config files that demonstrate how to do this? Again, to summarize, the goal is very simple: I need to run different queries against different databases, and I want to avoid duplicating the database names in each individual query. If a DB name changes, then ideally I only want to change it in one location, in the data_source_name. Thanks. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 10 replies
-
Edit: I found some prior discussions that seem to suggest splitting targets by job, so I tried this in my primary config file, but sql_exporter crashes: jobs:
The crash: ts=2024-10-17T19:28:07.920Z caller=klog.go:118 level=warn func=Warningf msg="Starting SQL exporter (version=0.15.0, branch=HEAD, revision=cb883e06441c462b41295361d6b71623bc957188) (go=go1.21.12, platform=windows/amd64, user=root@c031fda141fa, date=20240708-20:31:14, tags=netgo)" goroutine 1 [running]: |
Beta Was this translation helpful? Give feedback.
-
That's what I figured, and I did look at the code (job.go line 36) but I'm completely unfamiliar with Go and couldn't quite figure out from the loop what to try to structure differently to get it going. Here's my sql_exporter.yml.
...and here's my db1.collector.yml:
I also have a db2.collector.yml file which, for all intents and purposes, is so far identical except for db1 -> db2 and of course the query (which again shouldn't come into play yet) Your feedback is very much appreciated. Thanks |
Beta Was this translation helpful? Give feedback.
Oh. My. God. You will hate me.
I just realized I had a stray hyphen character in my sql_exporter.yml. Do you see it?
I swear I missed that, and it just looked like a spec of dust my on my monitor.
With it gone, the crash is gone. Not only that, but the collection wor…