Skip to content

Adding an "info" metric #16

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 13, 2023
Merged

Conversation

C-Duv
Copy link
Contributor

@C-Duv C-Duv commented Mar 10, 2023

Here is an implementation for new wp_info metric to export WordPress code and database versions as talked in #15.

This adds a new wp_info metric that returns WordPress code and database
versions.

Versions are in the "version" and "db_version" labels.

Issue: CodeAtCode#15
@C-Duv
Copy link
Contributor Author

C-Duv commented Mar 10, 2023

I opened this PR as draft because I fail to make it working, all seems good to me but the new metrics is not printed/returned. All others metrics are returned just fine and there is no error in the logs.

I am not really sure how to tell the plugin it should load/enable this metric, I thought adding it to Default_Metrics_Loader was enough.

Also, I want to provide a JSON for updating the Grafana Dashboard (but I'd rather wait we agree on the metric first).

@C-Duv
Copy link
Contributor Author

C-Duv commented Mar 11, 2023

In the end, it finally works fine (I obviously had some caching issue).

Here is the JSON for a table Grafana panel to use in the Dashboard:

{
  "id": 36,
  "type": "table",
  "title": "Versions",
  "targets": [
    {
      "refId": "A",
      "editorMode": "code",
      "expr": "topk(1, wp_info{host=\"$host\"})",
      "legendFormat": "__auto",
      "range": false,
      "instant": true,
      "exemplar": false,
      "format": "table"
    }
  ],
  "options": {
    "showHeader": true,
    "footer": {
      "show": false,
      "reducer": [
        "sum"
      ],
      "fields": ""
    }
  },
  "fieldConfig": {
    "defaults": {
      "custom": {
        "align": "auto",
        "displayMode": "auto",
        "inspect": false
      },
      "mappings": [],
      "thresholds": {
        "mode": "absolute",
        "steps": []
      },
      "color": {
        "mode": "thresholds"
      }
    },
    "overrides": []
  },
  "pluginVersion": "9.3.1",
  "transformations": [
    {
      "id": "merge",
      "options": {}
    },
    {
      "id": "organize",
      "options": {
        "excludeByName": {
          "Time": true,
          "job": true,
          "instance": true,
          "host": true,
          "__name__": true,
          "scheme": true,
          "Value": true
        },
        "indexByName": {
          "version": 0,
          "db_version": 1,
          "Time": 2,
          "__name__": 3,
          "host": 4,
          "instance": 5,
          "job": 6,
          "scheme": 7,
          "Value": 8
        },
        "renameByName": {
          "__name__": "",
          "db_version": "Database Version ",
          "version": "WordPress Version "
        }
      }
    }
  ]
}

It adds "Versions" table panel looking as follows:

image

The PromQL is topk(1, wp_info{host="$host"}) with some transformation to keep only 2 fields, and rename them.

@C-Duv
Copy link
Contributor Author

C-Duv commented Mar 11, 2023

I wonder if I should also return the exporter plugin's version?

@C-Duv C-Duv changed the title Draft: Adding an "info" metric Adding an "info" metric Mar 11, 2023
@Mte90
Copy link
Member

Mte90 commented Mar 13, 2023

I think that is perfect as it is.
About the plugin version I don't think that is too much important as it isn't updated so often as you can see.

@Mte90 Mte90 merged commit 2ed1208 into CodeAtCode:v3.0 Mar 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants