Skip to content
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

Is it possible to export the pm2 app status ? #5

Open
dinkonin opened this issue Oct 1, 2024 · 6 comments
Open

Is it possible to export the pm2 app status ? #5

dinkonin opened this issue Oct 1, 2024 · 6 comments

Comments

@dinkonin
Copy link

dinkonin commented Oct 1, 2024

Can we get a metric of the pm2 app status i.e. pm2_app_status{job="XXX",app="YYY"} $STATUS ?

Value mapped for example "online" = 1 , "stopped" = 0, "errored" = 2 would be awesome.

@VeXell
Copy link
Owner

VeXell commented Oct 1, 2024

Hello @dinkonin

Interesting question. But what a problem do you want to resolve with it?

@dinkonin
Copy link
Author

dinkonin commented Oct 1, 2024

Basically I monitor a server with 20+ apps ran by pm2, sometimes one of them errors out, or gets stopped accidentally by a developer and then forgotten. Ideally I would like to have an alertmanager rule for this situation and a timestamp of the exact time. It would also provide a nice overview of running/stopped apps in grafana.

@VeXell
Copy link
Owner

VeXell commented Oct 1, 2024

@dinkonin Ok, i will investigate what i can do here. But now i guess you can use app_uptime metric and if it changed it means something happened with the app. Also by my initial logic if app "stopped" or "errored" i will skip it in prom output.

@dinkonin
Copy link
Author

dinkonin commented Oct 1, 2024

Also by my initial logic if app "stopped" or "errored" i will skip it in prom output.

This is exactly why app_uptime would not work, the app just dissapears from the metrics even tho it is still there in pm2 list.

@VeXell
Copy link
Owner

VeXell commented Oct 1, 2024

@dinkonin yes, make sense. But anyway, i will do it in t next 2.4.0 release

@dinkonin
Copy link
Author

dinkonin commented Oct 1, 2024

Also currently i monitor this using node_exporter text collector, but it would be awesome if it's integrated in your app

Here is the bash script that generates the .prom fie

#!/usr/bin/env bash

echo '# TYPE PM2Status gauge'
pm2 jlist|jq --arg jqhost "$HOST" -rc '.[]|"PM2Status{host=\""+$jqhost+"\", name=\""+.name+"\"} \(if .pm2_env.status == "online" then 0 elif . == "stopped" then 1 else 2 end)"'

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

No branches or pull requests

2 participants