Skip to content

OpCache data in Home Assistant #109

Closed

Description

@cvc90

Hi @amnuts,

I want to import OpCache data into Home Assistant via multiscrape, is there any method to view the data in .json format?

Activity

  1. amnuts commented on Jun 4, 2024

    @amnuts
    Owner

    What a really interesting idea, @cvc90!

    It doesn't have a built in method, as such... The main method that spits out the details is getData. Where that's use, within handle() and the main template itself when outputting the main React component, it just wraps the output of getData() in PHP's own json_encode().

    The handle() method it will output json format under a couple conditions; if it's a json request and the allow_realtime option is set. So you could try to take advantage of that, but it might just be easier to add your own function to wrap around getData()?

    Here's where it's called currently in the code:

    which end up combined as:

  2. cvc90 commented on Jun 7, 2024

    @cvc90
    ContributorAuthor

    Hi @amnuts,

    After investigating your answer for several days and analyzing how you were importing this ‘.json’ data, I have found a possible solution to import this data to ‘Home Assistant’ or any program that is compatible with ‘.json’ from opcache-gui without having to modify anything.

    Here is a summary:

    To be able to visualize the data in ‘.json’ format it would be as simple as making a request with the following ‘header’

    headers:
    Accept: ‘application/json, text/plain, /’

    Here is an example of making a request using curl to return the ‘.json’ file

    curl ‘https://url/opcache-gui.php’ -H ‘accept: application/json, text/plain, /’

    If what we want is to import this data to ‘Home Assistant’ there are several methods for importing ‘.json’ data but I think the most efficient to not saturate requests and from the same request to collect the data would be using the ‘HA MultiScrape custom component’.

    Here is an example of how it would be to collect data from some of the variables

    • name: OpCache
      resource: https://url/opcache-gui.php
      verify_ssl: False
      scan_interval: 30
      headers:
      Accept: ‘application/json, text/plain, /’
      sensor:
      • unique_id: opcache_version
        name: "OpCache - Versión"
        value_template: "{{ value_json.version.version }}"
        #icon: mdi:
      • unique_id: opcache_start_time
        name: "OpCache - Start time"
        value_template: "{{ value_json.overview.readable.start_time }}"
        icon: mdi:clock
      • unique_id: opcache_total_memory
        name: "OpCache - Total memory"
        value_template: "{{ value_json.overview.readable.total_memory }}"
        icon: fas:memory
      • unique_id: opcache_cache_hits
        name: "OpCache - Cache hits"
        value_template: "{{ value_json.overview.hits }}"
        icon: mdi:web-check
      • unique_id: opcache_cache_misses
        name: "OpCache - Cache misses"
        value_template: "{{ value_json.overview.misses }}"

    A sample of data from ‘Home Assistant’, from one of my servers to which I have already implemented this integration.

    image

    What do you think about this integration? There are other methods but I think it is the easiest / cleanest to implement.

    What do you think?

  3. amnuts commented on Jun 10, 2024

    @amnuts
    Owner

    I only have speaker-based assistants, no screens, so this is not something I've ever loomed into (though as a coincidence, I did book the HA details a couple months back to look into to controlling some lighting via an arduino... not that I have, yet!), so I can't really speak as to whether it's the best way forwards or not.

    However, with a quick scan on the forums, it does look like a bunch of people on there are getting json data in a similar way with multiscrape. So if it works for you, and from the screenshot I'm going to say, yes, it does 😄, then I think your solution is great!

    but I think that if it works for you then you're on to a winner! :-)

  4. cvc90 commented on Jun 10, 2024

    @cvc90
    ContributorAuthor

    Even if you only have "speaker-based assistants", by adding each tribute as a sensor in "HA", you can use it from the "speaker-based assistants" to tell you the status of each sensor.

    You can even create your own automations to send you messages through the "HA" application, messaging systems like Telegram or even voice messages for your "speaker-based assistants" such as for status checks or even if it detects that some value does not match what is established.

    I have to say that this integration can be very useful...

    After several days and including them in several "Home Assistants", they work perfectly without any problem.

  5. Repository owner locked and limited conversation to collaborators on Jun 23, 2024
  6. converted this issue into a discussion #113 on Jun 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions