cyrenbyren 12 Posted July 18, 2021 Share Posted July 18, 2021 I've been wanting a metrics API for emby for quite a while. I do have the functionality down, as a matter of fact, but it's an external one that incessantly queries the API, which results in a lot of spam in the logs. So I figured a "native" API would be better. Is it possible to expose a new route, or otherwise add functionality the existing API? And if there is, are there any examples or documentation anywhere on how? Link to comment Share on other sites More sharing options...
chef 3745 Posted July 18, 2021 Share Posted July 18, 2021 Sounds like you want to build a plugin that uses the IService interface and creates a couple new routes. What data would you want to host at these endpoints? So I understand exactly what you're look for? Link to comment Share on other sites More sharing options...
chef 3745 Posted July 18, 2021 Share Posted July 18, 2021 51 minutes ago, cyrenbyren said: I've been wanting a metrics API for emby for quite a while. I do have the functionality down, as a matter of fact, but it's an external one that incessantly queries the API, which results in a lot of spam in the logs. So I figured a "native" API would be better. Is it possible to expose a new route, or otherwise add functionality the existing API? And if there is, are there any examples or documentation anywhere on how? Sounds like you want to build a plugin that uses the IService interface and creates a couple new routes. What data would you want to host at these endpoints? So I understand exactly what you're look for? Link to comment Share on other sites More sharing options...
cyrenbyren 12 Posted July 19, 2021 Author Share Posted July 19, 2021 I appreciate this! This is likely exactly what I'm looking for. In essence, it will be prometheus style metrics. Number of movies, episodes, shows, current active sessions. Stuff like that! Link to comment Share on other sites More sharing options...
chef 3745 Posted July 19, 2021 Share Posted July 19, 2021 (edited) 5 hours ago, cyrenbyren said: I appreciate this! This is likely exactly what I'm looking for. In essence, it will be prometheus style metrics. Number of movies, episodes, shows, current active sessions. Stuff like that! There is the reports plugin and playback reporting plugin for the server which has this functionality. However, building your own plugin is an awesome idea . I have several GitHub repos that you can read, as well as the Emby GitHub plugin repo that has a ton of resources. https://github.com/chefbennyj1 https://github.com/MediaBrowser/Emby/wiki/How-to-build-a-Server-Plugin I also made some "half hazzard" YouTube videos about how to set up a plugin... I'm terrible at YouTube videos: https://youtu.be/qX8gfZz99Yo Once the plugin base is ready, you'd want to create a Class that inherits IService. Then you can list all the routes there. My AlexaController skill plugin endpoint gets fairly advanced, but in the API folder in the Service class, are examples of this, and also in the Autoorganize plugin in the FileOrganizeService. I just checked out Prometheus and it looks amazing. To create graphs on the web page check out my Diskspace plugin. We side load Chartjs. I have a feeling that is what you are looking for. You might also consider, keeping the plugin cross platform. So getting resource info for each type of system can get tricky. There is a rabbit hole there. Not impossible though. Edited July 19, 2021 by chef 1 Link to comment Share on other sites More sharing options...
cyrenbyren 12 Posted July 19, 2021 Author Share Posted July 19, 2021 (edited) Great, thank you! I will (probably) not create a web page for showing reports and such - the idea is to enable Prometheus to pull metrics from an existing instance. Simply adding a /metrics route that it can connect to. Prometheus metrics look like this: emby_info{instance="my_emby_instance",version="4.6.4.0",id="f926dfca63faa96b04199438813e0f0d"} 1 1626706224325 emby_movie_count{instance="my_emby_instance"} 10 1626706224325 emby_show_count{instance="my_emby_instance"} 10 1626706224325 emby_sessions{instance="my_emby_instance", user="some_user", type="Episode", name="Some show - Season 1 - Episode name"} 1 1626706224325 Having this will allow me point Prometheus to poll Emby at https://my.emby.instance:8920/metrics to start building up metrics and use that in Grafana, for example, to build up graphs and other pretty things. I use this for several other services, which is why I want it for Emby as well! Edited July 19, 2021 by cyrenbyren 1 Link to comment Share on other sites More sharing options...
chef 3745 Posted July 19, 2021 Share Posted July 19, 2021 Cool! check out the Sessions, Users, LibraryService endpoints that is in the API, sounds like they'll also have data you'll want. Lemme know how you get in with it. Sound super cool! Link to comment Share on other sites More sharing options...
chef 3745 Posted July 19, 2021 Share Posted July 19, 2021 (edited) I also forgot to mention that emby has websockets, so you might not even have to poll the server for info, you might be able to broadcast an event... I haven't done this before to other clients, but might be worth checking into if Prometheus can listen for that kind of stuff. After further reading on the Prometheus website, I have to say, that application is super cool. I had never seen it before. Looks like you can put everything in one place. I wonder if they have integration with Ubiquiti networking stuff. If they did, I wiukd never open another dashboard again unless it was nesessary Edited July 19, 2021 by chef Link to comment Share on other sites More sharing options...
cyrenbyren 12 Posted July 19, 2021 Author Share Posted July 19, 2021 There is indeed an exporter for use with Ubiquiti (Unifi specifically), it works lovely! Link to comment Share on other sites More sharing options...
cyrenbyren 12 Posted July 19, 2021 Author Share Posted July 19, 2021 Mostly done! However, is there a way to determine the running version of Emby? 1 Link to comment Share on other sites More sharing options...
Luke 37063 Posted July 19, 2021 Share Posted July 19, 2021 2 hours ago, cyrenbyren said: Mostly done! However, is there a way to determine the running version of Emby? Yes, via /system/info/public Link to comment Share on other sites More sharing options...
cyrenbyren 12 Posted July 20, 2021 Author Share Posted July 20, 2021 Duh, of course. I'm already doing that for my external exporter. Silly me. Thank you! Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now