sql_exporter icon indicating copy to clipboard operation
sql_exporter copied to clipboard

can I add static labels to target?

Open farodrig opened this issue 6 years ago • 3 comments

Hi, I want to add some static labels to target. Is it possible?

ex:

target:
  # Data source name always has a URI schema that matches the driver name. In some cases (e.g. MySQL)
  # the schema gets dropped or replaced to match the driver expected DSN format.
  data_source_name: 'sqlserver://prom_user:[email protected]:1433'

  # Collectors (referenced by name) to execute on the target.
  collectors: [pricing_data_freshness]

  # My static labels
  labels:
    -  my_label: 'my-label-value'
    -  some-another-label: 'another-label-value'

farodrig avatar Nov 25 '19 20:11 farodrig

Hi @farodrig,

it's impossible to add static labels to the target afaik, but you can add static labels in the metrics definition. It was merged to master yesterday, so you can define it now within the metrics configuration with static_labels as key/value pair. See the example:

metrics:
  - metric_name: pricing_update_time
    type: gauge
    help: 'Time when prices for a market were last updated.'
    key_labels:
      # Populated from the `market` column of each row.
      - Market
    static_labels:  <-----------
      # Arbitrary key/value pair
      portfolio: income
      testlabel: testvalue
    values: [LastUpdateTime]
    query: |
      SELECT Market, max(UpdateTime) AS LastUpdateTime
      FROM MarketPrices
      GROUP BY Market

burningalchemist avatar Nov 28 '19 09:11 burningalchemist

See also a more complete request about this here: #58 (allows reusing collectors config accross different targets)

nanawel avatar Mar 24 '20 06:03 nanawel

It is missing in https://github.com/free/sql_exporter/blob/master/documentation/sql_exporter.yml

SPFZ avatar May 19 '20 08:05 SPFZ